1 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6 define i32 @test1(i32 %X) {
8 icmp slt i32 %X, 0 ; <i1>:0 [#uses=1]
9 zext i1 %0 to i32 ; <i32>:1 [#uses=1]
11 ; CHECK-LABEL: @test1(
12 ; CHECK: lshr i32 %X, 31
16 define i32 @test2(i32 %X) {
18 icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1]
19 zext i1 %0 to i32 ; <i32>:1 [#uses=1]
21 ; CHECK-LABEL: @test2(
22 ; CHECK: lshr i32 %X, 31
27 define i32 @test3(i32 %X) {
29 icmp slt i32 %X, 0 ; <i1>:0 [#uses=1]
30 sext i1 %0 to i32 ; <i32>:1 [#uses=1]
32 ; CHECK-LABEL: @test3(
33 ; CHECK: ashr i32 %X, 31
37 define i32 @test4(i32 %X) {
39 icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1]
40 sext i1 %0 to i32 ; <i32>:1 [#uses=1]
42 ; CHECK-LABEL: @test4(
43 ; CHECK: ashr i32 %X, 31
49 define <2 x i1> @test5(<2 x i64> %x) {
51 %V = icmp eq <2 x i64> %x, undef
53 ; CHECK-LABEL: @test5(
54 ; CHECK: ret <2 x i1> <i1 true, i1 true>
57 define i32 @test6(i32 %a, i32 %b) {
58 %c = icmp sle i32 %a, -1
59 %d = zext i1 %c to i32
63 ; CHECK-LABEL: @test6(
64 ; CHECK-NEXT: ashr i32 %a, 31
65 ; CHECK-NEXT: %f = and i32 %e, %b
66 ; CHECK-NEXT: ret i32 %f
70 define i1 @test7(i32 %x) {
73 %b = icmp ult i32 %a, %x
75 ; CHECK-LABEL: @test7(
76 ; CHECK: %b = icmp ne i32 %x, 0
80 define i1 @test8(i32 %x){
83 %b = icmp eq i32 %a, %x
85 ; CHECK-LABEL: @test8(
89 define i1 @test9(i32 %x) {
92 %b = icmp ugt i32 %x, %a
94 ; CHECK-LABEL: @test9(
95 ; CHECK: icmp ugt i32 %x, 1
99 define i1 @test10(i32 %x){
102 %b = icmp slt i32 %a, %x
104 ; CHECK-LABEL: @test10(
105 ; CHECK: %b = icmp ne i32 %x, -2147483648
109 define i1 @test11(i32 %x) {
110 %a = add nsw i32 %x, 8
111 %b = icmp slt i32 %x, %a
113 ; CHECK-LABEL: @test11(
118 define i1 @test12(i1 %A) {
119 %S = select i1 %A, i64 -4294967295, i64 8589934591
120 %B = icmp ne i64 bitcast (<2 x i32> <i32 1, i32 -1> to i64), %S
122 ; CHECK-LABEL: @test12(
123 ; CHECK-NEXT: = xor i1 %A, true
128 define i1 @test13(i8 %X) nounwind readnone {
130 %cmp = icmp slt i8 undef, %X
132 ; CHECK-LABEL: @test13(
133 ; CHECK: ret i1 false
136 define i1 @test14(i8 %X) nounwind readnone {
138 %cmp = icmp slt i8 undef, -128
140 ; CHECK-LABEL: @test14(
141 ; CHECK: ret i1 false
144 define i1 @test15() nounwind readnone {
146 %cmp = icmp eq i8 undef, -128
148 ; CHECK-LABEL: @test15(
149 ; CHECK: ret i1 undef
152 define i1 @test16() nounwind readnone {
154 %cmp = icmp ne i8 undef, -128
156 ; CHECK-LABEL: @test16(
157 ; CHECK: ret i1 undef
160 define i1 @test17(i32 %x) nounwind {
162 %and = and i32 %shl, 8
163 %cmp = icmp eq i32 %and, 0
165 ; CHECK-LABEL: @test17(
166 ; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
169 define i1 @test17a(i32 %x) nounwind {
171 %and = and i32 %shl, 7
172 %cmp = icmp eq i32 %and, 0
174 ; CHECK-LABEL: @test17a(
175 ; CHECK-NEXT: %cmp = icmp ugt i32 %x, 2
178 define i1 @test18(i32 %x) nounwind {
180 %and = and i32 %sh, 1
181 %cmp = icmp eq i32 %and, 0
183 ; CHECK-LABEL: @test18(
184 ; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
187 define i1 @test19(i32 %x) nounwind {
189 %and = and i32 %shl, 8
190 %cmp = icmp eq i32 %and, 8
192 ; CHECK-LABEL: @test19(
193 ; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
196 define i1 @test20(i32 %x) nounwind {
198 %and = and i32 %shl, 8
199 %cmp = icmp ne i32 %and, 0
201 ; CHECK-LABEL: @test20(
202 ; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
205 define i1 @test20a(i32 %x) nounwind {
207 %and = and i32 %shl, 7
208 %cmp = icmp ne i32 %and, 0
210 ; CHECK-LABEL: @test20a(
211 ; CHECK-NEXT: %cmp = icmp ult i32 %x, 3
214 define i1 @test21(i8 %x, i8 %y) {
215 ; CHECK-LABEL: @test21(
219 %B = icmp ugt i8 %A, 3
223 define i1 @test22(i8 %x, i8 %y) {
224 ; CHECK-LABEL: @test22(
228 %B = icmp ult i8 %A, 4
233 ; CHECK-LABEL: @test23(
234 ; CHECK: icmp sgt i32 %x, 1328634634
235 define i1 @test23(i32 %x) nounwind {
236 %i3 = sdiv i32 %x, -1328634635
237 %i4 = icmp eq i32 %i3, -1
241 @X = global [1000 x i32] zeroinitializer
244 ; CHECK-LABEL: @test24(
245 ; CHECK: %cmp = icmp eq i64 %i, 1000
247 define i1 @test24(i64 %i) {
248 %p1 = getelementptr inbounds i32* getelementptr inbounds ([1000 x i32]* @X, i64 0, i64 0), i64 %i
249 %cmp = icmp eq i32* %p1, getelementptr inbounds ([1000 x i32]* @X, i64 1, i64 0)
253 @X_as1 = addrspace(1) global [1000 x i32] zeroinitializer
256 ; CHECK: trunc i64 %i to i16
257 ; CHECK: %cmp = icmp eq i16 %1, 1000
259 define i1 @test24_as1(i64 %i) {
260 %p1 = getelementptr inbounds i32 addrspace(1)* getelementptr inbounds ([1000 x i32] addrspace(1)* @X_as1, i64 0, i64 0), i64 %i
261 %cmp = icmp eq i32 addrspace(1)* %p1, getelementptr inbounds ([1000 x i32] addrspace(1)* @X_as1, i64 1, i64 0)
265 ; CHECK-LABEL: @test25(
266 ; X + Z > Y + Z -> X > Y if there is no overflow.
267 ; CHECK: %c = icmp sgt i32 %x, %y
269 define i1 @test25(i32 %x, i32 %y, i32 %z) {
270 %lhs = add nsw i32 %x, %z
271 %rhs = add nsw i32 %y, %z
272 %c = icmp sgt i32 %lhs, %rhs
276 ; CHECK-LABEL: @test26(
277 ; X + Z > Y + Z -> X > Y if there is no overflow.
278 ; CHECK: %c = icmp ugt i32 %x, %y
280 define i1 @test26(i32 %x, i32 %y, i32 %z) {
281 %lhs = add nuw i32 %x, %z
282 %rhs = add nuw i32 %y, %z
283 %c = icmp ugt i32 %lhs, %rhs
287 ; CHECK-LABEL: @test27(
288 ; X - Z > Y - Z -> X > Y if there is no overflow.
289 ; CHECK: %c = icmp sgt i32 %x, %y
291 define i1 @test27(i32 %x, i32 %y, i32 %z) {
292 %lhs = sub nsw i32 %x, %z
293 %rhs = sub nsw i32 %y, %z
294 %c = icmp sgt i32 %lhs, %rhs
298 ; CHECK-LABEL: @test28(
299 ; X - Z > Y - Z -> X > Y if there is no overflow.
300 ; CHECK: %c = icmp ugt i32 %x, %y
302 define i1 @test28(i32 %x, i32 %y, i32 %z) {
303 %lhs = sub nuw i32 %x, %z
304 %rhs = sub nuw i32 %y, %z
305 %c = icmp ugt i32 %lhs, %rhs
309 ; CHECK-LABEL: @test29(
310 ; X + Y > X -> Y > 0 if there is no overflow.
311 ; CHECK: %c = icmp sgt i32 %y, 0
313 define i1 @test29(i32 %x, i32 %y) {
314 %lhs = add nsw i32 %x, %y
315 %c = icmp sgt i32 %lhs, %x
319 ; CHECK-LABEL: @test30(
320 ; X + Y > X -> Y > 0 if there is no overflow.
321 ; CHECK: %c = icmp ne i32 %y, 0
323 define i1 @test30(i32 %x, i32 %y) {
324 %lhs = add nuw i32 %x, %y
325 %c = icmp ugt i32 %lhs, %x
329 ; CHECK-LABEL: @test31(
330 ; X > X + Y -> 0 > Y if there is no overflow.
331 ; CHECK: %c = icmp slt i32 %y, 0
333 define i1 @test31(i32 %x, i32 %y) {
334 %rhs = add nsw i32 %x, %y
335 %c = icmp sgt i32 %x, %rhs
339 ; CHECK-LABEL: @test32(
340 ; X > X + Y -> 0 > Y if there is no overflow.
341 ; CHECK: ret i1 false
342 define i1 @test32(i32 %x, i32 %y) {
343 %rhs = add nuw i32 %x, %y
344 %c = icmp ugt i32 %x, %rhs
348 ; CHECK-LABEL: @test33(
349 ; X - Y > X -> 0 > Y if there is no overflow.
350 ; CHECK: %c = icmp slt i32 %y, 0
352 define i1 @test33(i32 %x, i32 %y) {
353 %lhs = sub nsw i32 %x, %y
354 %c = icmp sgt i32 %lhs, %x
358 ; CHECK-LABEL: @test34(
359 ; X - Y > X -> 0 > Y if there is no overflow.
360 ; CHECK: ret i1 false
361 define i1 @test34(i32 %x, i32 %y) {
362 %lhs = sub nuw i32 %x, %y
363 %c = icmp ugt i32 %lhs, %x
367 ; CHECK-LABEL: @test35(
368 ; X > X - Y -> Y > 0 if there is no overflow.
369 ; CHECK: %c = icmp sgt i32 %y, 0
371 define i1 @test35(i32 %x, i32 %y) {
372 %rhs = sub nsw i32 %x, %y
373 %c = icmp sgt i32 %x, %rhs
377 ; CHECK-LABEL: @test36(
378 ; X > X - Y -> Y > 0 if there is no overflow.
379 ; CHECK: %c = icmp ne i32 %y, 0
381 define i1 @test36(i32 %x, i32 %y) {
382 %rhs = sub nuw i32 %x, %y
383 %c = icmp ugt i32 %x, %rhs
387 ; CHECK-LABEL: @test37(
388 ; X - Y > X - Z -> Z > Y if there is no overflow.
389 ; CHECK: %c = icmp sgt i32 %z, %y
391 define i1 @test37(i32 %x, i32 %y, i32 %z) {
392 %lhs = sub nsw i32 %x, %y
393 %rhs = sub nsw i32 %x, %z
394 %c = icmp sgt i32 %lhs, %rhs
398 ; CHECK-LABEL: @test38(
399 ; X - Y > X - Z -> Z > Y if there is no overflow.
400 ; CHECK: %c = icmp ugt i32 %z, %y
402 define i1 @test38(i32 %x, i32 %y, i32 %z) {
403 %lhs = sub nuw i32 %x, %y
404 %rhs = sub nuw i32 %x, %z
405 %c = icmp ugt i32 %lhs, %rhs
410 ; CHECK-LABEL: @test39(
411 ; CHECK: %B = icmp eq i32 %X, 0
412 define i1 @test39(i32 %X, i32 %Y) {
413 %A = ashr exact i32 %X, %Y
414 %B = icmp eq i32 %A, 0
418 ; CHECK-LABEL: @test40(
419 ; CHECK: %B = icmp ne i32 %X, 0
420 define i1 @test40(i32 %X, i32 %Y) {
421 %A = lshr exact i32 %X, %Y
422 %B = icmp ne i32 %A, 0
427 ; CHECK-LABEL: @test41(
429 define i1 @test41(i32 %X, i32 %Y) {
431 %B = icmp ugt i32 %Y, %A
435 ; CHECK-LABEL: @test42(
436 ; CHECK: %B = icmp sgt i32 %Y, -1
437 define i1 @test42(i32 %X, i32 %Y) {
439 %B = icmp slt i32 %A, %Y
443 ; CHECK-LABEL: @test43(
444 ; CHECK: %B = icmp slt i32 %Y, 0
445 define i1 @test43(i32 %X, i32 %Y) {
447 %B = icmp slt i32 %Y, %A
451 ; CHECK-LABEL: @test44(
452 ; CHECK: %B = icmp sgt i32 %Y, -1
453 define i1 @test44(i32 %X, i32 %Y) {
455 %B = icmp slt i32 %A, %Y
459 ; CHECK-LABEL: @test45(
460 ; CHECK: %B = icmp slt i32 %Y, 0
461 define i1 @test45(i32 %X, i32 %Y) {
463 %B = icmp slt i32 %Y, %A
468 ; CHECK-LABEL: @test46(
469 ; CHECK: %C = icmp ult i32 %X, %Y
470 define i1 @test46(i32 %X, i32 %Y, i32 %Z) {
471 %A = ashr exact i32 %X, %Z
472 %B = ashr exact i32 %Y, %Z
473 %C = icmp ult i32 %A, %B
478 ; CHECK-LABEL: @test47(
479 ; CHECK: %C = icmp ugt i32 %X, %Y
480 define i1 @test47(i32 %X, i32 %Y, i32 %Z) {
481 %A = ashr exact i32 %X, %Z
482 %B = ashr exact i32 %Y, %Z
483 %C = icmp ugt i32 %A, %B
488 ; CHECK-LABEL: @test48(
489 ; CHECK: %C = icmp eq i32 %X, %Y
490 define i1 @test48(i32 %X, i32 %Y, i32 %Z) {
491 %A = sdiv exact i32 %X, %Z
492 %B = sdiv exact i32 %Y, %Z
493 %C = icmp eq i32 %A, %B
498 ; CHECK-LABEL: @test49(
499 ; CHECK: ret <2 x i1> <i1 true, i1 true>
500 define <2 x i1> @test49(<2 x i32> %tmp3) {
502 %tmp11 = and <2 x i32> %tmp3, <i32 3, i32 3>
503 %cmp = icmp ult <2 x i32> %tmp11, <i32 4, i32 4>
508 ; CHECK-LABEL: @test50(
510 define i1 @test50(i16 %X, i32 %Y) {
511 %A = zext i16 %X to i32
513 %C = icmp sgt i32 %B, -1
517 ; CHECK-LABEL: @test51(
519 define i1 @test51(i32 %X, i32 %Y) {
520 %A = and i32 %X, 2147483648
522 %C = icmp sgt i32 %B, -1
526 ; CHECK-LABEL: @test52(
527 ; CHECK-NEXT: and i32 %x1, 16711935
528 ; CHECK-NEXT: icmp eq i32 {{.*}}, 4980863
530 define i1 @test52(i32 %x1) nounwind {
531 %conv = and i32 %x1, 255
532 %cmp = icmp eq i32 %conv, 127
533 %tmp2 = lshr i32 %x1, 16
534 %tmp3 = trunc i32 %tmp2 to i8
535 %cmp15 = icmp eq i8 %tmp3, 76
537 %A = and i1 %cmp, %cmp15
542 ; CHECK-LABEL: @test53(
543 ; CHECK-NEXT: sdiv exact
546 define i1 @test53(i32 %a, i32 %b) nounwind {
547 %x = sdiv exact i32 %a, 30
549 %z = icmp eq i32 %x, %y
553 ; CHECK-LABEL: @test54(
554 ; CHECK-NEXT: %and = and i8 %a, -64
555 ; CHECK-NEXT: icmp eq i8 %and, -128
556 define i1 @test54(i8 %a) nounwind {
557 %ext = zext i8 %a to i32
558 %and = and i32 %ext, 192
559 %ret = icmp eq i32 %and, 128
563 ; CHECK-LABEL: @test55(
564 ; CHECK-NEXT: icmp eq i32 %a, -123
565 define i1 @test55(i32 %a) {
567 %cmp = icmp eq i32 %sub, 123
571 ; CHECK-LABEL: @test56(
572 ; CHECK-NEXT: icmp eq i32 %a, -113
573 define i1 @test56(i32 %a) {
574 %sub = sub i32 10, %a
575 %cmp = icmp eq i32 %sub, 123
579 ; PR10267 Don't make icmps more expensive when no other inst is subsumed.
580 declare void @foo(i32)
581 ; CHECK-LABEL: @test57(
582 ; CHECK: %and = and i32 %a, -2
583 ; CHECK: %cmp = icmp ne i32 %and, 0
584 define i1 @test57(i32 %a) {
585 %and = and i32 %a, -2
586 %cmp = icmp ne i32 %and, 0
587 call void @foo(i32 %and)
591 ; rdar://problem/10482509
592 ; CHECK-LABEL: @cmpabs1(
593 ; CHECK-NEXT: icmp ne
594 define zeroext i1 @cmpabs1(i64 %val) {
595 %sub = sub nsw i64 0, %val
596 %cmp = icmp slt i64 %val, 0
597 %sub.val = select i1 %cmp, i64 %sub, i64 %val
598 %tobool = icmp ne i64 %sub.val, 0
602 ; CHECK-LABEL: @cmpabs2(
603 ; CHECK-NEXT: icmp ne
604 define zeroext i1 @cmpabs2(i64 %val) {
605 %sub = sub nsw i64 0, %val
606 %cmp = icmp slt i64 %val, 0
607 %sub.val = select i1 %cmp, i64 %val, i64 %sub
608 %tobool = icmp ne i64 %sub.val, 0
612 ; CHECK-LABEL: @test58(
613 ; CHECK-NEXT: call i32 @test58_d(i64 36029346783166592)
614 define void @test58() nounwind {
615 %cast = bitcast <1 x i64> <i64 36029346783166592> to i64
616 %call = call i32 @test58_d( i64 %cast) nounwind
619 declare i32 @test58_d(i64)
621 define i1 @test59(i8* %foo) {
622 %bit = bitcast i8* %foo to i32*
623 %gep1 = getelementptr inbounds i32* %bit, i64 2
624 %gep2 = getelementptr inbounds i8* %foo, i64 10
625 %cast1 = bitcast i32* %gep1 to i8*
626 %cmp = icmp ult i8* %cast1, %gep2
627 %use = ptrtoint i8* %cast1 to i64
628 %call = call i32 @test58_d(i64 %use) nounwind
630 ; CHECK-LABEL: @test59(
634 define i1 @test59_as1(i8 addrspace(1)* %foo) {
635 %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)*
636 %gep1 = getelementptr inbounds i32 addrspace(1)* %bit, i64 2
637 %gep2 = getelementptr inbounds i8 addrspace(1)* %foo, i64 10
638 %cast1 = bitcast i32 addrspace(1)* %gep1 to i8 addrspace(1)*
639 %cmp = icmp ult i8 addrspace(1)* %cast1, %gep2
640 %use = ptrtoint i8 addrspace(1)* %cast1 to i64
641 %call = call i32 @test58_d(i64 %use) nounwind
644 ; CHECK: %[[GEP:.+]] = getelementptr inbounds i8 addrspace(1)* %foo, i16 8
645 ; CHECK: ptrtoint i8 addrspace(1)* %[[GEP]] to i16
649 define i1 @test60(i8* %foo, i64 %i, i64 %j) {
650 %bit = bitcast i8* %foo to i32*
651 %gep1 = getelementptr inbounds i32* %bit, i64 %i
652 %gep2 = getelementptr inbounds i8* %foo, i64 %j
653 %cast1 = bitcast i32* %gep1 to i8*
654 %cmp = icmp ult i8* %cast1, %gep2
656 ; CHECK-LABEL: @test60(
657 ; CHECK-NEXT: %gep1.idx = shl nuw i64 %i, 2
658 ; CHECK-NEXT: icmp slt i64 %gep1.idx, %j
662 define i1 @test60_as1(i8 addrspace(1)* %foo, i64 %i, i64 %j) {
663 %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)*
664 %gep1 = getelementptr inbounds i32 addrspace(1)* %bit, i64 %i
665 %gep2 = getelementptr inbounds i8 addrspace(1)* %foo, i64 %j
666 %cast1 = bitcast i32 addrspace(1)* %gep1 to i8 addrspace(1)*
667 %cmp = icmp ult i8 addrspace(1)* %cast1, %gep2
670 ; CHECK: trunc i64 %i to i16
671 ; CHECK: trunc i64 %j to i16
672 ; CHECK: %gep1.idx = shl nuw i16 %{{.+}}, 2
673 ; CHECK-NEXT: icmp sgt i16 %{{.+}}, %gep1.idx
677 define i1 @test61(i8* %foo, i64 %i, i64 %j) {
678 %bit = bitcast i8* %foo to i32*
679 %gep1 = getelementptr i32* %bit, i64 %i
680 %gep2 = getelementptr i8* %foo, i64 %j
681 %cast1 = bitcast i32* %gep1 to i8*
682 %cmp = icmp ult i8* %cast1, %gep2
684 ; Don't transform non-inbounds GEPs.
685 ; CHECK-LABEL: @test61(
686 ; CHECK: icmp ult i8* %cast1, %gep2
690 define i1 @test61_as1(i8 addrspace(1)* %foo, i16 %i, i16 %j) {
691 %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)*
692 %gep1 = getelementptr i32 addrspace(1)* %bit, i16 %i
693 %gep2 = getelementptr i8 addrspace(1)* %foo, i16 %j
694 %cast1 = bitcast i32 addrspace(1)* %gep1 to i8 addrspace(1)*
695 %cmp = icmp ult i8 addrspace(1)* %cast1, %gep2
697 ; Don't transform non-inbounds GEPs.
699 ; CHECK: icmp ult i8 addrspace(1)* %cast1, %gep2
703 define i1 @test62(i8* %a) {
704 %arrayidx1 = getelementptr inbounds i8* %a, i64 1
705 %arrayidx2 = getelementptr inbounds i8* %a, i64 10
706 %cmp = icmp slt i8* %arrayidx1, %arrayidx2
708 ; CHECK-LABEL: @test62(
709 ; CHECK-NEXT: ret i1 true
712 define i1 @test62_as1(i8 addrspace(1)* %a) {
713 ; CHECK-LABEL: @test62_as1(
714 ; CHECK-NEXT: ret i1 true
715 %arrayidx1 = getelementptr inbounds i8 addrspace(1)* %a, i64 1
716 %arrayidx2 = getelementptr inbounds i8 addrspace(1)* %a, i64 10
717 %cmp = icmp slt i8 addrspace(1)* %arrayidx1, %arrayidx2
721 define i1 @test63(i8 %a, i32 %b) nounwind {
722 %z = zext i8 %a to i32
724 %c = icmp eq i32 %z, %t
726 ; CHECK-LABEL: @test63(
727 ; CHECK-NEXT: %1 = trunc i32 %b to i8
728 ; CHECK-NEXT: %c = icmp eq i8 %1, %a
729 ; CHECK-NEXT: ret i1 %c
732 define i1 @test64(i8 %a, i32 %b) nounwind {
734 %z = zext i8 %a to i32
735 %c = icmp eq i32 %t, %z
737 ; CHECK-LABEL: @test64(
738 ; CHECK-NEXT: %1 = trunc i32 %b to i8
739 ; CHECK-NEXT: %c = icmp eq i8 %1, %a
740 ; CHECK-NEXT: ret i1 %c
743 define i1 @test65(i64 %A, i64 %B) {
746 %cmp = icmp eq i64 %s1, %s2
747 ; CHECK-LABEL: @test65(
748 ; CHECK-NEXT: ret i1 true
752 define i1 @test66(i64 %A, i64 %B) {
755 %cmp = icmp eq i64 %s1, %s2
756 ; CHECK-LABEL: @test66(
757 ; CHECK-NEXT: ret i1 true
761 ; CHECK-LABEL: @test67(
762 ; CHECK: %and = and i32 %x, 96
763 ; CHECK: %cmp = icmp ne i32 %and, 0
764 define i1 @test67(i32 %x) nounwind uwtable {
765 %and = and i32 %x, 127
766 %cmp = icmp sgt i32 %and, 31
770 ; CHECK-LABEL: @test68(
771 ; CHECK: %cmp = icmp ugt i32 %and, 30
772 define i1 @test68(i32 %x) nounwind uwtable {
773 %and = and i32 %x, 127
774 %cmp = icmp sgt i32 %and, 30
779 ; CHECK-LABEL: @test69(
780 ; CHECK: %1 = and i32 %c, -33
781 ; CHECK: %2 = icmp eq i32 %1, 65
783 define i1 @test69(i32 %c) nounwind uwtable {
784 %1 = icmp eq i32 %c, 97
785 %2 = icmp eq i32 %c, 65
791 ; CHECK-LABEL: @test70(
792 ; CHECK-NEXT: %A = srem i32 5, %X
793 ; CHECK-NEXT: %C = icmp ne i32 %A, 2
794 ; CHECK-NEXT: ret i1 %C
795 define i1 @test70(i32 %X) {
798 %C = icmp ne i32 %B, 4
802 ; CHECK-LABEL: @icmp_sext16trunc(
803 ; CHECK-NEXT: %1 = trunc i32 %x to i16
804 ; CHECK-NEXT: %cmp = icmp slt i16 %1, 36
805 define i1 @icmp_sext16trunc(i32 %x) {
806 %trunc = trunc i32 %x to i16
807 %sext = sext i16 %trunc to i32
808 %cmp = icmp slt i32 %sext, 36
812 ; CHECK-LABEL: @icmp_sext8trunc(
813 ; CHECK-NEXT: %1 = trunc i32 %x to i8
814 ; CHECK-NEXT: %cmp = icmp slt i8 %1, 36
815 define i1 @icmp_sext8trunc(i32 %x) {
816 %trunc = trunc i32 %x to i8
817 %sext = sext i8 %trunc to i32
818 %cmp = icmp slt i32 %sext, 36
822 ; CHECK-LABEL: @icmp_shl16(
823 ; CHECK-NEXT: %1 = trunc i32 %x to i16
824 ; CHECK-NEXT: %cmp = icmp slt i16 %1, 36
825 define i1 @icmp_shl16(i32 %x) {
826 %shl = shl i32 %x, 16
827 %cmp = icmp slt i32 %shl, 2359296
831 ; CHECK-LABEL: @icmp_shl24(
832 ; CHECK-NEXT: %1 = trunc i32 %x to i8
833 ; CHECK-NEXT: %cmp = icmp slt i8 %1, 36
834 define i1 @icmp_shl24(i32 %x) {
835 %shl = shl i32 %x, 24
836 %cmp = icmp slt i32 %shl, 603979776
840 ; If the (shl x, C) preserved the sign and this is a sign test,
841 ; compare the LHS operand instead
842 ; CHECK-LABEL: @icmp_shl_nsw_sgt(
843 ; CHECK-NEXT: icmp sgt i32 %x, 0
844 define i1 @icmp_shl_nsw_sgt(i32 %x) {
845 %shl = shl nsw i32 %x, 21
846 %cmp = icmp sgt i32 %shl, 0
850 ; CHECK-LABEL: @icmp_shl_nsw_sge0(
851 ; CHECK-NEXT: icmp sgt i32 %x, -1
852 define i1 @icmp_shl_nsw_sge0(i32 %x) {
853 %shl = shl nsw i32 %x, 21
854 %cmp = icmp sge i32 %shl, 0
858 ; CHECK-LABEL: @icmp_shl_nsw_sge1(
859 ; CHECK-NEXT: icmp sgt i32 %x, 0
860 define i1 @icmp_shl_nsw_sge1(i32 %x) {
861 %shl = shl nsw i32 %x, 21
862 %cmp = icmp sge i32 %shl, 1
866 ; Checks for icmp (eq|ne) (shl x, C), 0
867 ; CHECK-LABEL: @icmp_shl_nsw_eq(
868 ; CHECK-NEXT: icmp eq i32 %x, 0
869 define i1 @icmp_shl_nsw_eq(i32 %x) {
870 %mul = shl nsw i32 %x, 5
871 %cmp = icmp eq i32 %mul, 0
875 ; CHECK-LABEL: @icmp_shl_eq(
876 ; CHECK-NOT: icmp eq i32 %mul, 0
877 define i1 @icmp_shl_eq(i32 %x) {
879 %cmp = icmp eq i32 %mul, 0
883 ; CHECK-LABEL: @icmp_shl_nsw_ne(
884 ; CHECK-NEXT: icmp ne i32 %x, 0
885 define i1 @icmp_shl_nsw_ne(i32 %x) {
886 %mul = shl nsw i32 %x, 7
887 %cmp = icmp ne i32 %mul, 0
891 ; CHECK-LABEL: @icmp_shl_ne(
892 ; CHECK-NOT: icmp ne i32 %x, 0
893 define i1 @icmp_shl_ne(i32 %x) {
895 %cmp = icmp ne i32 %mul, 0
899 ; If the (mul x, C) preserved the sign and this is sign test,
900 ; compare the LHS operand instead
901 ; CHECK-LABEL: @icmp_mul_nsw(
902 ; CHECK-NEXT: icmp sgt i32 %x, 0
903 define i1 @icmp_mul_nsw(i32 %x) {
904 %mul = mul nsw i32 %x, 12
905 %cmp = icmp sgt i32 %mul, 0
909 ; CHECK-LABEL: @icmp_mul_nsw1(
910 ; CHECK-NEXT: icmp slt i32 %x, 0
911 define i1 @icmp_mul_nsw1(i32 %x) {
912 %mul = mul nsw i32 %x, 12
913 %cmp = icmp sle i32 %mul, -1
917 ; CHECK-LABEL: @icmp_mul_nsw_neg(
918 ; CHECK-NEXT: icmp slt i32 %x, 1
919 define i1 @icmp_mul_nsw_neg(i32 %x) {
920 %mul = mul nsw i32 %x, -12
921 %cmp = icmp sge i32 %mul, 0
925 ; CHECK-LABEL: @icmp_mul_nsw_neg1(
926 ; CHECK-NEXT: icmp slt i32 %x, 0
927 define i1 @icmp_mul_nsw_neg1(i32 %x) {
928 %mul = mul nsw i32 %x, -12
929 %cmp = icmp sge i32 %mul, 1
933 ; CHECK-LABEL: @icmp_mul_nsw_0(
934 ; CHECK-NOT: icmp sgt i32 %x, 0
935 define i1 @icmp_mul_nsw_0(i32 %x) {
936 %mul = mul nsw i32 %x, 0
937 %cmp = icmp sgt i32 %mul, 0
941 ; CHECK-LABEL: @icmp_mul(
942 ; CHECK-NEXT: %mul = mul i32 %x, -12
943 define i1 @icmp_mul(i32 %x) {
944 %mul = mul i32 %x, -12
945 %cmp = icmp sge i32 %mul, 0
949 ; Checks for icmp (eq|ne) (mul x, C), 0
950 ; CHECK-LABEL: @icmp_mul_neq0(
951 ; CHECK-NEXT: icmp ne i32 %x, 0
952 define i1 @icmp_mul_neq0(i32 %x) {
953 %mul = mul nsw i32 %x, -12
954 %cmp = icmp ne i32 %mul, 0
958 ; CHECK-LABEL: @icmp_mul_eq0(
959 ; CHECK-NEXT: icmp eq i32 %x, 0
960 define i1 @icmp_mul_eq0(i32 %x) {
961 %mul = mul nsw i32 %x, 12
962 %cmp = icmp eq i32 %mul, 0
966 ; CHECK-LABEL: @icmp_mul0_eq0(
967 ; CHECK-NEXT: ret i1 true
968 define i1 @icmp_mul0_eq0(i32 %x) {
970 %cmp = icmp eq i32 %mul, 0
974 ; CHECK-LABEL: @icmp_mul0_ne0(
975 ; CHECK-NEXT: ret i1 false
976 define i1 @icmp_mul0_ne0(i32 %x) {
978 %cmp = icmp ne i32 %mul, 0
982 ; CHECK-LABEL: @icmp_sub1_sge(
983 ; CHECK-NEXT: icmp sgt i32 %x, %y
984 define i1 @icmp_sub1_sge(i32 %x, i32 %y) {
985 %sub = add nsw i32 %x, -1
986 %cmp = icmp sge i32 %sub, %y
990 ; CHECK-LABEL: @icmp_add1_sgt(
991 ; CHECK-NEXT: icmp sge i32 %x, %y
992 define i1 @icmp_add1_sgt(i32 %x, i32 %y) {
993 %add = add nsw i32 %x, 1
994 %cmp = icmp sgt i32 %add, %y
998 ; CHECK-LABEL: @icmp_sub1_slt(
999 ; CHECK-NEXT: icmp sle i32 %x, %y
1000 define i1 @icmp_sub1_slt(i32 %x, i32 %y) {
1001 %sub = add nsw i32 %x, -1
1002 %cmp = icmp slt i32 %sub, %y
1006 ; CHECK-LABEL: @icmp_add1_sle(
1007 ; CHECK-NEXT: icmp slt i32 %x, %y
1008 define i1 @icmp_add1_sle(i32 %x, i32 %y) {
1009 %add = add nsw i32 %x, 1
1010 %cmp = icmp sle i32 %add, %y
1014 ; CHECK-LABEL: @icmp_add20_sge_add57(
1015 ; CHECK-NEXT: [[ADD:%[a-z0-9]+]] = add nsw i32 %y, 37
1016 ; CHECK-NEXT: icmp sle i32 [[ADD]], %x
1017 define i1 @icmp_add20_sge_add57(i32 %x, i32 %y) {
1018 %1 = add nsw i32 %x, 20
1019 %2 = add nsw i32 %y, 57
1020 %cmp = icmp sge i32 %1, %2
1024 ; CHECK-LABEL: @icmp_sub57_sge_sub20(
1025 ; CHECK-NEXT: [[SUB:%[a-z0-9]+]] = add nsw i32 %x, -37
1026 ; CHECK-NEXT: icmp sge i32 [[SUB]], %y
1027 define i1 @icmp_sub57_sge_sub20(i32 %x, i32 %y) {
1028 %1 = add nsw i32 %x, -57
1029 %2 = add nsw i32 %y, -20
1030 %cmp = icmp sge i32 %1, %2
1034 ; CHECK-LABEL: @icmp_and_shl_neg_ne_0(
1035 ; CHECK-NEXT: [[SHL:%[a-z0-9]+]] = shl i32 1, %B
1036 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[SHL]], %A
1037 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[AND]], 0
1038 ; CHECK-NEXT: ret i1 [[CMP]]
1039 define i1 @icmp_and_shl_neg_ne_0(i32 %A, i32 %B) {
1040 %neg = xor i32 %A, -1
1041 %shl = shl i32 1, %B
1042 %and = and i32 %shl, %neg
1043 %cmp = icmp ne i32 %and, 0
1047 ; CHECK-LABEL: @icmp_and_shl_neg_eq_0(
1048 ; CHECK-NEXT: [[SHL:%[a-z0-9]+]] = shl i32 1, %B
1049 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[SHL]], %A
1050 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[AND]], 0
1051 ; CHECK-NEXT: ret i1 [[CMP]]
1052 define i1 @icmp_and_shl_neg_eq_0(i32 %A, i32 %B) {
1053 %neg = xor i32 %A, -1
1054 %shl = shl i32 1, %B
1055 %and = and i32 %shl, %neg
1056 %cmp = icmp eq i32 %and, 0
1060 ; CHECK-LABEL: @icmp_add_and_shr_ne_0(
1061 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, 240
1062 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[AND]], 224
1063 ; CHECK-NEXT: ret i1 [[CMP]]
1064 define i1 @icmp_add_and_shr_ne_0(i32 %X) {
1065 %shr = lshr i32 %X, 4
1066 %and = and i32 %shr, 15
1067 %add = add i32 %and, -14
1068 %tobool = icmp ne i32 %add, 0
1073 ; CHECK-LABEL: define i1 @test71(
1074 ; CHECK-NEXT: ret i1 false
1075 define i1 @test71(i8* %x) {
1076 %a = getelementptr i8* %x, i64 8
1077 %b = getelementptr inbounds i8* %x, i64 8
1078 %c = icmp ugt i8* %a, %b
1082 define i1 @test71_as1(i8 addrspace(1)* %x) {
1083 ; CHECK-LABEL: @test71_as1(
1084 ; CHECK-NEXT: ret i1 false
1085 %a = getelementptr i8 addrspace(1)* %x, i64 8
1086 %b = getelementptr inbounds i8 addrspace(1)* %x, i64 8
1087 %c = icmp ugt i8 addrspace(1)* %a, %b
1091 ; CHECK-LABEL: @icmp_shl_1_V_ult_32(
1092 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %V, 5
1093 ; CHECK-NEXT: ret i1 [[CMP]]
1094 define i1 @icmp_shl_1_V_ult_32(i32 %V) {
1095 %shl = shl i32 1, %V
1096 %cmp = icmp ult i32 %shl, 32
1100 ; CHECK-LABEL: @icmp_shl_1_V_eq_32(
1101 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 %V, 5
1102 ; CHECK-NEXT: ret i1 [[CMP]]
1103 define i1 @icmp_shl_1_V_eq_32(i32 %V) {
1104 %shl = shl i32 1, %V
1105 %cmp = icmp eq i32 %shl, 32
1109 ; CHECK-LABEL: @icmp_shl_1_V_eq_31(
1110 ; CHECK-NEXT: ret i1 false
1111 define i1 @icmp_shl_1_V_eq_31(i32 %V) {
1112 %shl = shl i32 1, %V
1113 %cmp = icmp eq i32 %shl, 31
1117 ; CHECK-LABEL: @icmp_shl_1_V_ne_31(
1118 ; CHECK-NEXT: ret i1 true
1119 define i1 @icmp_shl_1_V_ne_31(i32 %V) {
1120 %shl = shl i32 1, %V
1121 %cmp = icmp ne i32 %shl, 31
1125 ; CHECK-LABEL: @icmp_shl_1_V_ult_30(
1126 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %V, 5
1127 ; CHECK-NEXT: ret i1 [[CMP]]
1128 define i1 @icmp_shl_1_V_ult_30(i32 %V) {
1129 %shl = shl i32 1, %V
1130 %cmp = icmp ult i32 %shl, 30
1134 ; CHECK-LABEL: @icmp_shl_1_V_ugt_30(
1135 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %V, 4
1136 ; CHECK-NEXT: ret i1 [[CMP]]
1137 define i1 @icmp_shl_1_V_ugt_30(i32 %V) {
1138 %shl = shl i32 1, %V
1139 %cmp = icmp ugt i32 %shl, 30
1143 ; CHECK-LABEL: @icmp_shl_1_V_ule_30(
1144 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %V, 5
1145 ; CHECK-NEXT: ret i1 [[CMP]]
1146 define i1 @icmp_shl_1_V_ule_30(i32 %V) {
1147 %shl = shl i32 1, %V
1148 %cmp = icmp ule i32 %shl, 30
1152 ; CHECK-LABEL: @icmp_shl_1_V_uge_30(
1153 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %V, 4
1154 ; CHECK-NEXT: ret i1 [[CMP]]
1155 define i1 @icmp_shl_1_V_uge_30(i32 %V) {
1156 %shl = shl i32 1, %V
1157 %cmp = icmp uge i32 %shl, 30
1161 ; CHECK-LABEL: @icmp_shl_1_V_uge_2147483648(
1162 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 %V, 31
1163 ; CHECK-NEXT: ret i1 [[CMP]]
1164 define i1 @icmp_shl_1_V_uge_2147483648(i32 %V) {
1165 %shl = shl i32 1, %V
1166 %cmp = icmp uge i32 %shl, 2147483648
1170 ; CHECK-LABEL: @icmp_shl_1_V_ugt_2147483648(
1171 ; CHECK-NEXT: ret i1 false
1172 define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) {
1173 %shl = shl i32 1, %V
1174 %cmp = icmp ugt i32 %shl, 2147483648
1178 ; CHECK-LABEL: @icmp_shl_1_V_ule_2147483648(
1179 ; CHECK-NEXT: ret i1 true
1180 define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) {
1181 %shl = shl i32 1, %V
1182 %cmp = icmp ule i32 %shl, 2147483648
1186 ; CHECK-LABEL: @icmp_shl_1_V_ult_2147483648(
1187 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %V, 31
1188 ; CHECK-NEXT: ret i1 [[CMP]]
1189 define i1 @icmp_shl_1_V_ult_2147483648(i32 %V) {
1190 %shl = shl i32 1, %V
1191 %cmp = icmp ult i32 %shl, 2147483648
1195 ; CHECK-LABEL: @or_icmp_eq_B_0_icmp_ult_A_B(
1196 ; CHECK-NEXT: [[SUB:%[a-z0-9]+]] = add i64 %b, -1
1197 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp uge i64 [[SUB]], %a
1198 ; CHECK-NEXT: ret i1 [[CMP]]
1199 define i1 @or_icmp_eq_B_0_icmp_ult_A_B(i64 %a, i64 %b) {
1200 %1 = icmp eq i64 %b, 0
1201 %2 = icmp ult i64 %a, %b
1206 ; CHECK-LABEL: @icmp_add_ult_2(
1207 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, -2
1208 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[AND]], 14
1209 ; CHECK-NEXT: ret i1 [[CMP]]
1210 define i1 @icmp_add_ult_2(i32 %X) {
1211 %add = add i32 %X, -14
1212 %cmp = icmp ult i32 %add, 2
1216 ; CHECK: @icmp_add_X_-14_ult_2
1217 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, -2
1218 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[AND]], 14
1219 ; CHECK-NEXT: ret i1 [[CMP]]
1220 define i1 @icmp_add_X_-14_ult_2(i32 %X) {
1221 %add = add i32 %X, -14
1222 %cmp = icmp ult i32 %add, 2
1226 ; CHECK-LABEL: @icmp_sub_3_X_ult_2(
1227 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %X, 1
1228 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[OR]], 3
1229 ; CHECK-NEXT: ret i1 [[CMP]]
1230 define i1 @icmp_sub_3_X_ult_2(i32 %X) {
1231 %add = sub i32 3, %X
1232 %cmp = icmp ult i32 %add, 2
1236 ; CHECK: @icmp_add_X_-14_uge_2
1237 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, -2
1238 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[AND]], 14
1239 ; CHECK-NEXT: ret i1 [[CMP]]
1240 define i1 @icmp_add_X_-14_uge_2(i32 %X) {
1241 %add = add i32 %X, -14
1242 %cmp = icmp uge i32 %add, 2
1246 ; CHECK-LABEL: @icmp_sub_3_X_uge_2(
1247 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %X, 1
1248 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[OR]], 3
1249 ; CHECK-NEXT: ret i1 [[CMP]]
1250 define i1 @icmp_sub_3_X_uge_2(i32 %X) {
1251 %add = sub i32 3, %X
1252 %cmp = icmp uge i32 %add, 2
1256 ; CHECK: @icmp_and_X_-16_eq-16
1257 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %X, -17
1258 ; CHECK-NEXT: ret i1 [[CMP]]
1259 define i1 @icmp_and_X_-16_eq-16(i32 %X) {
1260 %and = and i32 %X, -16
1261 %cmp = icmp eq i32 %and, -16
1265 ; CHECK: @icmp_and_X_-16_ne-16
1266 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %X, -16
1267 ; CHECK-NEXT: ret i1 [[CMP]]
1268 define i1 @icmp_and_X_-16_ne-16(i32 %X) {
1269 %and = and i32 %X, -16
1270 %cmp = icmp ne i32 %and, -16
1274 ; CHECK: @icmp_sub_-1_X_ult_4
1275 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %X, -5
1276 ; CHECK-NEXT: ret i1 [[CMP]]
1277 define i1 @icmp_sub_-1_X_ult_4(i32 %X) {
1278 %sub = sub i32 -1, %X
1279 %cmp = icmp ult i32 %sub, 4
1283 ; CHECK: @icmp_sub_-1_X_uge_4
1284 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %X, -4
1285 ; CHECK-NEXT: ret i1 [[CMP]]
1286 define i1 @icmp_sub_-1_X_uge_4(i32 %X) {
1287 %sub = sub i32 -1, %X
1288 %cmp = icmp uge i32 %sub, 4
1292 ; CHECK-LABEL: @icmp_swap_operands_for_cse
1293 ; CHECK: [[CMP:%[a-z0-9]+]] = icmp ult i32 %X, %Y
1294 ; CHECK-NEXT: br i1 [[CMP]], label %true, label %false
1296 define i1 @icmp_swap_operands_for_cse(i32 %X, i32 %Y) {
1298 %sub = sub i32 %X, %Y
1299 %cmp = icmp ugt i32 %Y, %X
1300 br i1 %cmp, label %true, label %false
1302 %restrue = trunc i32 %sub to i1
1305 %shift = lshr i32 %sub, 4
1306 %resfalse = trunc i32 %shift to i1
1309 %res = phi i1 [%restrue, %true], [%resfalse, %false]
1313 ; CHECK-LABEL: @icmp_swap_operands_for_cse2
1314 ; CHECK: [[CMP:%[a-z0-9]+]] = icmp ult i32 %X, %Y
1315 ; CHECK-NEXT: br i1 [[CMP]], label %true, label %false
1317 define i1 @icmp_swap_operands_for_cse2(i32 %X, i32 %Y) {
1319 %cmp = icmp ugt i32 %Y, %X
1320 br i1 %cmp, label %true, label %false
1322 %sub = sub i32 %X, %Y
1323 %sub1 = sub i32 %X, %Y
1324 %add = add i32 %sub, %sub1
1325 %restrue = trunc i32 %add to i1
1328 %sub2 = sub i32 %Y, %X
1329 %resfalse = trunc i32 %sub2 to i1
1332 %res = phi i1 [%restrue, %true], [%resfalse, %false]
1336 ; CHECK-LABEL: @icmp_do_not_swap_operands_for_cse
1337 ; CHECK: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %Y, %X
1338 ; CHECK-NEXT: br i1 [[CMP]], label %true, label %false
1340 define i1 @icmp_do_not_swap_operands_for_cse(i32 %X, i32 %Y) {
1342 %cmp = icmp ugt i32 %Y, %X
1343 br i1 %cmp, label %true, label %false
1345 %sub = sub i32 %X, %Y
1346 %restrue = trunc i32 %sub to i1
1349 %sub2 = sub i32 %Y, %X
1350 %resfalse = trunc i32 %sub2 to i1
1353 %res = phi i1 [%restrue, %true], [%resfalse, %false]
1357 ; CHECK-LABEL: @icmp_lshr_lshr_eq
1358 ; CHECK: %z.unshifted = xor i32 %a, %b
1359 ; CHECK: %z = icmp ult i32 %z.unshifted, 1073741824
1360 define i1 @icmp_lshr_lshr_eq(i32 %a, i32 %b) nounwind {
1361 %x = lshr i32 %a, 30
1362 %y = lshr i32 %b, 30
1363 %z = icmp eq i32 %x, %y
1367 ; CHECK-LABEL: @icmp_ashr_ashr_ne
1368 ; CHECK: %z.unshifted = xor i32 %a, %b
1369 ; CHECK: %z = icmp ugt i32 %z.unshifted, 255
1370 define i1 @icmp_ashr_ashr_ne(i32 %a, i32 %b) nounwind {
1373 %z = icmp ne i32 %x, %y
1377 ; CHECK-LABEL: @icmp_neg_cst_slt
1378 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %a, 10
1379 ; CHECK-NEXT: ret i1 [[CMP]]
1380 define i1 @icmp_neg_cst_slt(i32 %a) {
1381 %1 = sub nsw i32 0, %a
1382 %2 = icmp slt i32 %1, -10
1386 ; CHECK-LABEL: @exact_ashr_eq_false
1387 ; CHECK-NEXT: icmp eq i32 %a, 1
1388 define i1 @exact_ashr_eq_false(i32 %a) {
1389 %shr = ashr exact i32 -30, %a
1390 %cmp = icmp eq i32 %shr, -15
1394 ; CHECK-LABEL: @exact_lhsr
1395 ; CHECK-NEXT: icmp eq i32 %a, 3
1396 define i1 @exact_lhsr(i32 %a) {
1397 %shr = lshr exact i32 80, %a
1398 %cmp = icmp eq i32 %shr, 10