1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4define i32 @sub_self(i32 %A) {
5; CHECK-LABEL: @sub_self(
6; CHECK-NEXT:    ret i32 0
7;
8  %B = sub i32 %A, %A
9  ret i32 %B
10}
11
12define <2 x i32> @sub_self_vec(<2 x i32> %A) {
13; CHECK-LABEL: @sub_self_vec(
14; CHECK-NEXT:    ret <2 x i32> zeroinitializer
15;
16  %B = sub <2 x i32> %A, %A
17  ret <2 x i32> %B
18}
19
20define i32 @sub_zero(i32 %A) {
21; CHECK-LABEL: @sub_zero(
22; CHECK-NEXT:    ret i32 [[A:%.*]]
23;
24  %B = sub i32 %A, 0
25  ret i32 %B
26}
27
28define <2 x i32> @sub_zero_vec(<2 x i32> %A) {
29; CHECK-LABEL: @sub_zero_vec(
30; CHECK-NEXT:    ret <2 x i32> [[A:%.*]]
31;
32  %B = sub <2 x i32> %A, <i32 0, i32 undef>
33  ret <2 x i32> %B
34}
35
36define i32 @neg_neg(i32 %A) {
37; CHECK-LABEL: @neg_neg(
38; CHECK-NEXT:    ret i32 [[A:%.*]]
39;
40  %B = sub i32 0, %A
41  %C = sub i32 0, %B
42  ret i32 %C
43}
44
45define <2 x i32> @neg_neg_vec(<2 x i32> %A) {
46; CHECK-LABEL: @neg_neg_vec(
47; CHECK-NEXT:    ret <2 x i32> [[A:%.*]]
48;
49  %B = sub <2 x i32> <i32 0, i32 undef>, %A
50  %C = sub <2 x i32> <i32 0, i32 undef>, %B
51  ret <2 x i32> %C
52}
53
54; TODO: these should be poison
55
56define i32 @poison1(i32 %x) {
57; CHECK-LABEL: @poison1(
58; CHECK-NEXT:    ret i32 undef
59;
60  %v = sub i32 %x, poison
61  ret i32 %v
62}
63
64define i32 @poison2(i32 %x) {
65; CHECK-LABEL: @poison2(
66; CHECK-NEXT:    ret i32 undef
67;
68  %v = sub i32 poison, %x
69  ret i32 %v
70}
71