1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
6 define i8 @basic(i8 %x, i8 %y) {
8 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: ret i8 [[NOTA]]
17 define i8 @basic_com_add(i8 %x, i8 %y) {
18 ; CHECK-LABEL: @basic_com_add(
19 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[Y:%.*]], [[X:%.*]]
20 ; CHECK-NEXT: ret i8 [[NOTA]]
28 define i8 @basic_use_xor(i8 %x, i8 %y) {
29 ; CHECK-LABEL: @basic_use_xor(
30 ; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
31 ; CHECK-NEXT: call void @use(i8 [[NOTX]])
32 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y:%.*]]
33 ; CHECK-NEXT: ret i8 [[NOTA]]
36 call void @use(i8 %notx)
42 define i8 @basic_use_add(i8 %x, i8 %y) {
43 ; CHECK-LABEL: @basic_use_add(
44 ; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
45 ; CHECK-NEXT: [[A:%.*]] = add i8 [[NOTX]], [[Y:%.*]]
46 ; CHECK-NEXT: call void @use(i8 [[A]])
47 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y]]
48 ; CHECK-NEXT: ret i8 [[NOTA]]
57 define i8 @basic_use_both(i8 %x, i8 %y) {
58 ; CHECK-LABEL: @basic_use_both(
59 ; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
60 ; CHECK-NEXT: call void @use(i8 [[NOTX]])
61 ; CHECK-NEXT: [[A:%.*]] = add i8 [[NOTX]], [[Y:%.*]]
62 ; CHECK-NEXT: call void @use(i8 [[A]])
63 ; CHECK-NEXT: [[NOTA:%.*]] = sub i8 [[X]], [[Y]]
64 ; CHECK-NEXT: ret i8 [[NOTA]]
67 call void @use(i8 %notx)
74 define i8 @basic_preserve_nsw(i8 %x, i8 %y) {
75 ; CHECK-LABEL: @basic_preserve_nsw(
76 ; CHECK-NEXT: [[NOTA:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]]
77 ; CHECK-NEXT: ret i8 [[NOTA]]
80 %a = add nsw i8 %notx, %y
85 define i8 @basic_preserve_nuw(i8 %x, i8 %y) {
86 ; CHECK-LABEL: @basic_preserve_nuw(
87 ; CHECK-NEXT: [[NOTA:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]]
88 ; CHECK-NEXT: ret i8 [[NOTA]]
91 %a = add nuw i8 %notx, %y
96 define i8 @basic_preserve_nuw_nsw(i8 %x, i8 %y) {
97 ; CHECK-LABEL: @basic_preserve_nuw_nsw(
98 ; CHECK-NEXT: [[NOTA:%.*]] = sub nuw nsw i8 [[X:%.*]], [[Y:%.*]]
99 ; CHECK-NEXT: ret i8 [[NOTA]]
101 %notx = xor i8 %x, -1
102 %a = add nuw nsw i8 %notx, %y
103 %nota = xor i8 %a, -1
107 define <4 x i32> @vector_test(<4 x i32> %x, <4 x i32> %y) {
108 ; CHECK-LABEL: @vector_test(
109 ; CHECK-NEXT: [[NOTA:%.*]] = sub <4 x i32> [[X:%.*]], [[Y:%.*]]
110 ; CHECK-NEXT: ret <4 x i32> [[NOTA]]
112 %notx = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
113 %a = add <4 x i32> %notx, %y
114 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 -1, i32 -1>
118 define <4 x i32> @vector_test_poison(<4 x i32> %x, <4 x i32> %y) {
119 ; CHECK-LABEL: @vector_test_poison(
120 ; CHECK-NEXT: [[NOTA:%.*]] = sub <4 x i32> [[X:%.*]], [[Y:%.*]]
121 ; CHECK-NEXT: ret <4 x i32> [[NOTA]]
123 %notx = xor <4 x i32> %x, <i32 -1, i32 poison, i32 poison, i32 -1>
124 %a = add <4 x i32> %notx, %y
125 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 poison, i32 poison>
130 define <4 x i32> @vector_test_poison_nsw_nuw(<4 x i32> %x, <4 x i32> %y) {
131 ; CHECK-LABEL: @vector_test_poison_nsw_nuw(
132 ; CHECK-NEXT: [[NOTA:%.*]] = sub nuw nsw <4 x i32> [[X:%.*]], [[Y:%.*]]
133 ; CHECK-NEXT: ret <4 x i32> [[NOTA]]
135 %notx = xor <4 x i32> %x, <i32 -1, i32 poison, i32 poison, i32 -1>
136 %a = add nsw nuw <4 x i32> %notx, %y
137 %nota = xor <4 x i32> %a, <i32 -1, i32 -1, i32 poison, i32 poison>
141 define i32 @pr50308(i1 %c1, i32 %v1, i32 %v2, i32 %v3) {
142 ; CHECK-LABEL: @pr50308(
144 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
146 ; CHECK-NEXT: [[ADD_NOT:%.*]] = sub i32 -2, [[V1:%.*]]
147 ; CHECK-NEXT: [[ADD1_NEG:%.*]] = xor i32 [[ADD_NOT]], [[V2:%.*]]
148 ; CHECK-NEXT: br label [[COND_END]]
150 ; CHECK-NEXT: [[COND_NEG:%.*]] = phi i32 [ [[ADD1_NEG]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
151 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[COND_NEG]], [[V3:%.*]]
152 ; CHECK-NEXT: ret i32 [[SUB]]
155 br i1 %c1, label %cond.true, label %cond.end
158 %add = add nsw i32 1, %v1
159 %xor = xor i32 %add, %v2
160 %add1 = add nsw i32 1, %xor
164 %cond = phi i32 [ %add1, %cond.true ], [ 0, %entry ]
165 %sub = sub nsw i32 %v3, %cond
169 @g = extern_weak global i32
170 define void @pr50370(i32 %x) {
171 ; CHECK-LABEL: @pr50370(
173 ; CHECK-NEXT: store i32 poison, ptr undef, align 4
174 ; CHECK-NEXT: ret void
178 %cmp = icmp eq ptr @g, null
179 %ext = zext i1 %cmp to i32
181 %or4 = or i32 %or, 65536
182 %B6 = ashr i32 65536, %or4
183 %B15 = srem i32 %B6, %xor
184 %B20 = sdiv i32 %or4, 2147483647
185 %B22 = add i32 %B15, %B20
186 %B14 = srem i32 %B6, %B22
187 %B12 = add i32 %B15, %B6
188 %B8 = shl i32 %B20, %B14
189 %B2 = xor i32 %B12, %B8
190 %B3 = or i32 %B12, undef
191 %B = xor i32 %B2, %B3
192 store i32 %B, ptr undef, align 4