1 ; This test makes sure that these instructions are properly eliminated.
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
6 define i32 @test1(i32 %A) {
13 define i32 @test2(i32 %A) {
20 define i8 @test2a(i8 %A) {
27 define i1 @test3(i1 %A) {
34 define i1 @test4(i1 %A) {
41 define i1 @test5(i1 %A) {
48 define i32 @test6(i32 %A) {
56 define i32 @test7(i32 %A) {
57 %NotA = xor i32 -1, %A
64 define i8 @test8(i8 %A) {
72 ; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
73 define i8 @test9(i8 %A, i8 %B) {
82 define i8 @test10(i8 %A) {
85 ; (X & C1) | C2 --> (X | C2) & (C1|C2)
92 define i8 @test11(i8 %A) {
95 ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
103 define i32 @test12(i32 %A) {
104 ; Should be eliminated
109 ; CHECK: %C = and i32 %A, 8
113 define i32 @test13(i32 %A) {
122 define i1 @test14(i32 %A, i32 %B) {
123 %C1 = icmp ult i32 %A, %B
124 %C2 = icmp ugt i32 %A, %B
125 ; (A < B) | (A > B) === A != B
129 ; CHECK: icmp ne i32 %A, %B
133 define i1 @test15(i32 %A, i32 %B) {
134 %C1 = icmp ult i32 %A, %B
135 %C2 = icmp eq i32 %A, %B
136 ; (A < B) | (A == B) === A <= B
140 ; CHECK: icmp ule i32 %A, %B
144 define i32 @test16(i32 %A) {
148 ; %D = and int %B, -1 == %B
155 define i32 @test17(i32 %A) {
162 ; CHECK: %D = and i32 %A, 5
166 define i1 @test18(i32 %A) {
167 %B = icmp sge i32 %A, 100
168 %C = icmp slt i32 %A, 50
178 define i1 @test19(i32 %A) {
179 %B = icmp eq i32 %A, 50
180 %C = icmp eq i32 %A, 51
190 define i32 @test20(i32 %x) {
198 define i32 @test21(i32 %tmp.1) {
199 %tmp.1.mask1 = add i32 %tmp.1, 2
200 %tmp.3 = and i32 %tmp.1.mask1, -2
201 %tmp.5 = and i32 %tmp.1, 1
203 %tmp.6 = or i32 %tmp.5, %tmp.3
206 ; CHECK: add i32 %{{[^,]*}}, 2
210 define i32 @test22(i32 %B) {
211 %ELIM41 = and i32 %B, 1
212 %ELIM7 = and i32 %B, -2
213 %ELIM5 = or i32 %ELIM41, %ELIM7
219 define i16 @test23(i16 %A) {
222 %C = or i16 %B, -32768
223 %D = xor i16 %C, 8193
226 ; CHECK: %B = lshr i16 %A, 1
227 ; CHECK: %D = xor i16 %B, -24575
232 define i1 @test24(double %X, double %Y) {
233 %tmp9 = fcmp uno double %X, 0.000000e+00 ; <i1> [#uses=1]
234 %tmp13 = fcmp uno double %Y, 0.000000e+00 ; <i1> [#uses=1]
235 %bothcond = or i1 %tmp13, %tmp9 ; <i1> [#uses=1]
239 ; CHECK: = fcmp uno double %Y, %X
244 define i1 @test25(i32 %A, i32 %B) {
245 %C = icmp eq i32 %A, 0
246 %D = icmp eq i32 %B, 57
252 ; CHECK: icmp ne i32 %A, 0
253 ; CHECK-NEXT: icmp ne i32 %B, 57
254 ; CHECK-NEXT: %F = and i1
255 ; CHECK-NEXT: ret i1 %F
259 define i1 @test26(i32 %A, i32 %B) {
260 %C1 = icmp eq i32 %A, 0
261 %C2 = icmp eq i32 %B, 0
262 ; (A == 0) & (A == 0) --> (A|B) == 0
266 ; CHECK: or i32 %A, %B
267 ; CHECK: icmp eq i32 {{.*}}, 0
271 define i1 @test27(i32* %A, i32* %B) {
272 %C1 = ptrtoint i32* %A to i32
273 %C2 = ptrtoint i32* %B to i32
275 %E = icmp eq i32 %D, 0
278 ; CHECK: icmp eq i32* %A, null
279 ; CHECK: icmp eq i32* %B, null
285 define i1 @test28(i32 %A, i32 %B) {
286 %C1 = icmp ne i32 %A, 0
287 %C2 = icmp ne i32 %B, 0
288 ; (A != 0) | (A != 0) --> (A|B) != 0
292 ; CHECK: or i32 %A, %B
293 ; CHECK: icmp ne i32 {{.*}}, 0
297 define i1 @test29(i32* %A, i32* %B) {
298 %C1 = ptrtoint i32* %A to i32
299 %C2 = ptrtoint i32* %B to i32
301 %E = icmp ne i32 %D, 0
304 ; CHECK: icmp ne i32* %A, null
305 ; CHECK: icmp ne i32* %B, null
311 define i32 @test30(i32 %A) {
313 %B = or i32 %A, 32962
314 %C = and i32 %A, -65536
315 %D = and i32 %B, 40186
319 ; CHECK: %D = and i32 %A, -58312
320 ; CHECK: %E = or i32 %D, 32962
325 define i64 @test31(i64 %A) nounwind readnone ssp noredzone {
329 %C = or i64 %A, 32768
330 %E = and i64 %C, 4294941696
335 ; CHECK-NEXT: %E1 = and i64 %A, 4294908984
336 ; CHECK-NEXT: %F = or i64 %E1, 32962
337 ; CHECK-NEXT: ret i64 %F
340 define <4 x i32> @test32(<4 x i1> %and.i1352, <4 x i32> %vecinit6.i176, <4 x i32> %vecinit6.i191) {
341 %and.i135 = sext <4 x i1> %and.i1352 to <4 x i32> ; <<4 x i32>> [#uses=2]
342 %and.i129 = and <4 x i32> %vecinit6.i176, %and.i135 ; <<4 x i32>> [#uses=1]
343 %neg.i = xor <4 x i32> %and.i135, <i32 -1, i32 -1, i32 -1, i32 -1> ; <<4 x i32>> [#uses=1]
344 %and.i = and <4 x i32> %vecinit6.i191, %neg.i ; <<4 x i32>> [#uses=1]
345 %or.i = or <4 x i32> %and.i, %and.i129 ; <<4 x i32>> [#uses=1]
347 ; Don't turn this into a vector select until codegen matures to handle them
350 ; CHECK: or <4 x i32> %and.i, %and.i129
353 define i1 @test33(i1 %X, i1 %Y) {
358 ; CHECK-NEXT: or i1 %X, %Y
362 define i32 @test34(i32 %X, i32 %Y) {
367 ; CHECK-NEXT: or i32 %X, %Y
371 define i32 @test35(i32 %a, i32 %b) {
376 ; CHECK-NEXT: or i32 %a, %b
377 ; CHECK-NEXT: or i32 %1, 1135
380 define i1 @test36(i32 %x) {
381 %cmp1 = icmp eq i32 %x, 23
382 %cmp2 = icmp eq i32 %x, 24
383 %ret1 = or i1 %cmp1, %cmp2
384 %cmp3 = icmp eq i32 %x, 25
385 %ret2 = or i1 %ret1, %cmp3
388 ; CHECK-NEXT: %x.off = add i32 %x, -23
389 ; CHECK-NEXT: icmp ult i32 %x.off, 3