1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-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 ; CHECK-NEXT: [[X_LOBIT:%.*]] = lshr i32 [[X:%.*]], 31
9 ; CHECK-NEXT: ret i32 [[X_LOBIT]]
11 %a = icmp slt i32 %X, 0
12 %b = zext i1 %a to i32
16 define <2 x i32> @test1vec(<2 x i32> %X) {
17 ; CHECK-LABEL: @test1vec(
18 ; CHECK-NEXT: [[X_LOBIT:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 31, i32 31>
19 ; CHECK-NEXT: ret <2 x i32> [[X_LOBIT]]
21 %a = icmp slt <2 x i32> %X, zeroinitializer
22 %b = zext <2 x i1> %a to <2 x i32>
26 define i32 @test2(i32 %X) {
27 ; CHECK-LABEL: @test2(
28 ; CHECK-NEXT: [[X_LOBIT:%.*]] = lshr i32 [[X:%.*]], 31
29 ; CHECK-NEXT: [[X_LOBIT_NOT:%.*]] = xor i32 [[X_LOBIT]], 1
30 ; CHECK-NEXT: ret i32 [[X_LOBIT_NOT]]
32 %a = icmp ult i32 %X, -2147483648
33 %b = zext i1 %a to i32
37 define <2 x i32> @test2vec(<2 x i32> %X) {
38 ; CHECK-LABEL: @test2vec(
39 ; CHECK-NEXT: [[X_LOBIT:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 31, i32 31>
40 ; CHECK-NEXT: [[X_LOBIT_NOT:%.*]] = xor <2 x i32> [[X_LOBIT]], <i32 1, i32 1>
41 ; CHECK-NEXT: ret <2 x i32> [[X_LOBIT_NOT]]
43 %a = icmp ult <2 x i32> %X, <i32 -2147483648, i32 -2147483648>
44 %b = zext <2 x i1> %a to <2 x i32>
48 define i32 @test3(i32 %X) {
49 ; CHECK-LABEL: @test3(
50 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i32 [[X:%.*]], 31
51 ; CHECK-NEXT: ret i32 [[X_LOBIT]]
53 %a = icmp slt i32 %X, 0
54 %b = sext i1 %a to i32
58 define i32 @test4(i32 %X) {
59 ; CHECK-LABEL: @test4(
60 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i32 [[X:%.*]], 31
61 ; CHECK-NEXT: [[X_LOBIT_NOT:%.*]] = xor i32 [[X_LOBIT]], -1
62 ; CHECK-NEXT: ret i32 [[X_LOBIT_NOT]]
64 %a = icmp ult i32 %X, -2147483648
65 %b = sext i1 %a to i32
70 define <2 x i1> @test5_eq(<2 x i64> %x) {
71 ; CHECK-LABEL: @test5_eq(
72 ; CHECK-NEXT: ret <2 x i1> undef
74 %V = icmp eq <2 x i64> %x, undef
77 define <2 x i1> @test5_ne(<2 x i64> %x) {
78 ; CHECK-LABEL: @test5_ne(
79 ; CHECK-NEXT: ret <2 x i1> undef
81 %V = icmp ne <2 x i64> %x, undef
84 define <2 x i1> @test5_ugt(<2 x i64> %x) {
85 ; CHECK-LABEL: @test5_ugt(
86 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
88 %V = icmp ugt <2 x i64> %x, undef
91 define <2 x i1> @test5_zero() {
92 ; CHECK-LABEL: @test5_zero(
93 ; CHECK-NEXT: ret <2 x i1> undef
95 %V = icmp eq <2 x i64> zeroinitializer, undef
99 define i32 @test6(i32 %a, i32 %b) {
100 ; CHECK-LABEL: @test6(
101 ; CHECK-NEXT: [[E:%.*]] = ashr i32 [[A:%.*]], 31
102 ; CHECK-NEXT: [[F:%.*]] = and i32 [[E]], [[B:%.*]]
103 ; CHECK-NEXT: ret i32 [[F]]
105 %c = icmp sle i32 %a, -1
106 %d = zext i1 %c to i32
113 define i1 @test7(i32 %x) {
114 ; CHECK-LABEL: @test7(
115 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[X:%.*]], 0
116 ; CHECK-NEXT: ret i1 [[B]]
119 %b = icmp ult i32 %a, %x
123 define <2 x i1> @test7_vec(<2 x i32> %x) {
124 ; CHECK-LABEL: @test7_vec(
125 ; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i32> [[X:%.*]], zeroinitializer
126 ; CHECK-NEXT: ret <2 x i1> [[B]]
128 %a = add <2 x i32> %x, <i32 -1, i32 -1>
129 %b = icmp ult <2 x i32> %a, %x
133 define i1 @test8(i32 %x) {
134 ; CHECK-LABEL: @test8(
135 ; CHECK-NEXT: ret i1 false
138 %b = icmp eq i32 %a, %x
142 define <2 x i1> @test8_vec(<2 x i32> %x) {
143 ; CHECK-LABEL: @test8_vec(
144 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
146 %a = add <2 x i32> %x, <i32 -1, i32 -1>
147 %b = icmp eq <2 x i32> %a, %x
151 define i1 @test9(i32 %x) {
152 ; CHECK-LABEL: @test9(
153 ; CHECK-NEXT: [[B:%.*]] = icmp ugt i32 [[X:%.*]], 1
154 ; CHECK-NEXT: ret i1 [[B]]
157 %b = icmp ugt i32 %x, %a
161 define <2 x i1> @test9_vec(<2 x i32> %x) {
162 ; CHECK-LABEL: @test9_vec(
163 ; CHECK-NEXT: [[B:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 1, i32 1>
164 ; CHECK-NEXT: ret <2 x i1> [[B]]
166 %a = add <2 x i32> %x, <i32 -2, i32 -2>
167 %b = icmp ugt <2 x i32> %x, %a
171 define i1 @test9b(i32 %x) {
172 ; CHECK-LABEL: @test9b(
173 ; CHECK-NEXT: [[B:%.*]] = icmp ult i32 [[X:%.*]], 2
174 ; CHECK-NEXT: ret i1 [[B]]
177 %b = icmp ugt i32 %a, %x
181 define <2 x i1> @test9b_vec(<2 x i32> %x) {
182 ; CHECK-LABEL: @test9b_vec(
183 ; CHECK-NEXT: [[B:%.*]] = icmp ult <2 x i32> [[X:%.*]], <i32 2, i32 2>
184 ; CHECK-NEXT: ret <2 x i1> [[B]]
186 %a = add <2 x i32> %x, <i32 -2, i32 -2>
187 %b = icmp ugt <2 x i32> %a, %x
191 define i1 @test10(i32 %x) {
192 ; CHECK-LABEL: @test10(
193 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[X:%.*]], -2147483648
194 ; CHECK-NEXT: ret i1 [[B]]
197 %b = icmp slt i32 %a, %x
201 define <2 x i1> @test10_vec(<2 x i32> %x) {
202 ; CHECK-LABEL: @test10_vec(
203 ; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i32> [[X:%.*]], <i32 -2147483648, i32 -2147483648>
204 ; CHECK-NEXT: ret <2 x i1> [[B]]
206 %a = add <2 x i32> %x, <i32 -1, i32 -1>
207 %b = icmp slt <2 x i32> %a, %x
211 define i1 @test10b(i32 %x) {
212 ; CHECK-LABEL: @test10b(
213 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[X:%.*]], -2147483648
214 ; CHECK-NEXT: ret i1 [[B]]
217 %b = icmp sgt i32 %a, %x
221 define <2 x i1> @test10b_vec(<2 x i32> %x) {
222 ; CHECK-LABEL: @test10b_vec(
223 ; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i32> [[X:%.*]], <i32 -2147483648, i32 -2147483648>
224 ; CHECK-NEXT: ret <2 x i1> [[B]]
226 %a = add <2 x i32> %x, <i32 -1, i32 -1>
227 %b = icmp sgt <2 x i32> %a, %x
231 define i1 @test11(i32 %x) {
232 ; CHECK-LABEL: @test11(
233 ; CHECK-NEXT: ret i1 true
235 %a = add nsw i32 %x, 8
236 %b = icmp slt i32 %x, %a
240 define <2 x i1> @test11_vec(<2 x i32> %x) {
241 ; CHECK-LABEL: @test11_vec(
242 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
244 %a = add nsw <2 x i32> %x, <i32 8, i32 8>
245 %b = icmp slt <2 x i32> %x, %a
250 define i1 @test12(i1 %A) {
251 ; CHECK-LABEL: @test12(
252 ; CHECK-NEXT: [[NOT_A:%.*]] = xor i1 [[A:%.*]], true
253 ; CHECK-NEXT: ret i1 [[NOT_A]]
255 %S = select i1 %A, i64 -4294967295, i64 8589934591
256 %B = icmp ne i64 bitcast (<2 x i32> <i32 1, i32 -1> to i64), %S
261 define i1 @test13(i8 %X) {
262 ; CHECK-LABEL: @test13(
263 ; CHECK-NEXT: ret i1 false
265 %cmp = icmp slt i8 undef, %X
269 define i1 @test14(i8 %X) {
270 ; CHECK-LABEL: @test14(
271 ; CHECK-NEXT: ret i1 false
273 %cmp = icmp slt i8 undef, -128
277 define i1 @test15() {
278 ; CHECK-LABEL: @test15(
279 ; CHECK-NEXT: ret i1 undef
281 %cmp = icmp eq i8 undef, -128
285 define i1 @test16() {
286 ; CHECK-LABEL: @test16(
287 ; CHECK-NEXT: ret i1 undef
289 %cmp = icmp ne i8 undef, -128
293 define i1 @test17(i32 %x) {
294 ; CHECK-LABEL: @test17(
295 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 3
296 ; CHECK-NEXT: ret i1 [[CMP]]
299 %and = and i32 %shl, 8
300 %cmp = icmp eq i32 %and, 0
304 define <2 x i1> @test17vec(<2 x i32> %x) {
305 ; CHECK-LABEL: @test17vec(
306 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[X:%.*]], <i32 3, i32 3>
307 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
309 %shl = shl <2 x i32> <i32 1, i32 1>, %x
310 %and = and <2 x i32> %shl, <i32 8, i32 8>
311 %cmp = icmp eq <2 x i32> %and, zeroinitializer
315 define i1 @test17a(i32 %x) {
316 ; CHECK-LABEL: @test17a(
317 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], 2
318 ; CHECK-NEXT: ret i1 [[CMP]]
321 %and = and i32 %shl, 7
322 %cmp = icmp eq i32 %and, 0
326 define <2 x i1> @test17a_vec(<2 x i32> %x) {
327 ; CHECK-LABEL: @test17a_vec(
328 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 2, i32 2>
329 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
331 %shl = shl <2 x i32> <i32 1, i32 1>, %x
332 %and = and <2 x i32> %shl, <i32 7, i32 7>
333 %cmp = icmp eq <2 x i32> %and, zeroinitializer
337 define i1 @test18_eq(i32 %x) {
338 ; CHECK-LABEL: @test18_eq(
339 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 3
340 ; CHECK-NEXT: ret i1 [[CMP]]
343 %and = and i32 %sh, 1
344 %cmp = icmp eq i32 %and, 0
348 define <2 x i1> @test18_eq_vec(<2 x i32> %x) {
349 ; CHECK-LABEL: @test18_eq_vec(
350 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[X:%.*]], <i32 3, i32 3>
351 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
353 %sh = lshr <2 x i32> <i32 8, i32 8>, %x
354 %and = and <2 x i32> %sh, <i32 1, i32 1>
355 %cmp = icmp eq <2 x i32> %and, zeroinitializer
359 define i1 @test18_ne(i32 %x) {
360 ; CHECK-LABEL: @test18_ne(
361 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 3
362 ; CHECK-NEXT: ret i1 [[CMP]]
365 %and = and i32 %sh, 1
366 %cmp = icmp ne i32 %and, 0
370 define <2 x i1> @test18_ne_vec(<2 x i32> %x) {
371 ; CHECK-LABEL: @test18_ne_vec(
372 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[X:%.*]], <i32 3, i32 3>
373 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
375 %sh = lshr <2 x i32> <i32 8, i32 8>, %x
376 %and = and <2 x i32> %sh, <i32 1, i32 1>
377 %cmp = icmp ne <2 x i32> %and, zeroinitializer
381 define i1 @test19(i32 %x) {
382 ; CHECK-LABEL: @test19(
383 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 3
384 ; CHECK-NEXT: ret i1 [[CMP]]
387 %and = and i32 %shl, 8
388 %cmp = icmp eq i32 %and, 8
392 define <2 x i1> @test19vec(<2 x i32> %x) {
393 ; CHECK-LABEL: @test19vec(
394 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[X:%.*]], <i32 3, i32 3>
395 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
397 %shl = shl <2 x i32> <i32 1, i32 1>, %x
398 %and = and <2 x i32> %shl, <i32 8, i32 8>
399 %cmp = icmp eq <2 x i32> %and, <i32 8, i32 8>
403 define <2 x i1> @cmp_and_signbit_vec(<2 x i3> %x) {
404 ; CHECK-LABEL: @cmp_and_signbit_vec(
405 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i3> [[X:%.*]], zeroinitializer
406 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
408 %and = and <2 x i3> %x, <i3 4, i3 4>
409 %cmp = icmp ne <2 x i3> %and, zeroinitializer
413 define i1 @test20(i32 %x) {
414 ; CHECK-LABEL: @test20(
415 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 3
416 ; CHECK-NEXT: ret i1 [[CMP]]
419 %and = and i32 %shl, 8
420 %cmp = icmp ne i32 %and, 0
424 define <2 x i1> @test20vec(<2 x i32> %x) {
425 ; CHECK-LABEL: @test20vec(
426 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[X:%.*]], <i32 3, i32 3>
427 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
429 %shl = shl <2 x i32> <i32 1, i32 1>, %x
430 %and = and <2 x i32> %shl, <i32 8, i32 8>
431 %cmp = icmp ne <2 x i32> %and, zeroinitializer
435 define i1 @test20a(i32 %x) {
436 ; CHECK-LABEL: @test20a(
437 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], 3
438 ; CHECK-NEXT: ret i1 [[CMP]]
441 %and = and i32 %shl, 7
442 %cmp = icmp ne i32 %and, 0
446 define <2 x i1> @test20a_vec(<2 x i32> %x) {
447 ; CHECK-LABEL: @test20a_vec(
448 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[X:%.*]], <i32 3, i32 3>
449 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
451 %shl = shl <2 x i32> <i32 1, i32 1>, %x
452 %and = and <2 x i32> %shl, <i32 7, i32 7>
453 %cmp = icmp ne <2 x i32> %and, zeroinitializer
457 define i1 @test21(i8 %x, i8 %y) {
458 ; CHECK-LABEL: @test21(
459 ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[X:%.*]], 3
460 ; CHECK-NEXT: ret i1 [[B]]
463 %B = icmp ugt i8 %A, 3
467 define i1 @test22(i8 %x, i8 %y) {
468 ; CHECK-LABEL: @test22(
469 ; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[X:%.*]], 4
470 ; CHECK-NEXT: ret i1 [[B]]
473 %B = icmp ult i8 %A, 4
478 define i1 @test23(i32 %x) {
479 ; CHECK-LABEL: @test23(
480 ; CHECK-NEXT: [[I4:%.*]] = icmp sgt i32 [[X:%.*]], 1328634634
481 ; CHECK-NEXT: ret i1 [[I4]]
483 %i3 = sdiv i32 %x, -1328634635
484 %i4 = icmp eq i32 %i3, -1
488 define <2 x i1> @test23vec(<2 x i32> %x) {
489 ; CHECK-LABEL: @test23vec(
490 ; CHECK-NEXT: [[I4:%.*]] = icmp sgt <2 x i32> [[X:%.*]], <i32 1328634634, i32 1328634634>
491 ; CHECK-NEXT: ret <2 x i1> [[I4]]
493 %i3 = sdiv <2 x i32> %x, <i32 -1328634635, i32 -1328634635>
494 %i4 = icmp eq <2 x i32> %i3, <i32 -1, i32 -1>
498 @X = global [1000 x i32] zeroinitializer
501 define i1 @test24(i64 %i) {
502 ; CHECK-LABEL: @test24(
503 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[I:%.*]], 1000
504 ; CHECK-NEXT: ret i1 [[CMP]]
506 %p1 = getelementptr inbounds i32, i32* getelementptr inbounds ([1000 x i32], [1000 x i32]* @X, i64 0, i64 0), i64 %i
507 %cmp = icmp eq i32* %p1, getelementptr inbounds ([1000 x i32], [1000 x i32]* @X, i64 1, i64 0)
511 @X_as1 = addrspace(1) global [1000 x i32] zeroinitializer
513 define i1 @test24_as1(i64 %i) {
514 ; CHECK-LABEL: @test24_as1(
515 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[I:%.*]] to i16
516 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[TMP1]], 1000
517 ; CHECK-NEXT: ret i1 [[CMP]]
519 %p1 = getelementptr inbounds i32, i32 addrspace(1)* getelementptr inbounds ([1000 x i32], [1000 x i32] addrspace(1)* @X_as1, i64 0, i64 0), i64 %i
520 %cmp = icmp eq i32 addrspace(1)* %p1, getelementptr inbounds ([1000 x i32], [1000 x i32] addrspace(1)* @X_as1, i64 1, i64 0)
524 ; X - Z > Y - Z -> X > Y if there is no overflow.
525 define i1 @test27(i32 %x, i32 %y, i32 %z) {
526 ; CHECK-LABEL: @test27(
527 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
528 ; CHECK-NEXT: ret i1 [[C]]
530 %lhs = sub nsw i32 %x, %z
531 %rhs = sub nsw i32 %y, %z
532 %c = icmp sgt i32 %lhs, %rhs
536 define i1 @test27_extra_uses(i32 %x, i32 %y, i32 %z) {
537 ; CHECK-LABEL: @test27_extra_uses(
538 ; CHECK-NEXT: [[LHS:%.*]] = sub nsw i32 [[X:%.*]], [[Z:%.*]]
539 ; CHECK-NEXT: call void @foo(i32 [[LHS]])
540 ; CHECK-NEXT: [[RHS:%.*]] = sub nsw i32 [[Y:%.*]], [[Z]]
541 ; CHECK-NEXT: call void @foo(i32 [[RHS]])
542 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X]], [[Y]]
543 ; CHECK-NEXT: ret i1 [[C]]
545 %lhs = sub nsw i32 %x, %z
546 call void @foo(i32 %lhs)
547 %rhs = sub nsw i32 %y, %z
548 call void @foo(i32 %rhs)
549 %c = icmp sgt i32 %lhs, %rhs
553 ; X - Z > Y - Z -> X > Y if there is no overflow.
554 define i1 @test28(i32 %x, i32 %y, i32 %z) {
555 ; CHECK-LABEL: @test28(
556 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
557 ; CHECK-NEXT: ret i1 [[C]]
559 %lhs = sub nuw i32 %x, %z
560 %rhs = sub nuw i32 %y, %z
561 %c = icmp ugt i32 %lhs, %rhs
565 define i1 @test28_extra_uses(i32 %x, i32 %y, i32 %z) {
566 ; CHECK-LABEL: @test28_extra_uses(
567 ; CHECK-NEXT: [[LHS:%.*]] = sub nuw i32 [[X:%.*]], [[Z:%.*]]
568 ; CHECK-NEXT: call void @foo(i32 [[LHS]])
569 ; CHECK-NEXT: [[RHS:%.*]] = sub nuw i32 [[Y:%.*]], [[Z]]
570 ; CHECK-NEXT: call void @foo(i32 [[RHS]])
571 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X]], [[Y]]
572 ; CHECK-NEXT: ret i1 [[C]]
574 %lhs = sub nuw i32 %x, %z
575 call void @foo(i32 %lhs)
576 %rhs = sub nuw i32 %y, %z
577 call void @foo(i32 %rhs)
578 %c = icmp ugt i32 %lhs, %rhs
582 ; PR36969 - https://bugs.llvm.org/show_bug.cgi?id=36969
584 define i1 @ugt_sub(i32 %xsrc, i32 %y) {
585 ; CHECK-LABEL: @ugt_sub(
586 ; CHECK-NEXT: [[X:%.*]] = udiv i32 [[XSRC:%.*]], 42
587 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X]], [[Y:%.*]]
588 ; CHECK-NEXT: ret i1 [[CMP]]
590 %x = udiv i32 %xsrc, 42 ; thwart complexity-based canonicalization
591 %sub = sub i32 %x, %y
592 %cmp = icmp ugt i32 %sub, %x
596 ; Swap operands and predicate. Try a vector type to verify that works too.
598 define <2 x i1> @ult_sub(<2 x i8> %xsrc, <2 x i8> %y) {
599 ; CHECK-LABEL: @ult_sub(
600 ; CHECK-NEXT: [[X:%.*]] = udiv <2 x i8> [[XSRC:%.*]], <i8 42, i8 -42>
601 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[X]], [[Y:%.*]]
602 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
604 %x = udiv <2 x i8> %xsrc, <i8 42, i8 -42> ; thwart complexity-based canonicalization
605 %sub = sub <2 x i8> %x, %y
606 %cmp = icmp ult <2 x i8> %x, %sub
610 ; X - Y > X -> 0 > Y if there is no overflow.
611 define i1 @test33(i32 %x, i32 %y) {
612 ; CHECK-LABEL: @test33(
613 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[Y:%.*]], 0
614 ; CHECK-NEXT: ret i1 [[C]]
616 %lhs = sub nsw i32 %x, %y
617 %c = icmp sgt i32 %lhs, %x
621 ; X - Y > X -> 0 > Y if there is no overflow.
622 define i1 @test34(i32 %x, i32 %y) {
623 ; CHECK-LABEL: @test34(
624 ; CHECK-NEXT: ret i1 false
626 %lhs = sub nuw i32 %x, %y
627 %c = icmp ugt i32 %lhs, %x
631 ; X > X - Y -> Y > 0 if there is no overflow.
632 define i1 @test35(i32 %x, i32 %y) {
633 ; CHECK-LABEL: @test35(
634 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[Y:%.*]], 0
635 ; CHECK-NEXT: ret i1 [[C]]
637 %rhs = sub nsw i32 %x, %y
638 %c = icmp sgt i32 %x, %rhs
642 ; X > X - Y -> Y > 0 if there is no overflow.
643 define i1 @test36(i32 %x, i32 %y) {
644 ; CHECK-LABEL: @test36(
645 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[Y:%.*]], 0
646 ; CHECK-NEXT: ret i1 [[C]]
648 %rhs = sub nuw i32 %x, %y
649 %c = icmp ugt i32 %x, %rhs
653 ; X - Y > X - Z -> Z > Y if there is no overflow.
654 define i1 @test37(i32 %x, i32 %y, i32 %z) {
655 ; CHECK-LABEL: @test37(
656 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[Z:%.*]], [[Y:%.*]]
657 ; CHECK-NEXT: ret i1 [[C]]
659 %lhs = sub nsw i32 %x, %y
660 %rhs = sub nsw i32 %x, %z
661 %c = icmp sgt i32 %lhs, %rhs
665 define i1 @test37_extra_uses(i32 %x, i32 %y, i32 %z) {
666 ; CHECK-LABEL: @test37_extra_uses(
667 ; CHECK-NEXT: [[LHS:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
668 ; CHECK-NEXT: call void @foo(i32 [[LHS]])
669 ; CHECK-NEXT: [[RHS:%.*]] = sub nsw i32 [[X]], [[Z:%.*]]
670 ; CHECK-NEXT: call void @foo(i32 [[RHS]])
671 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[Z]], [[Y]]
672 ; CHECK-NEXT: ret i1 [[C]]
674 %lhs = sub nsw i32 %x, %y
675 call void @foo(i32 %lhs)
676 %rhs = sub nsw i32 %x, %z
677 call void @foo(i32 %rhs)
678 %c = icmp sgt i32 %lhs, %rhs
682 ; X - Y > X - Z -> Z > Y if there is no overflow.
683 define i1 @test38(i32 %x, i32 %y, i32 %z) {
684 ; CHECK-LABEL: @test38(
685 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[Z:%.*]], [[Y:%.*]]
686 ; CHECK-NEXT: ret i1 [[C]]
688 %lhs = sub nuw i32 %x, %y
689 %rhs = sub nuw i32 %x, %z
690 %c = icmp ugt i32 %lhs, %rhs
694 define i1 @test38_extra_uses(i32 %x, i32 %y, i32 %z) {
695 ; CHECK-LABEL: @test38_extra_uses(
696 ; CHECK-NEXT: [[LHS:%.*]] = sub nuw i32 [[X:%.*]], [[Y:%.*]]
697 ; CHECK-NEXT: call void @foo(i32 [[LHS]])
698 ; CHECK-NEXT: [[RHS:%.*]] = sub nuw i32 [[X]], [[Z:%.*]]
699 ; CHECK-NEXT: call void @foo(i32 [[RHS]])
700 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[Z]], [[Y]]
701 ; CHECK-NEXT: ret i1 [[C]]
703 %lhs = sub nuw i32 %x, %y
704 call void @foo(i32 %lhs)
705 %rhs = sub nuw i32 %x, %z
706 call void @foo(i32 %rhs)
707 %c = icmp ugt i32 %lhs, %rhs
712 define i1 @test39(i32 %X, i32 %Y) {
713 ; CHECK-LABEL: @test39(
714 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[X:%.*]], 0
715 ; CHECK-NEXT: ret i1 [[B]]
717 %A = ashr exact i32 %X, %Y
718 %B = icmp eq i32 %A, 0
722 define <2 x i1> @test39vec(<2 x i32> %X, <2 x i32> %Y) {
723 ; CHECK-LABEL: @test39vec(
724 ; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i32> [[X:%.*]], zeroinitializer
725 ; CHECK-NEXT: ret <2 x i1> [[B]]
727 %A = ashr exact <2 x i32> %X, %Y
728 %B = icmp eq <2 x i32> %A, zeroinitializer
732 define i1 @test40(i32 %X, i32 %Y) {
733 ; CHECK-LABEL: @test40(
734 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[X:%.*]], 0
735 ; CHECK-NEXT: ret i1 [[B]]
737 %A = lshr exact i32 %X, %Y
738 %B = icmp ne i32 %A, 0
742 define <2 x i1> @test40vec(<2 x i32> %X, <2 x i32> %Y) {
743 ; CHECK-LABEL: @test40vec(
744 ; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i32> [[X:%.*]], zeroinitializer
745 ; CHECK-NEXT: ret <2 x i1> [[B]]
747 %A = lshr exact <2 x i32> %X, %Y
748 %B = icmp ne <2 x i32> %A, zeroinitializer
752 define i1 @shr_exact(i132 %x) {
753 ; CHECK-LABEL: @shr_exact(
754 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i132 [[X:%.*]], 32
755 ; CHECK-NEXT: ret i1 [[CMP]]
757 %sh = ashr exact i132 %x, 4
758 %cmp = icmp eq i132 %sh, 2
762 define <2 x i1> @shr_exact_vec(<2 x i132> %x) {
763 ; CHECK-LABEL: @shr_exact_vec(
764 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i132> [[X:%.*]], <i132 32, i132 32>
765 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
767 %sh = lshr exact <2 x i132> %x, <i132 4, i132 4>
768 %cmp = icmp ne <2 x i132> %sh, <i132 2, i132 2>
773 define i1 @test41(i32 %X, i32 %Y) {
774 ; CHECK-LABEL: @test41(
775 ; CHECK-NEXT: ret i1 true
778 %B = icmp ugt i32 %Y, %A
782 define i1 @test42(i32 %X, i32 %Y) {
783 ; CHECK-LABEL: @test42(
784 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 [[Y:%.*]], -1
785 ; CHECK-NEXT: ret i1 [[B]]
788 %B = icmp slt i32 %A, %Y
792 define i1 @test43(i32 %X, i32 %Y) {
793 ; CHECK-LABEL: @test43(
794 ; CHECK-NEXT: [[B:%.*]] = icmp slt i32 [[Y:%.*]], 0
795 ; CHECK-NEXT: ret i1 [[B]]
798 %B = icmp slt i32 %Y, %A
802 define i1 @test44(i32 %X, i32 %Y) {
803 ; CHECK-LABEL: @test44(
804 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 [[Y:%.*]], -1
805 ; CHECK-NEXT: ret i1 [[B]]
808 %B = icmp slt i32 %A, %Y
812 define i1 @test45(i32 %X, i32 %Y) {
813 ; CHECK-LABEL: @test45(
814 ; CHECK-NEXT: [[B:%.*]] = icmp slt i32 [[Y:%.*]], 0
815 ; CHECK-NEXT: ret i1 [[B]]
818 %B = icmp slt i32 %Y, %A
823 define i1 @test46(i32 %X, i32 %Y, i32 %Z) {
824 ; CHECK-LABEL: @test46(
825 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
826 ; CHECK-NEXT: ret i1 [[C]]
828 %A = ashr exact i32 %X, %Z
829 %B = ashr exact i32 %Y, %Z
830 %C = icmp ult i32 %A, %B
835 define i1 @test47(i32 %X, i32 %Y, i32 %Z) {
836 ; CHECK-LABEL: @test47(
837 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
838 ; CHECK-NEXT: ret i1 [[C]]
840 %A = ashr exact i32 %X, %Z
841 %B = ashr exact i32 %Y, %Z
842 %C = icmp ugt i32 %A, %B
847 define i1 @test48(i32 %X, i32 %Y, i32 %Z) {
848 ; CHECK-LABEL: @test48(
849 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
850 ; CHECK-NEXT: ret i1 [[C]]
852 %A = sdiv exact i32 %X, %Z
853 %B = sdiv exact i32 %Y, %Z
854 %C = icmp eq i32 %A, %B
858 ; The above transform only works for equality predicates.
860 define i1 @PR32949(i32 %X, i32 %Y, i32 %Z) {
861 ; CHECK-LABEL: @PR32949(
862 ; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 [[X:%.*]], [[Z:%.*]]
863 ; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 [[Y:%.*]], [[Z]]
864 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[A]], [[B]]
865 ; CHECK-NEXT: ret i1 [[C]]
867 %A = sdiv exact i32 %X, %Z
868 %B = sdiv exact i32 %Y, %Z
869 %C = icmp sgt i32 %A, %B
874 define <2 x i1> @test49(<2 x i32> %tmp3) {
875 ; CHECK-LABEL: @test49(
877 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
880 %tmp11 = and <2 x i32> %tmp3, <i32 3, i32 3>
881 %cmp = icmp ult <2 x i32> %tmp11, <i32 4, i32 4>
886 define i1 @test50(i16 %X, i32 %Y) {
887 ; CHECK-LABEL: @test50(
888 ; CHECK-NEXT: ret i1 true
890 %A = zext i16 %X to i32
892 %C = icmp sgt i32 %B, -1
896 define i1 @test51(i32 %X, i32 %Y) {
897 ; CHECK-LABEL: @test51(
898 ; CHECK-NEXT: [[A:%.*]] = and i32 [[X:%.*]], -2147483648
899 ; CHECK-NEXT: [[B:%.*]] = srem i32 [[A]], [[Y:%.*]]
900 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[B]], -1
901 ; CHECK-NEXT: ret i1 [[C]]
903 %A = and i32 %X, 2147483648
905 %C = icmp sgt i32 %B, -1
909 define i1 @test52(i32 %x1) {
910 ; CHECK-LABEL: @test52(
911 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X1:%.*]], 16711935
912 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 4980863
913 ; CHECK-NEXT: ret i1 [[TMP2]]
915 %conv = and i32 %x1, 255
916 %cmp = icmp eq i32 %conv, 127
917 %tmp2 = lshr i32 %x1, 16
918 %tmp3 = trunc i32 %tmp2 to i8
919 %cmp15 = icmp eq i8 %tmp3, 76
921 %A = and i1 %cmp, %cmp15
925 define i1 @test52b(i128 %x1) {
926 ; CHECK-LABEL: @test52b(
927 ; CHECK-NEXT: [[TMP1:%.*]] = and i128 [[X1:%.*]], 16711935
928 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i128 [[TMP1]], 4980863
929 ; CHECK-NEXT: ret i1 [[TMP2]]
931 %conv = and i128 %x1, 255
932 %cmp = icmp eq i128 %conv, 127
933 %tmp2 = lshr i128 %x1, 16
934 %tmp3 = trunc i128 %tmp2 to i8
935 %cmp15 = icmp eq i8 %tmp3, 76
937 %A = and i1 %cmp, %cmp15
942 define i1 @test53(i32 %a, i32 %b) {
943 ; CHECK-LABEL: @test53(
944 ; CHECK-NEXT: [[X:%.*]] = sdiv exact i32 [[A:%.*]], 30
945 ; CHECK-NEXT: [[Y:%.*]] = sdiv i32 [[B:%.*]], 30
946 ; CHECK-NEXT: [[Z:%.*]] = icmp eq i32 [[X]], [[Y]]
947 ; CHECK-NEXT: ret i1 [[Z]]
949 %x = sdiv exact i32 %a, 30
951 %z = icmp eq i32 %x, %y
955 define i1 @test54(i8 %a) {
956 ; CHECK-LABEL: @test54(
957 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[A:%.*]], -64
958 ; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[TMP1]], -128
959 ; CHECK-NEXT: ret i1 [[RET]]
961 %ext = zext i8 %a to i32
962 %and = and i32 %ext, 192
963 %ret = icmp eq i32 %and, 128
967 define i1 @test55(i32 %a) {
968 ; CHECK-LABEL: @test55(
969 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], -123
970 ; CHECK-NEXT: ret i1 [[CMP]]
973 %cmp = icmp eq i32 %sub, 123
977 define <2 x i1> @test55vec(<2 x i32> %a) {
978 ; CHECK-LABEL: @test55vec(
979 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[A:%.*]], <i32 -123, i32 -123>
980 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
982 %sub = sub <2 x i32> zeroinitializer, %a
983 %cmp = icmp eq <2 x i32> %sub, <i32 123, i32 123>
987 define i1 @test56(i32 %a) {
988 ; CHECK-LABEL: @test56(
989 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], -113
990 ; CHECK-NEXT: ret i1 [[CMP]]
992 %sub = sub i32 10, %a
993 %cmp = icmp eq i32 %sub, 123
997 define <2 x i1> @test56vec(<2 x i32> %a) {
998 ; CHECK-LABEL: @test56vec(
999 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[A:%.*]], <i32 -113, i32 -113>
1000 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1002 %sub = sub <2 x i32> <i32 10, i32 10>, %a
1003 %cmp = icmp eq <2 x i32> %sub, <i32 123, i32 123>
1007 ; PR10267 Don't make icmps more expensive when no other inst is subsumed.
1008 declare void @foo(i32)
1009 define i1 @test57(i32 %a) {
1010 ; CHECK-LABEL: @test57(
1011 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], -2
1012 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1013 ; CHECK-NEXT: call void @foo(i32 [[AND]])
1014 ; CHECK-NEXT: ret i1 [[CMP]]
1016 %and = and i32 %a, -2
1017 %cmp = icmp ne i32 %and, 0
1018 call void @foo(i32 %and)
1022 ; rdar://problem/10482509
1023 define zeroext i1 @cmpabs1(i64 %val) {
1024 ; CHECK-LABEL: @cmpabs1(
1025 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i64 [[VAL:%.*]], 0
1026 ; CHECK-NEXT: ret i1 [[TOBOOL]]
1028 %sub = sub nsw i64 0, %val
1029 %cmp = icmp slt i64 %val, 0
1030 %sub.val = select i1 %cmp, i64 %sub, i64 %val
1031 %tobool = icmp ne i64 %sub.val, 0
1035 define zeroext i1 @cmpabs2(i64 %val) {
1036 ; CHECK-LABEL: @cmpabs2(
1037 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i64 [[VAL:%.*]], 0
1038 ; CHECK-NEXT: ret i1 [[TOBOOL]]
1040 %sub = sub nsw i64 0, %val
1041 %cmp = icmp slt i64 %val, 0
1042 %sub.val = select i1 %cmp, i64 %val, i64 %sub
1043 %tobool = icmp ne i64 %sub.val, 0
1047 define void @test58() {
1048 ; CHECK-LABEL: @test58(
1049 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @test58_d(i64 36029346783166592)
1050 ; CHECK-NEXT: ret void
1052 %cast = bitcast <1 x i64> <i64 36029346783166592> to i64
1053 %call = call i32 @test58_d( i64 %cast)
1056 declare i32 @test58_d(i64)
1058 define i1 @test59(i8* %foo) {
1059 ; CHECK-LABEL: @test59(
1060 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, i8* [[FOO:%.*]], i64 8
1061 ; CHECK-NEXT: [[USE:%.*]] = ptrtoint i8* [[GEP1]] to i64
1062 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @test58_d(i64 [[USE]])
1063 ; CHECK-NEXT: ret i1 true
1065 %bit = bitcast i8* %foo to i32*
1066 %gep1 = getelementptr inbounds i32, i32* %bit, i64 2
1067 %gep2 = getelementptr inbounds i8, i8* %foo, i64 10
1068 %cast1 = bitcast i32* %gep1 to i8*
1069 %cmp = icmp ult i8* %cast1, %gep2
1070 %use = ptrtoint i8* %cast1 to i64
1071 %call = call i32 @test58_d(i64 %use)
1075 define i1 @test59_as1(i8 addrspace(1)* %foo) {
1076 ; CHECK-LABEL: @test59_as1(
1077 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, i8 addrspace(1)* [[FOO:%.*]], i16 8
1078 ; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint i8 addrspace(1)* [[GEP1]] to i16
1079 ; CHECK-NEXT: [[USE:%.*]] = zext i16 [[TMP1]] to i64
1080 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @test58_d(i64 [[USE]])
1081 ; CHECK-NEXT: ret i1 true
1083 %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)*
1084 %gep1 = getelementptr inbounds i32, i32 addrspace(1)* %bit, i64 2
1085 %gep2 = getelementptr inbounds i8, i8 addrspace(1)* %foo, i64 10
1086 %cast1 = bitcast i32 addrspace(1)* %gep1 to i8 addrspace(1)*
1087 %cmp = icmp ult i8 addrspace(1)* %cast1, %gep2
1088 %use = ptrtoint i8 addrspace(1)* %cast1 to i64
1089 %call = call i32 @test58_d(i64 %use)
1093 define i1 @test60(i8* %foo, i64 %i, i64 %j) {
1094 ; CHECK-LABEL: @test60(
1095 ; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nuw i64 [[I:%.*]], 2
1096 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i64 [[GEP1_IDX]], [[J:%.*]]
1097 ; CHECK-NEXT: ret i1 [[TMP1]]
1099 %bit = bitcast i8* %foo to i32*
1100 %gep1 = getelementptr inbounds i32, i32* %bit, i64 %i
1101 %gep2 = getelementptr inbounds i8, i8* %foo, i64 %j
1102 %cast1 = bitcast i32* %gep1 to i8*
1103 %cmp = icmp ult i8* %cast1, %gep2
1107 define i1 @test60_as1(i8 addrspace(1)* %foo, i64 %i, i64 %j) {
1108 ; CHECK-LABEL: @test60_as1(
1109 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[I:%.*]] to i16
1110 ; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[J:%.*]] to i16
1111 ; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nuw i16 [[TMP1]], 2
1112 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i16 [[GEP1_IDX]], [[TMP2]]
1113 ; CHECK-NEXT: ret i1 [[TMP3]]
1115 %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)*
1116 %gep1 = getelementptr inbounds i32, i32 addrspace(1)* %bit, i64 %i
1117 %gep2 = getelementptr inbounds i8, i8 addrspace(1)* %foo, i64 %j
1118 %cast1 = bitcast i32 addrspace(1)* %gep1 to i8 addrspace(1)*
1119 %cmp = icmp ult i8 addrspace(1)* %cast1, %gep2
1123 ; Same as test60, but look through an addrspacecast instead of a
1124 ; bitcast. This uses the same sized addrspace.
1125 define i1 @test60_addrspacecast(i8* %foo, i64 %i, i64 %j) {
1126 ; CHECK-LABEL: @test60_addrspacecast(
1127 ; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nuw i64 [[I:%.*]], 2
1128 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i64 [[GEP1_IDX]], [[J:%.*]]
1129 ; CHECK-NEXT: ret i1 [[TMP1]]
1131 %bit = addrspacecast i8* %foo to i32 addrspace(3)*
1132 %gep1 = getelementptr inbounds i32, i32 addrspace(3)* %bit, i64 %i
1133 %gep2 = getelementptr inbounds i8, i8* %foo, i64 %j
1134 %cast1 = addrspacecast i32 addrspace(3)* %gep1 to i8*
1135 %cmp = icmp ult i8* %cast1, %gep2
1139 define i1 @test60_addrspacecast_smaller(i8* %foo, i16 %i, i64 %j) {
1140 ; CHECK-LABEL: @test60_addrspacecast_smaller(
1141 ; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl nuw i16 [[I:%.*]], 2
1142 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[J:%.*]] to i16
1143 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i16 [[GEP1_IDX]], [[TMP1]]
1144 ; CHECK-NEXT: ret i1 [[TMP2]]
1146 %bit = addrspacecast i8* %foo to i32 addrspace(1)*
1147 %gep1 = getelementptr inbounds i32, i32 addrspace(1)* %bit, i16 %i
1148 %gep2 = getelementptr inbounds i8, i8* %foo, i64 %j
1149 %cast1 = addrspacecast i32 addrspace(1)* %gep1 to i8*
1150 %cmp = icmp ult i8* %cast1, %gep2
1154 define i1 @test60_addrspacecast_larger(i8 addrspace(1)* %foo, i32 %i, i16 %j) {
1155 ; CHECK-LABEL: @test60_addrspacecast_larger(
1156 ; CHECK-NEXT: [[I_TR:%.*]] = trunc i32 [[I:%.*]] to i16
1157 ; CHECK-NEXT: [[TMP1:%.*]] = shl i16 [[I_TR]], 2
1158 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i16 [[TMP1]], [[J:%.*]]
1159 ; CHECK-NEXT: ret i1 [[TMP2]]
1161 %bit = addrspacecast i8 addrspace(1)* %foo to i32 addrspace(2)*
1162 %gep1 = getelementptr inbounds i32, i32 addrspace(2)* %bit, i32 %i
1163 %gep2 = getelementptr inbounds i8, i8 addrspace(1)* %foo, i16 %j
1164 %cast1 = addrspacecast i32 addrspace(2)* %gep1 to i8 addrspace(1)*
1165 %cmp = icmp ult i8 addrspace(1)* %cast1, %gep2
1169 define i1 @test61(i8* %foo, i64 %i, i64 %j) {
1170 ; CHECK-LABEL: @test61(
1171 ; CHECK-NEXT: [[BIT:%.*]] = bitcast i8* [[FOO:%.*]] to i32*
1172 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, i32* [[BIT]], i64 [[I:%.*]]
1173 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, i8* [[FOO]], i64 [[J:%.*]]
1174 ; CHECK-NEXT: [[CAST1:%.*]] = bitcast i32* [[GEP1]] to i8*
1175 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8* [[GEP2]], [[CAST1]]
1176 ; CHECK-NEXT: ret i1 [[CMP]]
1178 %bit = bitcast i8* %foo to i32*
1179 %gep1 = getelementptr i32, i32* %bit, i64 %i
1180 %gep2 = getelementptr i8, i8* %foo, i64 %j
1181 %cast1 = bitcast i32* %gep1 to i8*
1182 %cmp = icmp ult i8* %cast1, %gep2
1184 ; Don't transform non-inbounds GEPs.
1187 define i1 @test61_as1(i8 addrspace(1)* %foo, i16 %i, i16 %j) {
1188 ; CHECK-LABEL: @test61_as1(
1189 ; CHECK-NEXT: [[BIT:%.*]] = bitcast i8 addrspace(1)* [[FOO:%.*]] to i32 addrspace(1)*
1190 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, i32 addrspace(1)* [[BIT]], i16 [[I:%.*]]
1191 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, i8 addrspace(1)* [[FOO]], i16 [[J:%.*]]
1192 ; CHECK-NEXT: [[CAST1:%.*]] = bitcast i32 addrspace(1)* [[GEP1]] to i8 addrspace(1)*
1193 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 addrspace(1)* [[GEP2]], [[CAST1]]
1194 ; CHECK-NEXT: ret i1 [[CMP]]
1196 %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)*
1197 %gep1 = getelementptr i32, i32 addrspace(1)* %bit, i16 %i
1198 %gep2 = getelementptr i8, i8 addrspace(1)* %foo, i16 %j
1199 %cast1 = bitcast i32 addrspace(1)* %gep1 to i8 addrspace(1)*
1200 %cmp = icmp ult i8 addrspace(1)* %cast1, %gep2
1202 ; Don't transform non-inbounds GEPs.
1205 define i1 @test62(i8* %a) {
1206 ; CHECK-LABEL: @test62(
1207 ; CHECK-NEXT: ret i1 true
1209 %arrayidx1 = getelementptr inbounds i8, i8* %a, i64 1
1210 %arrayidx2 = getelementptr inbounds i8, i8* %a, i64 10
1211 %cmp = icmp slt i8* %arrayidx1, %arrayidx2
1215 define i1 @test62_as1(i8 addrspace(1)* %a) {
1216 ; CHECK-LABEL: @test62_as1(
1217 ; CHECK-NEXT: ret i1 true
1219 %arrayidx1 = getelementptr inbounds i8, i8 addrspace(1)* %a, i64 1
1220 %arrayidx2 = getelementptr inbounds i8, i8 addrspace(1)* %a, i64 10
1221 %cmp = icmp slt i8 addrspace(1)* %arrayidx1, %arrayidx2
1225 define i1 @test63(i8 %a, i32 %b) {
1226 ; CHECK-LABEL: @test63(
1227 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
1228 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[TMP1]], [[A:%.*]]
1229 ; CHECK-NEXT: ret i1 [[C]]
1231 %z = zext i8 %a to i32
1232 %t = and i32 %b, 255
1233 %c = icmp eq i32 %z, %t
1237 define i1 @test64(i8 %a, i32 %b) {
1238 ; CHECK-LABEL: @test64(
1239 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[B:%.*]] to i8
1240 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[TMP1]], [[A:%.*]]
1241 ; CHECK-NEXT: ret i1 [[C]]
1243 %t = and i32 %b, 255
1244 %z = zext i8 %a to i32
1245 %c = icmp eq i32 %t, %z
1249 define i1 @test65(i64 %A, i64 %B) {
1250 ; CHECK-LABEL: @test65(
1251 ; CHECK-NEXT: ret i1 true
1253 %s1 = add i64 %A, %B
1254 %s2 = add i64 %A, %B
1255 %cmp = icmp eq i64 %s1, %s2
1259 define i1 @test66(i64 %A, i64 %B) {
1260 ; CHECK-LABEL: @test66(
1261 ; CHECK-NEXT: ret i1 true
1263 %s1 = add i64 %A, %B
1264 %s2 = add i64 %B, %A
1265 %cmp = icmp eq i64 %s1, %s2
1269 define i1 @test67(i32 %x) {
1270 ; CHECK-LABEL: @test67(
1271 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 96
1272 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1273 ; CHECK-NEXT: ret i1 [[CMP]]
1275 %and = and i32 %x, 127
1276 %cmp = icmp sgt i32 %and, 31
1280 define i1 @test67inverse(i32 %x) {
1281 ; CHECK-LABEL: @test67inverse(
1282 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 96
1283 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1284 ; CHECK-NEXT: ret i1 [[CMP]]
1286 %and = and i32 %x, 127
1287 %cmp = icmp sle i32 %and, 31
1291 ; The test above relies on 3 different folds.
1292 ; This test only checks the last of those (icmp ugt -> icmp ne).
1294 define <2 x i1> @test67vec(<2 x i32> %x) {
1295 ; CHECK-LABEL: @test67vec(
1296 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 96, i32 96>
1297 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer
1298 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1300 %and = and <2 x i32> %x, <i32 96, i32 96>
1301 %cmp = icmp ugt <2 x i32> %and, <i32 31, i32 31>
1305 define <2 x i1> @test67vec2(<2 x i32> %x) {
1306 ; CHECK-LABEL: @test67vec2(
1307 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 96, i32 96>
1308 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer
1309 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1311 %and = and <2 x i32> %x, <i32 127, i32 127>
1312 %cmp = icmp ugt <2 x i32> %and, <i32 31, i32 31>
1316 define <2 x i1> @test67vecinverse(<2 x i32> %x) {
1317 ; CHECK-LABEL: @test67vecinverse(
1318 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 96, i32 96>
1319 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[AND]], zeroinitializer
1320 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1322 %and = and <2 x i32> %x, <i32 96, i32 96>
1323 %cmp = icmp sle <2 x i32> %and, <i32 31, i32 31>
1327 define i1 @test68(i32 %x) {
1328 ; CHECK-LABEL: @test68(
1329 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 127
1330 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[AND]], 30
1331 ; CHECK-NEXT: ret i1 [[CMP]]
1333 %and = and i32 %x, 127
1334 %cmp = icmp sgt i32 %and, 30
1339 define i1 @test70(i32 %X) {
1340 ; CHECK-LABEL: @test70(
1341 ; CHECK-NEXT: [[A:%.*]] = srem i32 5, [[X:%.*]]
1342 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[A]], 2
1343 ; CHECK-NEXT: ret i1 [[C]]
1347 %C = icmp ne i32 %B, 4
1351 define <2 x i1> @test70vec(<2 x i32> %X) {
1352 ; CHECK-LABEL: @test70vec(
1353 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[X:%.*]], <i32 2, i32 2>
1354 ; CHECK-NEXT: ret <2 x i1> [[C]]
1356 %B = add <2 x i32> %X, <i32 2, i32 2>
1357 %C = icmp ne <2 x i32> %B, <i32 4, i32 4>
1361 define i1 @icmp_sext16trunc(i32 %x) {
1362 ; CHECK-LABEL: @icmp_sext16trunc(
1363 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i16
1364 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[TMP1]], 36
1365 ; CHECK-NEXT: ret i1 [[CMP]]
1367 %trunc = trunc i32 %x to i16
1368 %sext = sext i16 %trunc to i32
1369 %cmp = icmp slt i32 %sext, 36
1373 define i1 @icmp_sext8trunc(i32 %x) {
1374 ; CHECK-LABEL: @icmp_sext8trunc(
1375 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8
1376 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TMP1]], 36
1377 ; CHECK-NEXT: ret i1 [[CMP]]
1379 %trunc = trunc i32 %x to i8
1380 %sext = sext i8 %trunc to i32
1381 %cmp = icmp slt i32 %sext, 36
1385 ; Vectors should fold the same way.
1386 define <2 x i1> @icmp_sext8trunc_vec(<2 x i32> %x) {
1387 ; CHECK-LABEL: @icmp_sext8trunc_vec(
1388 ; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i32> [[X:%.*]] to <2 x i8>
1389 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[TMP1]], <i8 36, i8 36>
1390 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1392 %trunc = trunc <2 x i32> %x to <2 x i8>
1393 %sext = sext <2 x i8> %trunc to <2 x i32>
1394 %cmp = icmp slt <2 x i32> %sext, <i32 36, i32 36>
1398 define i1 @icmp_shl16(i32 %x) {
1399 ; CHECK-LABEL: @icmp_shl16(
1400 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i16
1401 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[TMP1]], 36
1402 ; CHECK-NEXT: ret i1 [[CMP]]
1404 %shl = shl i32 %x, 16
1405 %cmp = icmp slt i32 %shl, 2359296
1409 ; D25952: Don't create illegal types like i15 in InstCombine
1411 define i1 @icmp_shl17(i32 %x) {
1412 ; CHECK-LABEL: @icmp_shl17(
1413 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[X:%.*]], 17
1414 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[SHL]], 2359296
1415 ; CHECK-NEXT: ret i1 [[CMP]]
1417 %shl = shl i32 %x, 17
1418 %cmp = icmp slt i32 %shl, 2359296
1422 define <2 x i1> @icmp_shl16_vec(<2 x i32> %x) {
1423 ; CHECK-LABEL: @icmp_shl16_vec(
1424 ; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i32> [[X:%.*]] to <2 x i16>
1425 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i16> [[TMP1]], <i16 36, i16 36>
1426 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1428 %shl = shl <2 x i32> %x, <i32 16, i32 16>
1429 %cmp = icmp slt <2 x i32> %shl, <i32 2359296, i32 2359296>
1433 define i1 @icmp_shl24(i32 %x) {
1434 ; CHECK-LABEL: @icmp_shl24(
1435 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8
1436 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TMP1]], 36
1437 ; CHECK-NEXT: ret i1 [[CMP]]
1439 %shl = shl i32 %x, 24
1440 %cmp = icmp slt i32 %shl, 603979776
1444 define i1 @icmp_shl_eq(i32 %x) {
1445 ; CHECK-LABEL: @icmp_shl_eq(
1446 ; CHECK-NEXT: [[MUL_MASK:%.*]] = and i32 [[X:%.*]], 134217727
1447 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[MUL_MASK]], 0
1448 ; CHECK-NEXT: ret i1 [[CMP]]
1450 %mul = shl i32 %x, 5
1451 %cmp = icmp eq i32 %mul, 0
1455 define <2 x i1> @icmp_shl_eq_vec(<2 x i32> %x) {
1456 ; CHECK-LABEL: @icmp_shl_eq_vec(
1457 ; CHECK-NEXT: [[MUL_MASK:%.*]] = and <2 x i32> [[X:%.*]], <i32 134217727, i32 134217727>
1458 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[MUL_MASK]], zeroinitializer
1459 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1461 %mul = shl <2 x i32> %x, <i32 5, i32 5>
1462 %cmp = icmp eq <2 x i32> %mul, zeroinitializer
1466 define i1 @icmp_shl_nsw_ne(i32 %x) {
1467 ; CHECK-LABEL: @icmp_shl_nsw_ne(
1468 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 0
1469 ; CHECK-NEXT: ret i1 [[CMP]]
1471 %mul = shl nsw i32 %x, 7
1472 %cmp = icmp ne i32 %mul, 0
1476 define <2 x i1> @icmp_shl_nsw_ne_vec(<2 x i32> %x) {
1477 ; CHECK-LABEL: @icmp_shl_nsw_ne_vec(
1478 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[X:%.*]], zeroinitializer
1479 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1481 %mul = shl nsw <2 x i32> %x, <i32 7, i32 7>
1482 %cmp = icmp ne <2 x i32> %mul, zeroinitializer
1486 define i1 @icmp_shl_ne(i32 %x) {
1487 ; CHECK-LABEL: @icmp_shl_ne(
1488 ; CHECK-NEXT: [[MUL_MASK:%.*]] = and i32 [[X:%.*]], 33554431
1489 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[MUL_MASK]], 0
1490 ; CHECK-NEXT: ret i1 [[CMP]]
1492 %mul = shl i32 %x, 7
1493 %cmp = icmp ne i32 %mul, 0
1497 define <2 x i1> @icmp_shl_ne_vec(<2 x i32> %x) {
1498 ; CHECK-LABEL: @icmp_shl_ne_vec(
1499 ; CHECK-NEXT: [[MUL_MASK:%.*]] = and <2 x i32> [[X:%.*]], <i32 33554431, i32 33554431>
1500 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[MUL_MASK]], zeroinitializer
1501 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1503 %mul = shl <2 x i32> %x, <i32 7, i32 7>
1504 %cmp = icmp ne <2 x i32> %mul, zeroinitializer
1508 define <2 x i1> @icmp_shl_nuw_ne_vec(<2 x i32> %x) {
1509 ; CHECK-LABEL: @icmp_shl_nuw_ne_vec(
1510 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[X:%.*]], <i32 2, i32 2>
1511 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1513 %shl = shl nuw <2 x i32> %x, <i32 7, i32 7>
1514 %cmp = icmp ne <2 x i32> %shl, <i32 256, i32 256>
1518 ; If the (mul x, C) preserved the sign and this is sign test,
1519 ; compare the LHS operand instead
1520 define i1 @icmp_mul_nsw(i32 %x) {
1521 ; CHECK-LABEL: @icmp_mul_nsw(
1522 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 0
1523 ; CHECK-NEXT: ret i1 [[CMP]]
1525 %mul = mul nsw i32 %x, 12
1526 %cmp = icmp sgt i32 %mul, 0
1530 define i1 @icmp_mul_nsw1(i32 %x) {
1531 ; CHECK-LABEL: @icmp_mul_nsw1(
1532 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1533 ; CHECK-NEXT: ret i1 [[CMP]]
1535 %mul = mul nsw i32 %x, 12
1536 %cmp = icmp sle i32 %mul, -1
1540 define i1 @icmp_mul_nsw_neg(i32 %x) {
1541 ; CHECK-LABEL: @icmp_mul_nsw_neg(
1542 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 1
1543 ; CHECK-NEXT: ret i1 [[CMP]]
1545 %mul = mul nsw i32 %x, -12
1546 %cmp = icmp sge i32 %mul, 0
1550 define i1 @icmp_mul_nsw_neg1(i32 %x) {
1551 ; CHECK-LABEL: @icmp_mul_nsw_neg1(
1552 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
1553 ; CHECK-NEXT: ret i1 [[CMP]]
1555 %mul = mul nsw i32 %x, -12
1556 %cmp = icmp sge i32 %mul, 1
1560 define <2 x i1> @icmp_mul_nsw_neg1_vec(<2 x i32> %x) {
1561 ; CHECK-LABEL: @icmp_mul_nsw_neg1_vec(
1562 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
1563 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1565 %mul = mul nsw <2 x i32> %x, <i32 -12, i32 -12>
1566 %cmp = icmp sge <2 x i32> %mul, <i32 1, i32 1>
1570 define i1 @icmp_mul_nsw_0(i32 %x) {
1571 ; CHECK-LABEL: @icmp_mul_nsw_0(
1572 ; CHECK-NEXT: ret i1 false
1574 %mul = mul nsw i32 %x, 0
1575 %cmp = icmp sgt i32 %mul, 0
1579 define i1 @icmp_mul(i32 %x) {
1580 ; CHECK-LABEL: @icmp_mul(
1581 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], -12
1582 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[MUL]], -1
1583 ; CHECK-NEXT: ret i1 [[CMP]]
1585 %mul = mul i32 %x, -12
1586 %cmp = icmp sge i32 %mul, 0
1590 ; Checks for icmp (eq|ne) (mul x, C), 0
1591 define i1 @icmp_mul_neq0(i32 %x) {
1592 ; CHECK-LABEL: @icmp_mul_neq0(
1593 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 0
1594 ; CHECK-NEXT: ret i1 [[CMP]]
1596 %mul = mul nsw i32 %x, -12
1597 %cmp = icmp ne i32 %mul, 0
1601 define <2 x i1> @icmp_mul_neq0_vec(<2 x i32> %x) {
1602 ; CHECK-LABEL: @icmp_mul_neq0_vec(
1603 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[X:%.*]], zeroinitializer
1604 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1606 %mul = mul nsw <2 x i32> %x, <i32 -12, i32 -12>
1607 %cmp = icmp ne <2 x i32> %mul, zeroinitializer
1611 define i1 @icmp_mul_eq0(i32 %x) {
1612 ; CHECK-LABEL: @icmp_mul_eq0(
1613 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 0
1614 ; CHECK-NEXT: ret i1 [[CMP]]
1616 %mul = mul nsw i32 %x, 12
1617 %cmp = icmp eq i32 %mul, 0
1621 define i1 @icmp_mul0_eq0(i32 %x) {
1622 ; CHECK-LABEL: @icmp_mul0_eq0(
1623 ; CHECK-NEXT: ret i1 true
1625 %mul = mul i32 %x, 0
1626 %cmp = icmp eq i32 %mul, 0
1630 define i1 @icmp_mul0_ne0(i32 %x) {
1631 ; CHECK-LABEL: @icmp_mul0_ne0(
1632 ; CHECK-NEXT: ret i1 false
1634 %mul = mul i32 %x, 0
1635 %cmp = icmp ne i32 %mul, 0
1639 define i1 @icmp_sub1_sge(i32 %x, i32 %y) {
1640 ; CHECK-LABEL: @icmp_sub1_sge(
1641 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
1642 ; CHECK-NEXT: ret i1 [[CMP]]
1644 %sub = add nsw i32 %x, -1
1645 %cmp = icmp sge i32 %sub, %y
1649 define i1 @icmp_add1_sgt(i32 %x, i32 %y) {
1650 ; CHECK-LABEL: @icmp_add1_sgt(
1651 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]]
1652 ; CHECK-NEXT: ret i1 [[CMP]]
1654 %add = add nsw i32 %x, 1
1655 %cmp = icmp sgt i32 %add, %y
1659 define i1 @icmp_sub1_slt(i32 %x, i32 %y) {
1660 ; CHECK-LABEL: @icmp_sub1_slt(
1661 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]
1662 ; CHECK-NEXT: ret i1 [[CMP]]
1664 %sub = add nsw i32 %x, -1
1665 %cmp = icmp slt i32 %sub, %y
1669 define i1 @icmp_add1_sle(i32 %x, i32 %y) {
1670 ; CHECK-LABEL: @icmp_add1_sle(
1671 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
1672 ; CHECK-NEXT: ret i1 [[CMP]]
1674 %add = add nsw i32 %x, 1
1675 %cmp = icmp sle i32 %add, %y
1679 define i1 @icmp_add20_sge_add57(i32 %x, i32 %y) {
1680 ; CHECK-LABEL: @icmp_add20_sge_add57(
1681 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i32 [[Y:%.*]], 37
1682 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[TMP1]], [[X:%.*]]
1683 ; CHECK-NEXT: ret i1 [[CMP]]
1685 %1 = add nsw i32 %x, 20
1686 %2 = add nsw i32 %y, 57
1687 %cmp = icmp sge i32 %1, %2
1691 define i1 @icmp_sub57_sge_sub20(i32 %x, i32 %y) {
1692 ; CHECK-LABEL: @icmp_sub57_sge_sub20(
1693 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i32 [[X:%.*]], -37
1694 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[TMP1]], [[Y:%.*]]
1695 ; CHECK-NEXT: ret i1 [[CMP]]
1697 %1 = add nsw i32 %x, -57
1698 %2 = add nsw i32 %y, -20
1699 %cmp = icmp sge i32 %1, %2
1703 define i1 @icmp_and_shl_neg_ne_0(i32 %A, i32 %B) {
1704 ; CHECK-LABEL: @icmp_and_shl_neg_ne_0(
1705 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 1, [[B:%.*]]
1706 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[SHL]], [[A:%.*]]
1707 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 0
1708 ; CHECK-NEXT: ret i1 [[CMP]]
1710 %neg = xor i32 %A, -1
1711 %shl = shl i32 1, %B
1712 %and = and i32 %shl, %neg
1713 %cmp = icmp ne i32 %and, 0
1717 define i1 @icmp_and_shl_neg_eq_0(i32 %A, i32 %B) {
1718 ; CHECK-LABEL: @icmp_and_shl_neg_eq_0(
1719 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 1, [[B:%.*]]
1720 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[SHL]], [[A:%.*]]
1721 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP1]], 0
1722 ; CHECK-NEXT: ret i1 [[CMP]]
1724 %neg = xor i32 %A, -1
1725 %shl = shl i32 1, %B
1726 %and = and i32 %shl, %neg
1727 %cmp = icmp eq i32 %and, 0
1731 define i1 @icmp_add_and_shr_ne_0(i32 %X) {
1732 ; CHECK-LABEL: @icmp_add_and_shr_ne_0(
1733 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 240
1734 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[AND]], 224
1735 ; CHECK-NEXT: ret i1 [[TOBOOL]]
1737 %shr = lshr i32 %X, 4
1738 %and = and i32 %shr, 15
1739 %add = add i32 %and, -14
1740 %tobool = icmp ne i32 %add, 0
1744 define <2 x i1> @icmp_add_and_shr_ne_0_vec(<2 x i32> %X) {
1745 ; CHECK-LABEL: @icmp_add_and_shr_ne_0_vec(
1746 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 240, i32 240>
1747 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne <2 x i32> [[AND]], <i32 224, i32 224>
1748 ; CHECK-NEXT: ret <2 x i1> [[TOBOOL]]
1750 %shr = lshr <2 x i32> %X, <i32 4, i32 4>
1751 %and = and <2 x i32> %shr, <i32 15, i32 15>
1752 %add = add <2 x i32> %and, <i32 -14, i32 -14>
1753 %tobool = icmp ne <2 x i32> %add, zeroinitializer
1754 ret <2 x i1> %tobool
1757 ; Variation of the above with an extra use of the shift
1758 define i1 @icmp_and_shr_multiuse(i32 %X) {
1759 ; CHECK-LABEL: @icmp_and_shr_multiuse(
1760 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 240
1761 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[X]], 496
1762 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[AND]], 224
1763 ; CHECK-NEXT: [[TOBOOL2:%.*]] = icmp ne i32 [[AND2]], 432
1764 ; CHECK-NEXT: [[AND3:%.*]] = and i1 [[TOBOOL]], [[TOBOOL2]]
1765 ; CHECK-NEXT: ret i1 [[AND3]]
1767 %shr = lshr i32 %X, 4
1768 %and = and i32 %shr, 15
1769 %and2 = and i32 %shr, 31 ; second use of the shift
1770 %tobool = icmp ne i32 %and, 14
1771 %tobool2 = icmp ne i32 %and2, 27
1772 %and3 = and i1 %tobool, %tobool2
1776 ; Variation of the above with an ashr
1777 define i1 @icmp_and_ashr_multiuse(i32 %X) {
1778 ; CHECK-LABEL: @icmp_and_ashr_multiuse(
1779 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 240
1780 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[X]], 496
1781 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[AND]], 224
1782 ; CHECK-NEXT: [[TOBOOL2:%.*]] = icmp ne i32 [[AND2]], 432
1783 ; CHECK-NEXT: [[AND3:%.*]] = and i1 [[TOBOOL]], [[TOBOOL2]]
1784 ; CHECK-NEXT: ret i1 [[AND3]]
1786 %shr = ashr i32 %X, 4
1787 %and = and i32 %shr, 15
1788 %and2 = and i32 %shr, 31 ; second use of the shift
1789 %tobool = icmp ne i32 %and, 14
1790 %tobool2 = icmp ne i32 %and2, 27
1791 %and3 = and i1 %tobool, %tobool2
1795 define i1 @icmp_lshr_and_overshift(i8 %X) {
1796 ; CHECK-LABEL: @icmp_lshr_and_overshift(
1797 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ugt i8 [[X:%.*]], 31
1798 ; CHECK-NEXT: ret i1 [[TOBOOL]]
1800 %shr = lshr i8 %X, 5
1801 %and = and i8 %shr, 15
1802 %tobool = icmp ne i8 %and, 0
1806 ; We shouldn't simplify this because the and uses bits that are shifted in.
1807 define i1 @icmp_ashr_and_overshift(i8 %X) {
1808 ; CHECK-LABEL: @icmp_ashr_and_overshift(
1809 ; CHECK-NEXT: [[SHR:%.*]] = ashr i8 [[X:%.*]], 5
1810 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[SHR]], 15
1811 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i8 [[AND]], 0
1812 ; CHECK-NEXT: ret i1 [[TOBOOL]]
1814 %shr = ashr i8 %X, 5
1815 %and = and i8 %shr, 15
1816 %tobool = icmp ne i8 %and, 0
1821 define i1 @test71(i8* %x) {
1822 ; CHECK-LABEL: @test71(
1823 ; CHECK-NEXT: ret i1 false
1825 %a = getelementptr i8, i8* %x, i64 8
1826 %b = getelementptr inbounds i8, i8* %x, i64 8
1827 %c = icmp ugt i8* %a, %b
1831 define i1 @test71_as1(i8 addrspace(1)* %x) {
1832 ; CHECK-LABEL: @test71_as1(
1833 ; CHECK-NEXT: ret i1 false
1835 %a = getelementptr i8, i8 addrspace(1)* %x, i64 8
1836 %b = getelementptr inbounds i8, i8 addrspace(1)* %x, i64 8
1837 %c = icmp ugt i8 addrspace(1)* %a, %b
1841 define i1 @icmp_shl_1_V_ult_32(i32 %V) {
1842 ; CHECK-LABEL: @icmp_shl_1_V_ult_32(
1843 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[V:%.*]], 5
1844 ; CHECK-NEXT: ret i1 [[CMP]]
1846 %shl = shl i32 1, %V
1847 %cmp = icmp ult i32 %shl, 32
1851 define <2 x i1> @icmp_shl_1_V_ult_32_vec(<2 x i32> %V) {
1852 ; CHECK-LABEL: @icmp_shl_1_V_ult_32_vec(
1853 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[V:%.*]], <i32 5, i32 5>
1854 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1856 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1857 %cmp = icmp ult <2 x i32> %shl, <i32 32, i32 32>
1861 define i1 @icmp_shl_1_V_eq_32(i32 %V) {
1862 ; CHECK-LABEL: @icmp_shl_1_V_eq_32(
1863 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[V:%.*]], 5
1864 ; CHECK-NEXT: ret i1 [[CMP]]
1866 %shl = shl i32 1, %V
1867 %cmp = icmp eq i32 %shl, 32
1871 define <2 x i1> @icmp_shl_1_V_eq_32_vec(<2 x i32> %V) {
1872 ; CHECK-LABEL: @icmp_shl_1_V_eq_32_vec(
1873 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[V:%.*]], <i32 5, i32 5>
1874 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1876 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1877 %cmp = icmp eq <2 x i32> %shl, <i32 32, i32 32>
1881 define i1 @icmp_shl_1_V_ult_30(i32 %V) {
1882 ; CHECK-LABEL: @icmp_shl_1_V_ult_30(
1883 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[V:%.*]], 5
1884 ; CHECK-NEXT: ret i1 [[CMP]]
1886 %shl = shl i32 1, %V
1887 %cmp = icmp ult i32 %shl, 30
1891 define <2 x i1> @icmp_shl_1_V_ult_30_vec(<2 x i32> %V) {
1892 ; CHECK-LABEL: @icmp_shl_1_V_ult_30_vec(
1893 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[V:%.*]], <i32 5, i32 5>
1894 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1896 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1897 %cmp = icmp ult <2 x i32> %shl, <i32 30, i32 30>
1901 define i1 @icmp_shl_1_V_ugt_30(i32 %V) {
1902 ; CHECK-LABEL: @icmp_shl_1_V_ugt_30(
1903 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[V:%.*]], 4
1904 ; CHECK-NEXT: ret i1 [[CMP]]
1906 %shl = shl i32 1, %V
1907 %cmp = icmp ugt i32 %shl, 30
1911 define <2 x i1> @icmp_shl_1_V_ugt_30_vec(<2 x i32> %V) {
1912 ; CHECK-LABEL: @icmp_shl_1_V_ugt_30_vec(
1913 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[V:%.*]], <i32 4, i32 4>
1914 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1916 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1917 %cmp = icmp ugt <2 x i32> %shl, <i32 30, i32 30>
1921 define i1 @icmp_shl_1_V_ule_30(i32 %V) {
1922 ; CHECK-LABEL: @icmp_shl_1_V_ule_30(
1923 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[V:%.*]], 5
1924 ; CHECK-NEXT: ret i1 [[CMP]]
1926 %shl = shl i32 1, %V
1927 %cmp = icmp ule i32 %shl, 30
1931 define <2 x i1> @icmp_shl_1_V_ule_30_vec(<2 x i32> %V) {
1932 ; CHECK-LABEL: @icmp_shl_1_V_ule_30_vec(
1933 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[V:%.*]], <i32 5, i32 5>
1934 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1936 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1937 %cmp = icmp ule <2 x i32> %shl, <i32 30, i32 30>
1941 define i1 @icmp_shl_1_V_uge_30(i32 %V) {
1942 ; CHECK-LABEL: @icmp_shl_1_V_uge_30(
1943 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[V:%.*]], 4
1944 ; CHECK-NEXT: ret i1 [[CMP]]
1946 %shl = shl i32 1, %V
1947 %cmp = icmp uge i32 %shl, 30
1951 define <2 x i1> @icmp_shl_1_V_uge_30_vec(<2 x i32> %V) {
1952 ; CHECK-LABEL: @icmp_shl_1_V_uge_30_vec(
1953 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[V:%.*]], <i32 4, i32 4>
1954 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1956 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1957 %cmp = icmp uge <2 x i32> %shl, <i32 30, i32 30>
1961 define i1 @icmp_shl_1_V_uge_2147483648(i32 %V) {
1962 ; CHECK-LABEL: @icmp_shl_1_V_uge_2147483648(
1963 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[V:%.*]], 31
1964 ; CHECK-NEXT: ret i1 [[CMP]]
1966 %shl = shl i32 1, %V
1967 %cmp = icmp uge i32 %shl, 2147483648
1971 define <2 x i1> @icmp_shl_1_V_uge_2147483648_vec(<2 x i32> %V) {
1972 ; CHECK-LABEL: @icmp_shl_1_V_uge_2147483648_vec(
1973 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[V:%.*]], <i32 31, i32 31>
1974 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1976 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1977 %cmp = icmp uge <2 x i32> %shl, <i32 2147483648, i32 2147483648>
1981 define i1 @icmp_shl_1_V_ult_2147483648(i32 %V) {
1982 ; CHECK-LABEL: @icmp_shl_1_V_ult_2147483648(
1983 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[V:%.*]], 31
1984 ; CHECK-NEXT: ret i1 [[CMP]]
1986 %shl = shl i32 1, %V
1987 %cmp = icmp ult i32 %shl, 2147483648
1991 define <2 x i1> @icmp_shl_1_V_ult_2147483648_vec(<2 x i32> %V) {
1992 ; CHECK-LABEL: @icmp_shl_1_V_ult_2147483648_vec(
1993 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[V:%.*]], <i32 31, i32 31>
1994 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
1996 %shl = shl <2 x i32> <i32 1, i32 1>, %V
1997 %cmp = icmp ult <2 x i32> %shl, <i32 2147483648, i32 2147483648>
2001 define i1 @or_icmp_eq_B_0_icmp_ult_A_B(i64 %a, i64 %b) {
2002 ; CHECK-LABEL: @or_icmp_eq_B_0_icmp_ult_A_B(
2003 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[B:%.*]], -1
2004 ; CHECK-NEXT: [[TMP2:%.*]] = icmp uge i64 [[TMP1]], [[A:%.*]]
2005 ; CHECK-NEXT: ret i1 [[TMP2]]
2007 %1 = icmp eq i64 %b, 0
2008 %2 = icmp ult i64 %a, %b
2013 define i1 @icmp_add_ult_2(i32 %X) {
2014 ; CHECK-LABEL: @icmp_add_ult_2(
2015 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -2
2016 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 14
2017 ; CHECK-NEXT: ret i1 [[CMP]]
2019 %add = add i32 %X, -14
2020 %cmp = icmp ult i32 %add, 2
2024 define <2 x i1> @icmp_add_X_-14_ult_2_vec(<2 x i32> %X) {
2025 ; CHECK-LABEL: @icmp_add_X_-14_ult_2_vec(
2026 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X:%.*]], <i32 -2, i32 -2>
2027 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 14, i32 14>
2028 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2030 %add = add <2 x i32> %X, <i32 -14, i32 -14>
2031 %cmp = icmp ult <2 x i32> %add, <i32 2, i32 2>
2035 define i1 @icmp_sub_3_X_ult_2(i32 %X) {
2036 ; CHECK-LABEL: @icmp_sub_3_X_ult_2(
2037 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], 1
2038 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 3
2039 ; CHECK-NEXT: ret i1 [[CMP]]
2041 %add = sub i32 3, %X
2042 %cmp = icmp ult i32 %add, 2
2046 define <2 x i1> @icmp_sub_3_X_ult_2_vec(<2 x i32> %X) {
2047 ; CHECK-LABEL: @icmp_sub_3_X_ult_2_vec(
2048 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[X:%.*]], <i32 1, i32 1>
2049 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 3, i32 3>
2050 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2052 %add = sub <2 x i32> <i32 3, i32 3>, %X
2053 %cmp = icmp ult <2 x i32> %add, <i32 2, i32 2>
2057 define i1 @icmp_add_X_-14_uge_2(i32 %X) {
2058 ; CHECK-LABEL: @icmp_add_X_-14_uge_2(
2059 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -2
2060 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP1]], 14
2061 ; CHECK-NEXT: ret i1 [[CMP]]
2063 %add = add i32 %X, -14
2064 %cmp = icmp uge i32 %add, 2
2068 define <2 x i1> @icmp_add_X_-14_uge_2_vec(<2 x i32> %X) {
2069 ; CHECK-LABEL: @icmp_add_X_-14_uge_2_vec(
2070 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X:%.*]], <i32 -2, i32 -2>
2071 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[TMP1]], <i32 14, i32 14>
2072 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2074 %add = add <2 x i32> %X, <i32 -14, i32 -14>
2075 %cmp = icmp uge <2 x i32> %add, <i32 2, i32 2>
2079 define i1 @icmp_sub_3_X_uge_2(i32 %X) {
2080 ; CHECK-LABEL: @icmp_sub_3_X_uge_2(
2081 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], 1
2082 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP1]], 3
2083 ; CHECK-NEXT: ret i1 [[CMP]]
2085 %add = sub i32 3, %X
2086 %cmp = icmp uge i32 %add, 2
2090 define <2 x i1> @icmp_sub_3_X_uge_2_vec(<2 x i32> %X) {
2091 ; CHECK-LABEL: @icmp_sub_3_X_uge_2_vec(
2092 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[X:%.*]], <i32 1, i32 1>
2093 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[TMP1]], <i32 3, i32 3>
2094 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2096 %add = sub <2 x i32> <i32 3, i32 3>, %X
2097 %cmp = icmp uge <2 x i32> %add, <i32 2, i32 2>
2101 define i1 @icmp_and_X_-16_eq-16(i32 %X) {
2102 ; CHECK-LABEL: @icmp_and_X_-16_eq-16(
2103 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], -17
2104 ; CHECK-NEXT: ret i1 [[CMP]]
2106 %and = and i32 %X, -16
2107 %cmp = icmp eq i32 %and, -16
2111 define <2 x i1> @icmp_and_X_-16_eq-16_vec(<2 x i32> %X) {
2112 ; CHECK-LABEL: @icmp_and_X_-16_eq-16_vec(
2113 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 -17, i32 -17>
2114 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2116 %and = and <2 x i32> %X, <i32 -16, i32 -16>
2117 %cmp = icmp eq <2 x i32> %and, <i32 -16, i32 -16>
2121 define i1 @icmp_and_X_-16_ne-16(i32 %X) {
2122 ; CHECK-LABEL: @icmp_and_X_-16_ne-16(
2123 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], -16
2124 ; CHECK-NEXT: ret i1 [[CMP]]
2126 %and = and i32 %X, -16
2127 %cmp = icmp ne i32 %and, -16
2131 define <2 x i1> @icmp_and_X_-16_ne-16_vec(<2 x i32> %X) {
2132 ; CHECK-LABEL: @icmp_and_X_-16_ne-16_vec(
2133 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[X:%.*]], <i32 -16, i32 -16>
2134 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2136 %and = and <2 x i32> %X, <i32 -16, i32 -16>
2137 %cmp = icmp ne <2 x i32> %and, <i32 -16, i32 -16>
2141 ; PR32524: https://bugs.llvm.org/show_bug.cgi?id=32524
2142 ; X | C == C --> X <=u C (when C+1 is PowerOf2).
2144 define i1 @or1_eq1(i32 %x) {
2145 ; CHECK-LABEL: @or1_eq1(
2146 ; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 2
2147 ; CHECK-NEXT: ret i1 [[T1]]
2150 %t1 = icmp eq i32 %t0, 1
2154 ; X | C == C --> X <=u C (when C+1 is PowerOf2).
2156 define <2 x i1> @or3_eq3_vec(<2 x i8> %x) {
2157 ; CHECK-LABEL: @or3_eq3_vec(
2158 ; CHECK-NEXT: [[T1:%.*]] = icmp ult <2 x i8> [[X:%.*]], <i8 4, i8 4>
2159 ; CHECK-NEXT: ret <2 x i1> [[T1]]
2161 %t0 = or <2 x i8> %x, <i8 3, i8 3>
2162 %t1 = icmp eq <2 x i8> %t0, <i8 3, i8 3>
2166 ; X | C != C --> X >u C (when C+1 is PowerOf2).
2168 define i1 @or7_ne7(i32 %x) {
2169 ; CHECK-LABEL: @or7_ne7(
2170 ; CHECK-NEXT: [[T1:%.*]] = icmp ugt i32 [[X:%.*]], 7
2171 ; CHECK-NEXT: ret i1 [[T1]]
2174 %t1 = icmp ne i32 %t0, 7
2178 ; X | C != C --> X >u C (when C+1 is PowerOf2).
2180 define <2 x i1> @or63_ne63_vec(<2 x i8> %x) {
2181 ; CHECK-LABEL: @or63_ne63_vec(
2182 ; CHECK-NEXT: [[T1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 63, i8 63>
2183 ; CHECK-NEXT: ret <2 x i1> [[T1]]
2185 %t0 = or <2 x i8> %x, <i8 63, i8 63>
2186 %t1 = icmp ne <2 x i8> %t0, <i8 63, i8 63>
2190 ; PR40611: https://bugs.llvm.org/show_bug.cgi?id=40611
2191 ; X | C == C --> (X & ~C) == 0
2193 define i1 @orC_eqC(i32 %x) {
2194 ; CHECK-LABEL: @orC_eqC(
2195 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -43
2196 ; CHECK-NEXT: [[T1:%.*]] = icmp eq i32 [[TMP1]], 0
2197 ; CHECK-NEXT: ret i1 [[T1]]
2200 %t1 = icmp eq i32 %t0, 42
2204 ; X | C == C --> (X & ~C) == 0
2206 define <2 x i1> @orC_eqC_vec(<2 x i8> %x) {
2207 ; CHECK-LABEL: @orC_eqC_vec(
2208 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -44, i8 -44>
2209 ; CHECK-NEXT: [[T1:%.*]] = icmp eq <2 x i8> [[TMP1]], zeroinitializer
2210 ; CHECK-NEXT: ret <2 x i1> [[T1]]
2212 %t0 = or <2 x i8> %x, <i8 43, i8 43>
2213 %t1 = icmp eq <2 x i8> %t0, <i8 43, i8 43>
2217 ; X | C != C --> (X & ~C) != 0
2219 define i1 @orC_neC(i32 %x) {
2220 ; CHECK-LABEL: @orC_neC(
2221 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 41
2222 ; CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[TMP1]], 0
2223 ; CHECK-NEXT: ret i1 [[T1]]
2225 %t0 = or i32 %x, -42
2226 %t1 = icmp ne i32 %t0, -42
2230 ; X | C != C --> (X & ~C) != 0
2232 define <2 x i1> @orC_neC_vec(<2 x i8> %x) {
2233 ; CHECK-LABEL: @orC_neC_vec(
2234 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 42, i8 42>
2235 ; CHECK-NEXT: [[T1:%.*]] = icmp ne <2 x i8> [[TMP1]], zeroinitializer
2236 ; CHECK-NEXT: ret <2 x i1> [[T1]]
2238 %t0 = or <2 x i8> %x, <i8 -43, i8 -43>
2239 %t1 = icmp ne <2 x i8> %t0, <i8 -43, i8 -43>
2243 define i1 @shrink_constant(i32 %X) {
2244 ; CHECK-LABEL: @shrink_constant(
2245 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], -12
2246 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[XOR]], 4
2247 ; CHECK-NEXT: ret i1 [[CMP]]
2249 %xor = xor i32 %X, -9
2250 %cmp = icmp ult i32 %xor, 4
2254 define <2 x i1> @shrink_constant_vec(<2 x i32> %X) {
2255 ; CHECK-LABEL: @shrink_constant_vec(
2256 ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i32> [[X:%.*]], <i32 -12, i32 -12>
2257 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[XOR]], <i32 4, i32 4>
2258 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2260 %xor = xor <2 x i32> %X, <i32 -9, i32 -9>
2261 %cmp = icmp ult <2 x i32> %xor, <i32 4, i32 4>
2265 ; This test requires 3 different transforms to get to the result.
2266 define i1 @icmp_sub_-1_X_ult_4(i32 %X) {
2267 ; CHECK-LABEL: @icmp_sub_-1_X_ult_4(
2268 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], -5
2269 ; CHECK-NEXT: ret i1 [[CMP]]
2271 %sub = sub i32 -1, %X
2272 %cmp = icmp ult i32 %sub, 4
2276 define <2 x i1> @icmp_xor_neg4_X_ult_4_vec(<2 x i32> %X) {
2277 ; CHECK-LABEL: @icmp_xor_neg4_X_ult_4_vec(
2278 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[X:%.*]], <i32 -5, i32 -5>
2279 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2281 %xor = xor <2 x i32> %X, <i32 -4, i32 -4>
2282 %cmp = icmp ult <2 x i32> %xor, <i32 4, i32 4>
2286 define i1 @icmp_sub_-1_X_uge_4(i32 %X) {
2287 ; CHECK-LABEL: @icmp_sub_-1_X_uge_4(
2288 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], -4
2289 ; CHECK-NEXT: ret i1 [[CMP]]
2291 %sub = sub i32 -1, %X
2292 %cmp = icmp uge i32 %sub, 4
2296 define <2 x i1> @icmp_xor_neg4_X_uge_4_vec(<2 x i32> %X) {
2297 ; CHECK-LABEL: @icmp_xor_neg4_X_uge_4_vec(
2298 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[X:%.*]], <i32 -4, i32 -4>
2299 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2301 %xor = xor <2 x i32> %X, <i32 -4, i32 -4>
2302 %cmp = icmp uge <2 x i32> %xor, <i32 4, i32 4>
2306 define <2 x i1> @xor_ult(<2 x i8> %x) {
2307 ; CHECK-LABEL: @xor_ult(
2308 ; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 3>
2309 ; CHECK-NEXT: ret <2 x i1> [[R]]
2311 %xor = xor <2 x i8> %x, <i8 -4, i8 -4>
2312 %r = icmp ult <2 x i8> %xor, <i8 -4, i8 -4>
2316 define i1 @xor_ult_extra_use(i8 %x, i8* %p) {
2317 ; CHECK-LABEL: @xor_ult_extra_use(
2318 ; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X:%.*]], -32
2319 ; CHECK-NEXT: store i8 [[XOR]], i8* [[P:%.*]], align 1
2320 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[X]], 31
2321 ; CHECK-NEXT: ret i1 [[R]]
2323 %xor = xor i8 %x, -32
2324 store i8 %xor, i8* %p
2325 %r = icmp ult i8 %xor, -32
2329 define <2 x i1> @xor_ugt(<2 x i8> %x) {
2330 ; CHECK-LABEL: @xor_ugt(
2331 ; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 7, i8 7>
2332 ; CHECK-NEXT: ret <2 x i1> [[R]]
2334 %xor = xor <2 x i8> %x, <i8 7, i8 7>
2335 %r = icmp ugt <2 x i8> %xor, <i8 7, i8 7>
2339 define i1 @xor_ugt_extra_use(i8 %x, i8* %p) {
2340 ; CHECK-LABEL: @xor_ugt_extra_use(
2341 ; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[X:%.*]], 63
2342 ; CHECK-NEXT: store i8 [[XOR]], i8* [[P:%.*]], align 1
2343 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[X]], 63
2344 ; CHECK-NEXT: ret i1 [[R]]
2346 %xor = xor i8 %x, 63
2347 store i8 %xor, i8* %p
2348 %r = icmp ugt i8 %xor, 63
2352 define i1 @icmp_swap_operands_for_cse(i32 %X, i32 %Y) {
2353 ; CHECK-LABEL: @icmp_swap_operands_for_cse(
2354 ; CHECK-NEXT: entry:
2355 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
2356 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X]], [[Y]]
2357 ; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
2359 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[SUB]], 1
2360 ; CHECK-NEXT: br label [[END:%.*]]
2362 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[SUB]], 16
2363 ; CHECK-NEXT: br label [[END]]
2365 ; CHECK-NEXT: [[RES_IN:%.*]] = phi i32 [ [[TMP0]], [[TRUE]] ], [ [[TMP1]], [[FALSE]] ]
2366 ; CHECK-NEXT: [[RES:%.*]] = icmp ne i32 [[RES_IN]], 0
2367 ; CHECK-NEXT: ret i1 [[RES]]
2370 %sub = sub i32 %X, %Y
2371 %cmp = icmp ugt i32 %Y, %X
2372 br i1 %cmp, label %true, label %false
2374 %restrue = trunc i32 %sub to i1
2377 %shift = lshr i32 %sub, 4
2378 %resfalse = trunc i32 %shift to i1
2381 %res = phi i1 [%restrue, %true], [%resfalse, %false]
2385 define i1 @icmp_swap_operands_for_cse2(i32 %X, i32 %Y) {
2386 ; CHECK-LABEL: @icmp_swap_operands_for_cse2(
2387 ; CHECK-NEXT: entry:
2388 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
2389 ; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
2391 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X]], [[Y]]
2392 ; CHECK-NEXT: [[SUB1:%.*]] = sub i32 [[X]], [[Y]]
2393 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SUB]], [[SUB1]]
2394 ; CHECK-NEXT: br label [[END:%.*]]
2396 ; CHECK-NEXT: [[SUB2:%.*]] = sub i32 [[Y]], [[X]]
2397 ; CHECK-NEXT: br label [[END]]
2399 ; CHECK-NEXT: [[RES_IN_IN:%.*]] = phi i32 [ [[ADD]], [[TRUE]] ], [ [[SUB2]], [[FALSE]] ]
2400 ; CHECK-NEXT: [[RES_IN:%.*]] = and i32 [[RES_IN_IN]], 1
2401 ; CHECK-NEXT: [[RES:%.*]] = icmp ne i32 [[RES_IN]], 0
2402 ; CHECK-NEXT: ret i1 [[RES]]
2405 %cmp = icmp ugt i32 %Y, %X
2406 br i1 %cmp, label %true, label %false
2408 %sub = sub i32 %X, %Y
2409 %sub1 = sub i32 %X, %Y
2410 %add = add i32 %sub, %sub1
2411 %restrue = trunc i32 %add to i1
2414 %sub2 = sub i32 %Y, %X
2415 %resfalse = trunc i32 %sub2 to i1
2418 %res = phi i1 [%restrue, %true], [%resfalse, %false]
2422 define i1 @icmp_do_not_swap_operands_for_cse(i32 %X, i32 %Y) {
2423 ; CHECK-LABEL: @icmp_do_not_swap_operands_for_cse(
2424 ; CHECK-NEXT: entry:
2425 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[Y:%.*]], [[X:%.*]]
2426 ; CHECK-NEXT: br i1 [[CMP]], label [[TRUE:%.*]], label [[FALSE:%.*]]
2428 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[X]], [[Y]]
2429 ; CHECK-NEXT: br label [[END:%.*]]
2431 ; CHECK-NEXT: [[SUB2:%.*]] = sub i32 [[Y]], [[X]]
2432 ; CHECK-NEXT: br label [[END]]
2434 ; CHECK-NEXT: [[RES_IN_IN:%.*]] = phi i32 [ [[SUB]], [[TRUE]] ], [ [[SUB2]], [[FALSE]] ]
2435 ; CHECK-NEXT: [[RES_IN:%.*]] = and i32 [[RES_IN_IN]], 1
2436 ; CHECK-NEXT: [[RES:%.*]] = icmp ne i32 [[RES_IN]], 0
2437 ; CHECK-NEXT: ret i1 [[RES]]
2440 %cmp = icmp ugt i32 %Y, %X
2441 br i1 %cmp, label %true, label %false
2443 %sub = sub i32 %X, %Y
2444 %restrue = trunc i32 %sub to i1
2447 %sub2 = sub i32 %Y, %X
2448 %resfalse = trunc i32 %sub2 to i1
2451 %res = phi i1 [%restrue, %true], [%resfalse, %false]
2455 define i1 @icmp_lshr_lshr_eq(i32 %a, i32 %b) {
2456 ; CHECK-LABEL: @icmp_lshr_lshr_eq(
2457 ; CHECK-NEXT: [[Z_UNSHIFTED:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
2458 ; CHECK-NEXT: [[Z:%.*]] = icmp ult i32 [[Z_UNSHIFTED]], 1073741824
2459 ; CHECK-NEXT: ret i1 [[Z]]
2461 %x = lshr i32 %a, 30
2462 %y = lshr i32 %b, 30
2463 %z = icmp eq i32 %x, %y
2467 define i1 @icmp_ashr_ashr_ne(i32 %a, i32 %b) {
2468 ; CHECK-LABEL: @icmp_ashr_ashr_ne(
2469 ; CHECK-NEXT: [[Z_UNSHIFTED:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
2470 ; CHECK-NEXT: [[Z:%.*]] = icmp ugt i32 [[Z_UNSHIFTED]], 255
2471 ; CHECK-NEXT: ret i1 [[Z]]
2475 %z = icmp ne i32 %x, %y
2479 define i1 @icmp_neg_cst_slt(i32 %a) {
2480 ; CHECK-LABEL: @icmp_neg_cst_slt(
2481 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], 10
2482 ; CHECK-NEXT: ret i1 [[TMP1]]
2484 %1 = sub nsw i32 0, %a
2485 %2 = icmp slt i32 %1, -10
2489 define i1 @icmp_and_or_lshr(i32 %x, i32 %y) {
2490 ; CHECK-LABEL: @icmp_and_or_lshr(
2491 ; CHECK-NEXT: [[SHF1:%.*]] = shl nuw i32 1, [[Y:%.*]]
2492 ; CHECK-NEXT: [[OR2:%.*]] = or i32 [[SHF1]], 1
2493 ; CHECK-NEXT: [[AND3:%.*]] = and i32 [[OR2]], [[X:%.*]]
2494 ; CHECK-NEXT: [[RET:%.*]] = icmp ne i32 [[AND3]], 0
2495 ; CHECK-NEXT: ret i1 [[RET]]
2497 %shf = lshr i32 %x, %y
2498 %or = or i32 %shf, %x
2499 %and = and i32 %or, 1
2500 %ret = icmp ne i32 %and, 0
2504 define <2 x i1> @icmp_and_or_lshr_vec(<2 x i32> %x, <2 x i32> %y) {
2505 ; CHECK-LABEL: @icmp_and_or_lshr_vec(
2506 ; CHECK-NEXT: [[SHF:%.*]] = lshr <2 x i32> [[X:%.*]], [[Y:%.*]]
2507 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[SHF]], [[X]]
2508 ; CHECK-NEXT: [[RET:%.*]] = trunc <2 x i32> [[OR]] to <2 x i1>
2509 ; CHECK-NEXT: ret <2 x i1> [[RET]]
2511 %shf = lshr <2 x i32> %x, %y
2512 %or = or <2 x i32> %shf, %x
2513 %and = and <2 x i32> %or, <i32 1, i32 1>
2514 %ret = icmp ne <2 x i32> %and, zeroinitializer
2518 define <2 x i1> @icmp_and_or_lshr_vec_commute(<2 x i32> %xp, <2 x i32> %y) {
2519 ; CHECK-LABEL: @icmp_and_or_lshr_vec_commute(
2520 ; CHECK-NEXT: [[X:%.*]] = srem <2 x i32> [[XP:%.*]], <i32 42, i32 42>
2521 ; CHECK-NEXT: [[SHF:%.*]] = lshr <2 x i32> [[X]], [[Y:%.*]]
2522 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[X]], [[SHF]]
2523 ; CHECK-NEXT: [[RET:%.*]] = trunc <2 x i32> [[OR]] to <2 x i1>
2524 ; CHECK-NEXT: ret <2 x i1> [[RET]]
2526 %x = srem <2 x i32> %xp, <i32 42, i32 -42> ; prevent complexity-based canonicalization
2527 %shf = lshr <2 x i32> %x, %y
2528 %or = or <2 x i32> %x, %shf
2529 %and = and <2 x i32> %or, <i32 1, i32 1>
2530 %ret = icmp ne <2 x i32> %and, zeroinitializer
2534 define i1 @icmp_and_or_lshr_cst(i32 %x) {
2535 ; CHECK-LABEL: @icmp_and_or_lshr_cst(
2536 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[X:%.*]], 3
2537 ; CHECK-NEXT: [[RET:%.*]] = icmp ne i32 [[AND1]], 0
2538 ; CHECK-NEXT: ret i1 [[RET]]
2540 %shf = lshr i32 %x, 1
2541 %or = or i32 %shf, %x
2542 %and = and i32 %or, 1
2543 %ret = icmp ne i32 %and, 0
2547 define <2 x i1> @icmp_and_or_lshr_cst_vec(<2 x i32> %x) {
2548 ; CHECK-LABEL: @icmp_and_or_lshr_cst_vec(
2549 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X:%.*]], <i32 3, i32 3>
2550 ; CHECK-NEXT: [[RET:%.*]] = icmp ne <2 x i32> [[TMP1]], zeroinitializer
2551 ; CHECK-NEXT: ret <2 x i1> [[RET]]
2553 %shf = lshr <2 x i32> %x, <i32 1, i32 1>
2554 %or = or <2 x i32> %shf, %x
2555 %and = and <2 x i32> %or, <i32 1, i32 1>
2556 %ret = icmp ne <2 x i32> %and, zeroinitializer
2560 define <2 x i1> @icmp_and_or_lshr_cst_vec_commute(<2 x i32> %xp) {
2561 ; CHECK-LABEL: @icmp_and_or_lshr_cst_vec_commute(
2562 ; CHECK-NEXT: [[X:%.*]] = srem <2 x i32> [[XP:%.*]], <i32 42, i32 42>
2563 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X]], <i32 3, i32 3>
2564 ; CHECK-NEXT: [[RET:%.*]] = icmp ne <2 x i32> [[TMP1]], zeroinitializer
2565 ; CHECK-NEXT: ret <2 x i1> [[RET]]
2567 %x = srem <2 x i32> %xp, <i32 42, i32 -42> ; prevent complexity-based canonicalization
2568 %shf = lshr <2 x i32> %x, <i32 1, i32 1>
2569 %or = or <2 x i32> %x, %shf
2570 %and = and <2 x i32> %or, <i32 1, i32 1>
2571 %ret = icmp ne <2 x i32> %and, zeroinitializer
2575 define i1 @shl_ap1_zero_ap2_non_zero_2(i32 %a) {
2576 ; CHECK-LABEL: @shl_ap1_zero_ap2_non_zero_2(
2577 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[A:%.*]], 29
2578 ; CHECK-NEXT: ret i1 [[CMP]]
2580 %shl = shl i32 4, %a
2581 %cmp = icmp eq i32 %shl, 0
2585 define <2 x i1> @shl_ap1_zero_ap2_non_zero_2_vec(<2 x i32> %a) {
2586 ; CHECK-LABEL: @shl_ap1_zero_ap2_non_zero_2_vec(
2587 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[A:%.*]], <i32 29, i32 29>
2588 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2590 %shl = shl <2 x i32> <i32 4, i32 4>, %a
2591 %cmp = icmp eq <2 x i32> %shl, zeroinitializer
2595 define i1 @shl_ap1_zero_ap2_non_zero_4(i32 %a) {
2596 ; CHECK-LABEL: @shl_ap1_zero_ap2_non_zero_4(
2597 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[A:%.*]], 30
2598 ; CHECK-NEXT: ret i1 [[CMP]]
2600 %shl = shl i32 -2, %a
2601 %cmp = icmp eq i32 %shl, 0
2605 define i1 @shl_ap1_non_zero_ap2_non_zero_both_positive(i32 %a) {
2606 ; CHECK-LABEL: @shl_ap1_non_zero_ap2_non_zero_both_positive(
2607 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 0
2608 ; CHECK-NEXT: ret i1 [[CMP]]
2610 %shl = shl i32 50, %a
2611 %cmp = icmp eq i32 %shl, 50
2615 define i1 @shl_ap1_non_zero_ap2_non_zero_both_negative(i32 %a) {
2616 ; CHECK-LABEL: @shl_ap1_non_zero_ap2_non_zero_both_negative(
2617 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 0
2618 ; CHECK-NEXT: ret i1 [[CMP]]
2620 %shl = shl i32 -50, %a
2621 %cmp = icmp eq i32 %shl, -50
2625 define i1 @shl_ap1_non_zero_ap2_non_zero_ap1_1(i32 %a) {
2626 ; CHECK-LABEL: @shl_ap1_non_zero_ap2_non_zero_ap1_1(
2627 ; CHECK-NEXT: ret i1 false
2629 %shl = shl i32 50, %a
2630 %cmp = icmp eq i32 %shl, 25
2634 define i1 @shl_ap1_non_zero_ap2_non_zero_ap1_2(i32 %a) {
2635 ; CHECK-LABEL: @shl_ap1_non_zero_ap2_non_zero_ap1_2(
2636 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 1
2637 ; CHECK-NEXT: ret i1 [[CMP]]
2639 %shl = shl i32 25, %a
2640 %cmp = icmp eq i32 %shl, 50
2644 define i1 @shl_ap1_non_zero_ap2_non_zero_ap1_3(i32 %a) {
2645 ; CHECK-LABEL: @shl_ap1_non_zero_ap2_non_zero_ap1_3(
2646 ; CHECK-NEXT: ret i1 false
2648 %shl = shl i32 26, %a
2649 %cmp = icmp eq i32 %shl, 50
2653 define i1 @icmp_sgt_zero_add_nsw(i32 %a) {
2654 ; CHECK-LABEL: @icmp_sgt_zero_add_nsw(
2655 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], -1
2656 ; CHECK-NEXT: ret i1 [[CMP]]
2658 %add = add nsw i32 %a, 1
2659 %cmp = icmp sgt i32 %add, 0
2663 define i1 @icmp_sge_zero_add_nsw(i32 %a) {
2664 ; CHECK-LABEL: @icmp_sge_zero_add_nsw(
2665 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], -2
2666 ; CHECK-NEXT: ret i1 [[CMP]]
2668 %add = add nsw i32 %a, 1
2669 %cmp = icmp sge i32 %add, 0
2673 define i1 @icmp_sle_zero_add_nsw(i32 %a) {
2674 ; CHECK-LABEL: @icmp_sle_zero_add_nsw(
2675 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[A:%.*]], 0
2676 ; CHECK-NEXT: ret i1 [[CMP]]
2678 %add = add nsw i32 %a, 1
2679 %cmp = icmp sle i32 %add, 0
2683 define zeroext i1 @icmp_cmpxchg_strong(i32* %sc, i32 %old_val, i32 %new_val) {
2684 ; CHECK-LABEL: @icmp_cmpxchg_strong(
2685 ; CHECK-NEXT: [[XCHG:%.*]] = cmpxchg i32* [[SC:%.*]], i32 [[OLD_VAL:%.*]], i32 [[NEW_VAL:%.*]] seq_cst seq_cst
2686 ; CHECK-NEXT: [[ICMP:%.*]] = extractvalue { i32, i1 } [[XCHG]], 1
2687 ; CHECK-NEXT: ret i1 [[ICMP]]
2689 %xchg = cmpxchg i32* %sc, i32 %old_val, i32 %new_val seq_cst seq_cst
2690 %xtrc = extractvalue { i32, i1 } %xchg, 0
2691 %icmp = icmp eq i32 %xtrc, %old_val
2695 define i1 @f1(i64 %a, i64 %b) {
2697 ; CHECK-NEXT: [[V:%.*]] = icmp sge i64 [[A:%.*]], [[B:%.*]]
2698 ; CHECK-NEXT: ret i1 [[V]]
2700 %t = sub nsw i64 %a, %b
2701 %v = icmp sge i64 %t, 0
2705 define <2 x i1> @f1_vec(<2 x i64> %a, <2 x i64> %b) {
2706 ; CHECK-LABEL: @f1_vec(
2707 ; CHECK-NEXT: [[V:%.*]] = icmp sge <2 x i64> [[A:%.*]], [[B:%.*]]
2708 ; CHECK-NEXT: ret <2 x i1> [[V]]
2710 %t = sub nsw <2 x i64> %a, %b
2711 %v = icmp sgt <2 x i64> %t, <i64 -1, i64 -1>
2715 define i1 @f2(i64 %a, i64 %b) {
2717 ; CHECK-NEXT: [[V:%.*]] = icmp sgt i64 [[A:%.*]], [[B:%.*]]
2718 ; CHECK-NEXT: ret i1 [[V]]
2720 %t = sub nsw i64 %a, %b
2721 %v = icmp sgt i64 %t, 0
2725 define <2 x i1> @f2_vec(<2 x i64> %a, <2 x i64> %b) {
2726 ; CHECK-LABEL: @f2_vec(
2727 ; CHECK-NEXT: [[V:%.*]] = icmp sgt <2 x i64> [[A:%.*]], [[B:%.*]]
2728 ; CHECK-NEXT: ret <2 x i1> [[V]]
2730 %t = sub nsw <2 x i64> %a, %b
2731 %v = icmp sgt <2 x i64> %t, zeroinitializer
2735 define i1 @f3(i64 %a, i64 %b) {
2737 ; CHECK-NEXT: [[V:%.*]] = icmp slt i64 [[A:%.*]], [[B:%.*]]
2738 ; CHECK-NEXT: ret i1 [[V]]
2740 %t = sub nsw i64 %a, %b
2741 %v = icmp slt i64 %t, 0
2745 define <2 x i1> @f3_vec(<2 x i64> %a, <2 x i64> %b) {
2746 ; CHECK-LABEL: @f3_vec(
2747 ; CHECK-NEXT: [[V:%.*]] = icmp slt <2 x i64> [[A:%.*]], [[B:%.*]]
2748 ; CHECK-NEXT: ret <2 x i1> [[V]]
2750 %t = sub nsw <2 x i64> %a, %b
2751 %v = icmp slt <2 x i64> %t, zeroinitializer
2755 define i1 @f4(i64 %a, i64 %b) {
2757 ; CHECK-NEXT: [[V:%.*]] = icmp sle i64 [[A:%.*]], [[B:%.*]]
2758 ; CHECK-NEXT: ret i1 [[V]]
2760 %t = sub nsw i64 %a, %b
2761 %v = icmp sle i64 %t, 0
2765 define <2 x i1> @f4_vec(<2 x i64> %a, <2 x i64> %b) {
2766 ; CHECK-LABEL: @f4_vec(
2767 ; CHECK-NEXT: [[V:%.*]] = icmp sle <2 x i64> [[A:%.*]], [[B:%.*]]
2768 ; CHECK-NEXT: ret <2 x i1> [[V]]
2770 %t = sub nsw <2 x i64> %a, %b
2771 %v = icmp slt <2 x i64> %t, <i64 1, i64 1>
2775 define i32 @f5(i8 %a, i8 %b) {
2777 ; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[A:%.*]] to i32
2778 ; CHECK-NEXT: [[CONV3:%.*]] = zext i8 [[B:%.*]] to i32
2779 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[CONV]], [[CONV3]]
2780 ; CHECK-NEXT: [[CMP4:%.*]] = icmp slt i32 [[SUB]], 0
2781 ; CHECK-NEXT: [[SUB7:%.*]] = sub nsw i32 0, [[SUB]]
2782 ; CHECK-NEXT: [[SUB7_SUB:%.*]] = select i1 [[CMP4]], i32 [[SUB7]], i32 [[SUB]]
2783 ; CHECK-NEXT: ret i32 [[SUB7_SUB]]
2785 %conv = zext i8 %a to i32
2786 %conv3 = zext i8 %b to i32
2787 %sub = sub nsw i32 %conv, %conv3
2788 %cmp4 = icmp slt i32 %sub, 0
2789 %sub7 = sub nsw i32 0, %sub
2790 %sub7.sub = select i1 %cmp4, i32 %sub7, i32 %sub
2794 define i32 @f6(i32 %a, i32 %b) {
2796 ; CHECK-NEXT: [[CMP_UNSHIFTED:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
2797 ; CHECK-NEXT: [[CMP_MASK:%.*]] = and i32 [[CMP_UNSHIFTED]], 255
2798 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CMP_MASK]], 0
2799 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i32 10000, i32 0
2800 ; CHECK-NEXT: ret i32 [[S]]
2802 %sext = shl i32 %a, 24
2803 %conv = ashr i32 %sext, 24
2804 %sext6 = shl i32 %b, 24
2805 %conv4 = ashr i32 %sext6, 24
2806 %cmp = icmp eq i32 %conv, %conv4
2807 %s = select i1 %cmp, i32 10000, i32 0
2811 define i32 @f7(i32 %a, i32 %b) {
2813 ; CHECK-NEXT: [[CMP_UNSHIFTED:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
2814 ; CHECK-NEXT: [[CMP_MASK:%.*]] = and i32 [[CMP_UNSHIFTED]], 511
2815 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CMP_MASK]], 0
2816 ; CHECK-NEXT: [[S:%.*]] = select i1 [[CMP]], i32 0, i32 10000
2817 ; CHECK-NEXT: ret i32 [[S]]
2819 %sext = shl i32 %a, 23
2820 %sext6 = shl i32 %b, 23
2821 %cmp = icmp ne i32 %sext, %sext6
2822 %s = select i1 %cmp, i32 10000, i32 0
2826 define i1 @f8(i32 %val, i32 %lim) {
2828 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[LIM:%.*]], 0
2829 ; CHECK-NEXT: ret i1 [[R]]
2831 %lim.sub = add i32 %lim, -1
2832 %val.and = and i32 %val, %lim.sub
2833 %r = icmp ult i32 %val.and, %lim
2837 define i1 @f9(i32 %val, i32 %lim) {
2839 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[LIM:%.*]], 0
2840 ; CHECK-NEXT: ret i1 [[R]]
2842 %lim.sub = sub i32 %lim, 1
2843 %val.and = and i32 %val, %lim.sub
2844 %r = icmp ult i32 %val.and, %lim
2848 define i1 @f10(i16 %p) {
2849 ; CHECK-LABEL: @f10(
2850 ; CHECK-NEXT: [[CMP580:%.*]] = icmp uge i16 [[P:%.*]], mul (i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16), i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16))
2851 ; CHECK-NEXT: ret i1 [[CMP580]]
2853 %cmp580 = icmp ule i16 mul (i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16), i16 zext (i8 ptrtoint (i1 (i16)* @f10 to i8) to i16)), %p
2857 ; Note: fptosi is used in various tests below to ensure that operand complexity
2858 ; canonicalization does not kick in, which would make some of the tests
2859 ; equivalent to one another.
2861 define i1 @cmp_sgt_rhs_dec(float %x, i32 %i) {
2862 ; CHECK-LABEL: @cmp_sgt_rhs_dec(
2863 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
2864 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[CONV]], [[I:%.*]]
2865 ; CHECK-NEXT: ret i1 [[CMP]]
2867 %conv = fptosi float %x to i32
2868 %dec = sub nsw i32 %i, 1
2869 %cmp = icmp sgt i32 %conv, %dec
2873 define i1 @cmp_sle_rhs_dec(float %x, i32 %i) {
2874 ; CHECK-LABEL: @cmp_sle_rhs_dec(
2875 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
2876 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[CONV]], [[I:%.*]]
2877 ; CHECK-NEXT: ret i1 [[CMP]]
2879 %conv = fptosi float %x to i32
2880 %dec = sub nsw i32 %i, 1
2881 %cmp = icmp sle i32 %conv, %dec
2885 define i1 @cmp_sge_rhs_inc(float %x, i32 %i) {
2886 ; CHECK-LABEL: @cmp_sge_rhs_inc(
2887 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
2888 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CONV]], [[I:%.*]]
2889 ; CHECK-NEXT: ret i1 [[CMP]]
2891 %conv = fptosi float %x to i32
2892 %inc = add nsw i32 %i, 1
2893 %cmp = icmp sge i32 %conv, %inc
2897 define i1 @cmp_slt_rhs_inc(float %x, i32 %i) {
2898 ; CHECK-LABEL: @cmp_slt_rhs_inc(
2899 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
2900 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[CONV]], [[I:%.*]]
2901 ; CHECK-NEXT: ret i1 [[CMP]]
2903 %conv = fptosi float %x to i32
2904 %inc = add nsw i32 %i, 1
2905 %cmp = icmp slt i32 %conv, %inc
2909 define i1 @PR26407(i32 %x, i32 %y) {
2910 ; CHECK-LABEL: @PR26407(
2911 ; CHECK-NEXT: [[ADDX:%.*]] = add i32 [[X:%.*]], 2147483647
2912 ; CHECK-NEXT: [[ADDY:%.*]] = add i32 [[Y:%.*]], 2147483647
2913 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[ADDX]], [[ADDY]]
2914 ; CHECK-NEXT: ret i1 [[CMP]]
2916 %addx = add i32 %x, 2147483647
2917 %addy = add i32 %y, 2147483647
2918 %cmp = icmp uge i32 %addx, %addy
2922 define i1 @cmp_inverse_mask_bits_set_eq(i32 %x) {
2923 ; CHECK-LABEL: @cmp_inverse_mask_bits_set_eq(
2924 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -43
2925 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], -43
2926 ; CHECK-NEXT: ret i1 [[CMP]]
2929 %cmp = icmp eq i32 %or, -1
2933 define <2 x i1> @cmp_inverse_mask_bits_set_eq_vec(<2 x i32> %x) {
2934 ; CHECK-LABEL: @cmp_inverse_mask_bits_set_eq_vec(
2935 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X:%.*]], <i32 -43, i32 -43>
2936 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[TMP1]], <i32 -43, i32 -43>
2937 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2939 %or = or <2 x i32> %x, <i32 42, i32 42>
2940 %cmp = icmp eq <2 x i32> %or, <i32 -1, i32 -1>
2944 define i1 @cmp_inverse_mask_bits_set_ne(i32 %x) {
2945 ; CHECK-LABEL: @cmp_inverse_mask_bits_set_ne(
2946 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -43
2947 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP1]], -43
2948 ; CHECK-NEXT: ret i1 [[CMP]]
2951 %cmp = icmp ne i32 %or, -1
2955 ; When canonicalizing to 'gt/lt', make sure the constant is correct.
2957 define i1 @PR27792(i128 %a) {
2958 ; CHECK-LABEL: @PR27792(
2959 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[A:%.*]], -1
2960 ; CHECK-NEXT: ret i1 [[CMP]]
2962 %cmp = icmp sge i128 %a, 0
2966 define i1 @PR27792_2(i128 %a) {
2967 ; CHECK-LABEL: @PR27792_2(
2968 ; CHECK-NEXT: [[B:%.*]] = icmp ne i128 [[A:%.*]], 0
2969 ; CHECK-NEXT: ret i1 [[B]]
2971 %b = icmp uge i128 %a, 1
2975 define i1 @ugtMaxSignedVal(i8 %a) {
2976 ; CHECK-LABEL: @ugtMaxSignedVal(
2977 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[A:%.*]], 0
2978 ; CHECK-NEXT: ret i1 [[CMP]]
2980 %cmp = icmp ugt i8 %a, 127
2984 define <2 x i1> @ugtMaxSignedValVec(<2 x i8> %a) {
2985 ; CHECK-LABEL: @ugtMaxSignedValVec(
2986 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[A:%.*]], zeroinitializer
2987 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2989 %cmp = icmp ugt <2 x i8> %a, <i8 127, i8 127>
2993 define i1 @ugtKnownBits(i8 %a) {
2994 ; CHECK-LABEL: @ugtKnownBits(
2995 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], 17
2996 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[B]], 17
2997 ; CHECK-NEXT: ret i1 [[CMP]]
3000 %cmp = icmp ugt i8 %b, 16
3004 define <2 x i1> @ugtKnownBitsVec(<2 x i8> %a) {
3005 ; CHECK-LABEL: @ugtKnownBitsVec(
3006 ; CHECK-NEXT: [[B:%.*]] = and <2 x i8> [[A:%.*]], <i8 17, i8 17>
3007 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[B]], <i8 17, i8 17>
3008 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
3010 %b = and <2 x i8> %a, <i8 17, i8 17>
3011 %cmp = icmp ugt <2 x i8> %b, <i8 16, i8 16>
3015 define i1 @or_ptrtoint_mismatch(i8* %p, i32* %q) {
3016 ; CHECK-LABEL: @or_ptrtoint_mismatch(
3017 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8* [[P:%.*]], null
3018 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32* [[Q:%.*]], null
3019 ; CHECK-NEXT: [[B:%.*]] = and i1 [[TMP1]], [[TMP2]]
3020 ; CHECK-NEXT: ret i1 [[B]]
3023 %pp = ptrtoint i8* %p to i64
3024 %qq = ptrtoint i32* %q to i64
3025 %o = or i64 %pp, %qq
3026 %b = icmp eq i64 %o, 0
3030 define i1 @icmp_add1_ugt(i32 %x, i32 %y) {
3031 ; CHECK-LABEL: @icmp_add1_ugt(
3032 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
3033 ; CHECK-NEXT: ret i1 [[CMP]]
3035 %add = add nuw i32 %x, 1
3036 %cmp = icmp ugt i32 %add, %y
3040 define i1 @icmp_add1_ule(i32 %x, i32 %y) {
3041 ; CHECK-LABEL: @icmp_add1_ule(
3042 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
3043 ; CHECK-NEXT: ret i1 [[CMP]]
3045 %add = add nuw i32 %x, 1
3046 %cmp = icmp ule i32 %add, %y
3050 define i1 @cmp_uge_rhs_inc(float %x, i32 %i) {
3051 ; CHECK-LABEL: @cmp_uge_rhs_inc(
3052 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
3053 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[CONV]], [[I:%.*]]
3054 ; CHECK-NEXT: ret i1 [[CMP]]
3056 %conv = fptosi float %x to i32
3057 %inc = add nuw i32 %i, 1
3058 %cmp = icmp uge i32 %conv, %inc
3062 define i1 @cmp_ult_rhs_inc(float %x, i32 %i) {
3063 ; CHECK-LABEL: @cmp_ult_rhs_inc(
3064 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
3065 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule i32 [[CONV]], [[I:%.*]]
3066 ; CHECK-NEXT: ret i1 [[CMP]]
3068 %conv = fptosi float %x to i32
3069 %inc = add nuw i32 %i, 1
3070 %cmp = icmp ult i32 %conv, %inc
3074 define i1 @cmp_sge_lhs_inc(i32 %x, i32 %y) {
3075 ; CHECK-LABEL: @cmp_sge_lhs_inc(
3076 ; CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[X:%.*]], 1
3077 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[INC]], [[Y:%.*]]
3078 ; CHECK-NEXT: ret i1 [[CMP]]
3080 %inc = add nsw i32 %x, 1
3081 %cmp = icmp sge i32 %inc, %y
3085 define i1 @cmp_uge_lhs_inc(i32 %x, i32 %y) {
3086 ; CHECK-LABEL: @cmp_uge_lhs_inc(
3087 ; CHECK-NEXT: [[INC:%.*]] = add nuw i32 [[X:%.*]], 1
3088 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[INC]], [[Y:%.*]]
3089 ; CHECK-NEXT: ret i1 [[CMP]]
3091 %inc = add nuw i32 %x, 1
3092 %cmp = icmp uge i32 %inc, %y
3096 define i1 @cmp_sgt_lhs_dec(i32 %x, i32 %y) {
3097 ; CHECK-LABEL: @cmp_sgt_lhs_dec(
3098 ; CHECK-NEXT: [[DEC:%.*]] = add nsw i32 [[X:%.*]], -1
3099 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[DEC]], [[Y:%.*]]
3100 ; CHECK-NEXT: ret i1 [[CMP]]
3102 %dec = sub nsw i32 %x, 1
3103 %cmp = icmp sgt i32 %dec, %y
3107 define i1 @cmp_ugt_lhs_dec(i32 %x, i32 %y) {
3108 ; CHECK-LABEL: @cmp_ugt_lhs_dec(
3109 ; CHECK-NEXT: [[DEC:%.*]] = add i32 [[X:%.*]], -1
3110 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC]], [[Y:%.*]]
3111 ; CHECK-NEXT: ret i1 [[CMP]]
3113 %dec = sub nuw i32 %x, 1
3114 %cmp = icmp ugt i32 %dec, %y
3118 define i1 @cmp_sle_rhs_inc(float %x, i32 %y) {
3119 ; CHECK-LABEL: @cmp_sle_rhs_inc(
3120 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
3121 ; CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[Y:%.*]], 1
3122 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[INC]], [[CONV]]
3123 ; CHECK-NEXT: ret i1 [[CMP]]
3125 %conv = fptosi float %x to i32
3126 %inc = add nsw i32 %y, 1
3127 %cmp = icmp sle i32 %conv, %inc
3131 define i1 @cmp_ule_rhs_inc(float %x, i32 %y) {
3132 ; CHECK-LABEL: @cmp_ule_rhs_inc(
3133 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
3134 ; CHECK-NEXT: [[INC:%.*]] = add nuw i32 [[Y:%.*]], 1
3135 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge i32 [[INC]], [[CONV]]
3136 ; CHECK-NEXT: ret i1 [[CMP]]
3138 %conv = fptosi float %x to i32
3139 %inc = add nuw i32 %y, 1
3140 %cmp = icmp ule i32 %conv, %inc
3144 define i1 @cmp_slt_rhs_dec(float %x, i32 %y) {
3145 ; CHECK-LABEL: @cmp_slt_rhs_dec(
3146 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
3147 ; CHECK-NEXT: [[DEC:%.*]] = add nsw i32 [[Y:%.*]], -1
3148 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[DEC]], [[CONV]]
3149 ; CHECK-NEXT: ret i1 [[CMP]]
3151 %conv = fptosi float %x to i32
3152 %dec = sub nsw i32 %y, 1
3153 %cmp = icmp slt i32 %conv, %dec
3157 define i1 @cmp_ult_rhs_dec(float %x, i32 %y) {
3158 ; CHECK-LABEL: @cmp_ult_rhs_dec(
3159 ; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[X:%.*]] to i32
3160 ; CHECK-NEXT: [[DEC:%.*]] = add i32 [[Y:%.*]], -1
3161 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC]], [[CONV]]
3162 ; CHECK-NEXT: ret i1 [[CMP]]
3164 %conv = fptosi float %x to i32
3165 %dec = sub nuw i32 %y, 1
3166 %cmp = icmp ult i32 %conv, %dec
3170 define i1 @eq_add_constants(i32 %x, i32 %y) {
3171 ; CHECK-LABEL: @eq_add_constants(
3172 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
3173 ; CHECK-NEXT: ret i1 [[C]]
3177 %C = icmp eq i32 %A, %B
3181 define i1 @eq_mul_constants(i32 %x, i32 %y) {
3182 ; CHECK-LABEL: @eq_mul_constants(
3183 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
3184 ; CHECK-NEXT: ret i1 [[C]]
3188 %C = icmp eq i32 %A, %B
3192 define <2 x i1> @eq_mul_constants_splat(<2 x i32> %x, <2 x i32> %y) {
3193 ; CHECK-LABEL: @eq_mul_constants_splat(
3194 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[X:%.*]], [[Y:%.*]]
3195 ; CHECK-NEXT: ret <2 x i1> [[C]]
3197 %A = mul <2 x i32> %x, <i32 5, i32 5>
3198 %B = mul <2 x i32> %y, <i32 5, i32 5>
3199 %C = icmp ne <2 x i32> %A, %B
3203 ; If the multiply constant has any trailing zero bits, we get something completely different.
3204 ; We mask off the high bits of each input and then convert:
3205 ; (X&Z) == (Y&Z) -> (X^Y) & Z == 0
3207 define i1 @eq_mul_constants_with_tz(i32 %x, i32 %y) {
3208 ; CHECK-LABEL: @eq_mul_constants_with_tz(
3209 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
3210 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 1073741823
3211 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[TMP2]], 0
3212 ; CHECK-NEXT: ret i1 [[C]]
3216 %C = icmp ne i32 %A, %B
3220 define <2 x i1> @eq_mul_constants_with_tz_splat(<2 x i32> %x, <2 x i32> %y) {
3221 ; CHECK-LABEL: @eq_mul_constants_with_tz_splat(
3222 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[X:%.*]], [[Y:%.*]]
3223 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 1073741823, i32 1073741823>
3224 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[TMP2]], zeroinitializer
3225 ; CHECK-NEXT: ret <2 x i1> [[C]]
3227 %A = mul <2 x i32> %x, <i32 12, i32 12>
3228 %B = mul <2 x i32> %y, <i32 12, i32 12>
3229 %C = icmp eq <2 x i32> %A, %B
3233 declare i32 @llvm.bswap.i32(i32)
3235 define i1 @bswap_ne(i32 %x, i32 %y) {
3236 ; CHECK-LABEL: @bswap_ne(
3237 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], [[Y:%.*]]
3238 ; CHECK-NEXT: ret i1 [[CMP]]
3240 %swapx = call i32 @llvm.bswap.i32(i32 %x)
3241 %swapy = call i32 @llvm.bswap.i32(i32 %y)
3242 %cmp = icmp ne i32 %swapx, %swapy
3246 declare <8 x i16> @llvm.bswap.v8i16(<8 x i16>)
3248 define <8 x i1> @bswap_vec_eq(<8 x i16> %x, <8 x i16> %y) {
3249 ; CHECK-LABEL: @bswap_vec_eq(
3250 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <8 x i16> [[X:%.*]], [[Y:%.*]]
3251 ; CHECK-NEXT: ret <8 x i1> [[CMP]]
3253 %swapx = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %x)
3254 %swapy = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %y)
3255 %cmp = icmp eq <8 x i16> %swapx, %swapy
3259 declare i64 @llvm.bitreverse.i64(i64)
3261 define i1 @bitreverse_eq(i64 %x, i64 %y) {
3262 ; CHECK-LABEL: @bitreverse_eq(
3263 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[X:%.*]], [[Y:%.*]]
3264 ; CHECK-NEXT: ret i1 [[CMP]]
3266 %revx = call i64 @llvm.bitreverse.i64(i64 %x)
3267 %revy = call i64 @llvm.bitreverse.i64(i64 %y)
3268 %cmp = icmp eq i64 %revx, %revy
3272 declare <8 x i16> @llvm.bitreverse.v8i16(<8 x i16>)
3274 define <8 x i1> @bitreverse_vec_ne(<8 x i16> %x, <8 x i16> %y) {
3275 ; CHECK-LABEL: @bitreverse_vec_ne(
3276 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <8 x i16> [[X:%.*]], [[Y:%.*]]
3277 ; CHECK-NEXT: ret <8 x i1> [[CMP]]
3279 %revx = call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> %x)
3280 %revy = call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> %y)
3281 %cmp = icmp ne <8 x i16> %revx, %revy
3285 ; These perform a comparison of a value known to be between 4 and 5 with a value between 5 and 7.
3286 ; They should all simplify to equality compares.
3287 define i1 @knownbits1(i8 %a, i8 %b) {
3288 ; CHECK-LABEL: @knownbits1(
3289 ; CHECK-NEXT: [[A1:%.*]] = and i8 [[A:%.*]], 1
3290 ; CHECK-NEXT: [[A2:%.*]] = or i8 [[A1]], 4
3291 ; CHECK-NEXT: [[B1:%.*]] = and i8 [[B:%.*]], 2
3292 ; CHECK-NEXT: [[B2:%.*]] = or i8 [[B1]], 5
3293 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[A2]], [[B2]]
3294 ; CHECK-NEXT: ret i1 [[C]]
3300 %c = icmp uge i8 %a2, %b2
3304 define i1 @knownbits2(i8 %a, i8 %b) {
3305 ; CHECK-LABEL: @knownbits2(
3306 ; CHECK-NEXT: [[A1:%.*]] = and i8 [[A:%.*]], 1
3307 ; CHECK-NEXT: [[A2:%.*]] = or i8 [[A1]], 4
3308 ; CHECK-NEXT: [[B1:%.*]] = and i8 [[B:%.*]], 2
3309 ; CHECK-NEXT: [[B2:%.*]] = or i8 [[B1]], 5
3310 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[A2]], [[B2]]
3311 ; CHECK-NEXT: ret i1 [[C]]
3317 %c = icmp ult i8 %a2, %b2
3321 define i1 @knownbits3(i8 %a, i8 %b) {
3322 ; CHECK-LABEL: @knownbits3(
3323 ; CHECK-NEXT: [[A1:%.*]] = and i8 [[A:%.*]], 1
3324 ; CHECK-NEXT: [[A2:%.*]] = or i8 [[A1]], 4
3325 ; CHECK-NEXT: [[B1:%.*]] = and i8 [[B:%.*]], 2
3326 ; CHECK-NEXT: [[B2:%.*]] = or i8 [[B1]], 5
3327 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B2]], [[A2]]
3328 ; CHECK-NEXT: ret i1 [[C]]
3334 %c = icmp ule i8 %b2, %a2
3338 define <2 x i1> @knownbits4(<2 x i8> %a, <2 x i8> %b) {
3339 ; CHECK-LABEL: @knownbits4(
3340 ; CHECK-NEXT: [[A1:%.*]] = and <2 x i8> [[A:%.*]], <i8 1, i8 1>
3341 ; CHECK-NEXT: [[A2:%.*]] = or <2 x i8> [[A1]], <i8 4, i8 4>
3342 ; CHECK-NEXT: [[B1:%.*]] = and <2 x i8> [[B:%.*]], <i8 2, i8 2>
3343 ; CHECK-NEXT: [[B2:%.*]] = or <2 x i8> [[B1]], <i8 5, i8 5>
3344 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i8> [[B2]], [[A2]]
3345 ; CHECK-NEXT: ret <2 x i1> [[C]]
3347 %a1 = and <2 x i8> %a, <i8 5, i8 5>
3348 %a2 = or <2 x i8> %a1, <i8 4, i8 4>
3349 %b1 = and <2 x i8> %b, <i8 7, i8 7>
3350 %b2 = or <2 x i8> %b1, <i8 5, i8 5>
3351 %c = icmp ugt <2 x i8> %b2, %a2
3355 ; These are the signed versions of the above. One value is less than or equal to 5, but maybe negative.
3356 ; The other is known to be a value 5-7. These should simplify to equality comparisons.
3357 define i1 @knownbits5(i8 %a, i8 %b) {
3358 ; CHECK-LABEL: @knownbits5(
3359 ; CHECK-NEXT: [[A1:%.*]] = and i8 [[A:%.*]], -127
3360 ; CHECK-NEXT: [[A2:%.*]] = or i8 [[A1]], 4
3361 ; CHECK-NEXT: [[B1:%.*]] = and i8 [[B:%.*]], 2
3362 ; CHECK-NEXT: [[B2:%.*]] = or i8 [[B1]], 5
3363 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[A2]], [[B2]]
3364 ; CHECK-NEXT: ret i1 [[C]]
3366 %a1 = and i8 %a, 133
3370 %c = icmp sge i8 %a2, %b2
3374 define i1 @knownbits6(i8 %a, i8 %b) {
3375 ; CHECK-LABEL: @knownbits6(
3376 ; CHECK-NEXT: [[A1:%.*]] = and i8 [[A:%.*]], -127
3377 ; CHECK-NEXT: [[A2:%.*]] = or i8 [[A1]], 4
3378 ; CHECK-NEXT: [[B1:%.*]] = and i8 [[B:%.*]], 2
3379 ; CHECK-NEXT: [[B2:%.*]] = or i8 [[B1]], 5
3380 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[A2]], [[B2]]
3381 ; CHECK-NEXT: ret i1 [[C]]
3383 %a1 = and i8 %a, 133
3387 %c = icmp slt i8 %a2, %b2
3391 define <2 x i1> @knownbits7(<2 x i8> %a, <2 x i8> %b) {
3392 ; CHECK-LABEL: @knownbits7(
3393 ; CHECK-NEXT: [[A1:%.*]] = and <2 x i8> [[A:%.*]], <i8 -127, i8 -127>
3394 ; CHECK-NEXT: [[A2:%.*]] = or <2 x i8> [[A1]], <i8 4, i8 4>
3395 ; CHECK-NEXT: [[B1:%.*]] = and <2 x i8> [[B:%.*]], <i8 2, i8 2>
3396 ; CHECK-NEXT: [[B2:%.*]] = or <2 x i8> [[B1]], <i8 5, i8 5>
3397 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i8> [[B2]], [[A2]]
3398 ; CHECK-NEXT: ret <2 x i1> [[C]]
3400 %a1 = and <2 x i8> %a, <i8 133, i8 133>
3401 %a2 = or <2 x i8> %a1, <i8 4, i8 4>
3402 %b1 = and <2 x i8> %b, <i8 7, i8 7>
3403 %b2 = or <2 x i8> %b1, <i8 5, i8 5>
3404 %c = icmp sle <2 x i8> %b2, %a2
3408 define i1 @knownbits8(i8 %a, i8 %b) {
3409 ; CHECK-LABEL: @knownbits8(
3410 ; CHECK-NEXT: [[A1:%.*]] = and i8 [[A:%.*]], -127
3411 ; CHECK-NEXT: [[A2:%.*]] = or i8 [[A1]], 4
3412 ; CHECK-NEXT: [[B1:%.*]] = and i8 [[B:%.*]], 2
3413 ; CHECK-NEXT: [[B2:%.*]] = or i8 [[B1]], 5
3414 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[B2]], [[A2]]
3415 ; CHECK-NEXT: ret i1 [[C]]
3417 %a1 = and i8 %a, 133
3421 %c = icmp sgt i8 %b2, %a2
3425 ; Make sure InstCombine doesn't try too hard to simplify the icmp and break the abs idiom
3426 define i32 @abs_preserve(i32 %x) {
3427 ; CHECK-LABEL: @abs_preserve(
3428 ; CHECK-NEXT: [[A:%.*]] = shl nsw i32 [[X:%.*]], 1
3429 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[A]], 0
3430 ; CHECK-NEXT: [[NEGA:%.*]] = sub i32 0, [[A]]
3431 ; CHECK-NEXT: [[ABS:%.*]] = select i1 [[C]], i32 [[NEGA]], i32 [[A]]
3432 ; CHECK-NEXT: ret i32 [[ABS]]
3434 %a = mul nsw i32 %x, 2
3435 %c = icmp sge i32 %a, 0
3436 %nega = sub i32 0, %a
3437 %abs = select i1 %c, i32 %a, i32 %nega
3441 ; Don't crash by assuming the compared values are integers.
3443 declare void @llvm.assume(i1)
3444 define i1 @PR35794(i32* %a) {
3445 ; CHECK-LABEL: @PR35794(
3446 ; CHECK-NEXT: [[MASKCOND:%.*]] = icmp eq i32* [[A:%.*]], null
3447 ; CHECK-NEXT: tail call void @llvm.assume(i1 [[MASKCOND]])
3448 ; CHECK-NEXT: ret i1 true
3450 %cmp = icmp sgt i32* %a, inttoptr (i64 -1 to i32*)
3451 %maskcond = icmp eq i32* %a, null
3452 tail call void @llvm.assume(i1 %maskcond)
3456 ; Don't crash by assuming the compared values are integers.
3457 define <2 x i1> @PR36583(<2 x i8*>) {
3458 ; CHECK-LABEL: @PR36583(
3459 ; CHECK-NEXT: [[RES:%.*]] = icmp eq <2 x i8*> [[TMP0:%.*]], zeroinitializer
3460 ; CHECK-NEXT: ret <2 x i1> [[RES]]
3462 %cast = ptrtoint <2 x i8*> %0 to <2 x i64>
3463 %res = icmp eq <2 x i64> %cast, zeroinitializer
3467 ; fold (icmp pred (sub (0, X)) C1) for vec type
3468 define <2 x i32> @Op1Negated_Vec(<2 x i32> %x) {
3469 ; CHECK-LABEL: @Op1Negated_Vec(
3470 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
3471 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X]], zeroinitializer
3472 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> [[X]]
3473 ; CHECK-NEXT: ret <2 x i32> [[COND]]
3475 %sub = sub nsw <2 x i32> zeroinitializer, %x
3476 %cmp = icmp sgt <2 x i32> %sub, <i32 -1, i32 -1>
3477 %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x