1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3 target datalayout = "p:32:32-p1:64:64"
5 declare void @llvm.assume(i1)
7 define i1 @ptrtoint() {
8 ; CHECK-LABEL: @ptrtoint(
9 ; CHECK-NEXT: ret i1 false
12 %tmp = ptrtoint ptr %a to i32
13 %r = icmp eq i32 %tmp, 0
17 define i1 @bitcast() {
18 ; CHECK-LABEL: @bitcast(
19 ; CHECK-NEXT: ret i1 false
23 %cmp = icmp eq ptr %a, %b
29 ; CHECK-NEXT: ret i1 false
31 %a = alloca [3 x i8], align 8
32 %cmp = icmp eq ptr %a, null
38 ; CHECK-NEXT: ret i1 true
40 %a = alloca [3 x i8], align 8
41 %cmp = icmp eq ptr %a, %a
46 %gept = type { i32, i32 }
47 @gepy = global %gept zeroinitializer, align 8
48 @gepz = extern_weak global %gept
52 ; CHECK-NEXT: ret i1 false
54 %x = alloca %gept, align 8
55 %b = getelementptr %gept, ptr %x, i64 0, i32 1
56 %equal = icmp eq ptr %x, %b
62 ; CHECK-NEXT: ret i1 false
64 %x = alloca %gept, align 8
65 %b = getelementptr %gept, ptr @gepy, i64 0, i32 1
66 %equal = icmp eq ptr @gepy, %b
70 @a = common global [1 x i32] zeroinitializer, align 4
72 define i1 @PR31262() {
73 ; CHECK-LABEL: @PR31262(
74 ; CHECK-NEXT: ret i1 true
76 %idx = getelementptr inbounds [1 x i32], ptr @a, i64 0, i64 undef
77 %cmp = icmp uge ptr %idx, @a
83 ; CHECK-NEXT: ret i1 false
85 %x = alloca %gept, align 8
86 %a = getelementptr inbounds %gept, ptr %x, i64 0, i32 1
87 %equal = icmp eq ptr %a, @gepy
91 define i1 @gep6(ptr %x) {
92 ; Same as @gep3 but potentially null.
94 ; CHECK-NEXT: ret i1 false
96 %b = getelementptr %gept, ptr %x, i64 0, i32 1
97 %equal = icmp eq ptr %x, %b
101 define i1 @gep7(ptr %x) {
102 ; CHECK-LABEL: @gep7(
103 ; CHECK-NEXT: [[EQUAL:%.*]] = icmp eq ptr [[X:%.*]], @gepz
104 ; CHECK-NEXT: ret i1 [[EQUAL]]
106 %equal = icmp eq ptr %x, @gepz
110 define i1 @gep8(ptr %x) {
111 ; CHECK-LABEL: @gep8(
112 ; CHECK-NEXT: [[A:%.*]] = getelementptr [[GEPT:%.*]], ptr [[X:%.*]], i32 1
113 ; CHECK-NEXT: [[B:%.*]] = getelementptr [[GEPT]], ptr [[X]], i32 -1
114 ; CHECK-NEXT: [[EQUAL:%.*]] = icmp ugt ptr [[A]], [[B]]
115 ; CHECK-NEXT: ret i1 [[EQUAL]]
117 %a = getelementptr %gept, ptr %x, i32 1
118 %b = getelementptr %gept, ptr %x, i32 -1
119 %equal = icmp ugt ptr %a, %b
123 define i1 @gep9(ptr %ptr) {
124 ; CHECK-LABEL: @gep9(
126 ; CHECK-NEXT: ret i1 true
129 %first2 = getelementptr inbounds i8, ptr %ptr, i32 1
130 %first3 = getelementptr inbounds i8, ptr %first2, i32 2
131 %first4 = getelementptr inbounds i8, ptr %first3, i32 4
132 %last1 = getelementptr inbounds i8, ptr %first2, i32 48
133 %last2 = getelementptr inbounds i8, ptr %last1, i32 8
134 %last3 = getelementptr inbounds i8, ptr %last2, i32 -4
135 %last4 = getelementptr inbounds i8, ptr %last3, i32 -4
136 %first.int = ptrtoint ptr %first4 to i32
137 %last.int = ptrtoint ptr %last4 to i32
138 %cmp = icmp ne i32 %last.int, %first.int
142 define i1 @gep10(ptr %ptr) {
143 ; CHECK-LABEL: @gep10(
145 ; CHECK-NEXT: ret i1 true
148 %first1 = getelementptr inbounds i8, ptr %ptr, i32 -2
149 %first2 = getelementptr inbounds i8, ptr %first1, i32 44
150 %last1 = getelementptr inbounds i8, ptr %ptr, i32 48
151 %last2 = getelementptr inbounds i8, ptr %last1, i32 -6
152 %first.int = ptrtoint ptr %first2 to i32
153 %last.int = ptrtoint ptr %last2 to i32
154 %cmp = icmp eq i32 %last.int, %first.int
158 define i1 @gep11(ptr %ptr) {
159 ; CHECK-LABEL: @gep11(
161 ; CHECK-NEXT: ret i1 true
164 %first1 = getelementptr inbounds i8, ptr %ptr, i32 -2
165 %last1 = getelementptr inbounds i8, ptr %ptr, i32 48
166 %last2 = getelementptr inbounds i8, ptr %last1, i32 -6
167 %cmp = icmp ult ptr %first1, %last2
171 define i1 @gep12(ptr %ptr) {
172 ; CHECK-LABEL: @gep12(
174 ; CHECK-NEXT: [[FIRST1:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i32 -2
175 ; CHECK-NEXT: [[LAST1:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i32 48
176 ; CHECK-NEXT: [[LAST2:%.*]] = getelementptr inbounds i8, ptr [[LAST1]], i32 -6
177 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt ptr [[FIRST1]], [[LAST2]]
178 ; CHECK-NEXT: ret i1 [[CMP]]
181 %first1 = getelementptr inbounds i8, ptr %ptr, i32 -2
182 %last1 = getelementptr inbounds i8, ptr %ptr, i32 48
183 %last2 = getelementptr inbounds i8, ptr %last1, i32 -6
184 %cmp = icmp slt ptr %first1, %last2
188 define i1 @gep13(ptr %ptr) {
189 ; CHECK-LABEL: @gep13(
190 ; CHECK-NEXT: ret i1 false
192 ; We can prove this GEP is non-null because it is inbounds.
193 %x = getelementptr inbounds i8, ptr %ptr, i32 1
194 %cmp = icmp eq ptr %x, null
198 define i1 @gep13_no_null_opt(ptr %ptr) #0 {
199 ; We can't prove this GEP is non-null.
200 ; CHECK-LABEL: @gep13_no_null_opt(
201 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i32 1
202 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
203 ; CHECK-NEXT: ret i1 [[CMP]]
205 %x = getelementptr inbounds i8, ptr %ptr, i32 1
206 %cmp = icmp eq ptr %x, null
210 define i1 @gep14(ptr %ptr) {
211 ; CHECK-LABEL: @gep14(
212 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds { {}, i8 }, ptr [[PTR:%.*]], i32 0, i32 1
213 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
214 ; CHECK-NEXT: ret i1 [[CMP]]
216 ; We can't simplify this because the offset of one in the GEP actually doesn't
218 %x = getelementptr inbounds { {}, i8 }, ptr %ptr, i32 0, i32 1
219 %cmp = icmp eq ptr %x, null
223 define i1 @gep15(ptr %ptr, i32 %y) {
224 ; CHECK-LABEL: @gep15(
225 ; CHECK-NEXT: ret i1 false
227 ; We can prove this GEP is non-null even though there is a user value, as we
228 ; would necessarily violate inbounds on one side or the other.
229 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, ptr %ptr, i32 0, i32 1, i32 %y, i32 1
230 %cmp = icmp eq ptr %x, null
234 define i1 @gep15_no_null_opt(ptr %ptr, i32 %y) #0 {
235 ; We can't prove this GEP is non-null.
236 ; CHECK-LABEL: @gep15_no_null_opt(
237 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds { {}, [4 x { i8, i8 }] }, ptr [[PTR:%.*]], i32 0, i32 1, i32 [[Y:%.*]], i32 1
238 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
239 ; CHECK-NEXT: ret i1 [[CMP]]
241 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, ptr %ptr, i32 0, i32 1, i32 %y, i32 1
242 %cmp = icmp eq ptr %x, null
246 define i1 @gep16(ptr %ptr, i32 %a) {
247 ; CHECK-LABEL: @gep16(
248 ; CHECK-NEXT: ret i1 false
250 ; We can prove this GEP is non-null because it is inbounds and because we know
251 ; %b is non-zero even though we don't know its value.
253 %x = getelementptr inbounds i8, ptr %ptr, i32 %b
254 %cmp = icmp eq ptr %x, null
258 define i1 @gep16_no_null_opt(ptr %ptr, i32 %a) #0 {
259 ; We can't prove this GEP is non-null.
260 ; CHECK-LABEL: @gep16_no_null_opt(
261 ; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 1
262 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i32 [[B]]
263 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
264 ; CHECK-NEXT: ret i1 [[CMP]]
267 %x = getelementptr inbounds i8, ptr %ptr, i32 %b
268 %cmp = icmp eq ptr %x, null
273 ; CHECK-LABEL: @gep17(
274 ; CHECK-NEXT: ret i1 true
276 %alloca = alloca i32, align 4
277 %gep1 = getelementptr inbounds i32, ptr %alloca, i32 1
278 %pti1 = ptrtoint ptr %gep1 to i32
279 %gep2 = getelementptr inbounds [4 x i8], ptr %alloca, i32 0, i32 1
280 %pti2 = ptrtoint ptr %gep2 to i32
281 %cmp = icmp ugt i32 %pti1, %pti2
285 ; Negative test: GEP inbounds may cross sign boundary.
286 define i1 @gep_same_base_constant_indices(ptr %a) {
287 ; CHECK-LABEL: @gep_same_base_constant_indices(
288 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i64 1
289 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 10
290 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt ptr [[ARRAYIDX1]], [[ARRAYIDX2]]
291 ; CHECK-NEXT: ret i1 [[CMP]]
293 %arrayidx1 = getelementptr inbounds i8, ptr %a, i64 1
294 %arrayidx2 = getelementptr inbounds i8, ptr %a, i64 10
295 %cmp = icmp slt ptr %arrayidx1, %arrayidx2
299 define i1 @zext(i32 %x) {
300 ; CHECK-LABEL: @zext(
301 ; CHECK-NEXT: ret i1 true
303 %e1 = zext i32 %x to i64
304 %e2 = zext i32 %x to i64
305 %r = icmp eq i64 %e1, %e2
309 define i1 @zext2(i1 %x) {
310 ; CHECK-LABEL: @zext2(
311 ; CHECK-NEXT: ret i1 [[X:%.*]]
313 %e = zext i1 %x to i32
314 %c = icmp ne i32 %e, 0
319 ; CHECK-LABEL: @zext3(
320 ; CHECK-NEXT: ret i1 true
322 %e = zext i1 1 to i32
323 %c = icmp ne i32 %e, 0
327 define i1 @sext(i32 %x) {
328 ; CHECK-LABEL: @sext(
329 ; CHECK-NEXT: ret i1 true
331 %e1 = sext i32 %x to i64
332 %e2 = sext i32 %x to i64
333 %r = icmp eq i64 %e1, %e2
337 define i1 @sext2(i1 %x) {
338 ; CHECK-LABEL: @sext2(
339 ; CHECK-NEXT: ret i1 [[X:%.*]]
341 %e = sext i1 %x to i32
342 %c = icmp ne i32 %e, 0
347 ; CHECK-LABEL: @sext3(
348 ; CHECK-NEXT: ret i1 true
350 %e = sext i1 1 to i32
351 %c = icmp ne i32 %e, 0
355 define i1 @add(i32 %x, i32 %y) {
357 ; CHECK-NEXT: ret i1 false
363 %c = icmp eq i32 %s, 0
367 define i1 @addv(<2 x i32> %x, <2 x i32> %y) {
368 ; CHECK-LABEL: @addv(
369 ; CHECK-NEXT: ret i1 false
371 %l = lshr <2 x i32> %x, <i32 1, i32 0>
372 %q = lshr <2 x i32> %y, <i32 1, i32 0>
373 %r = or <2 x i32> %q, <i32 1, i32 0>
374 %s = add <2 x i32> %l, %r
375 %e = extractelement <2 x i32> %s, i32 0
376 %c = icmp eq i32 %e, 0
380 define i1 @add2(i8 %x, i8 %y) {
381 ; CHECK-LABEL: @add2(
382 ; CHECK-NEXT: ret i1 false
387 %c = icmp eq i8 %s, 0
391 define i1 @add2v(<2 x i8> %x, <2 x i8> %y) {
392 ; CHECK-LABEL: @add2v(
393 ; CHECK-NEXT: ret i1 false
395 %l = or <2 x i8> %x, <i8 0, i8 128>
396 %r = or <2 x i8> %y, <i8 0, i8 129>
397 %s = add <2 x i8> %l, %r
398 %e = extractelement <2 x i8> %s, i32 1
399 %c = icmp eq i8 %e, 0
403 define i1 @add3(i8 %x, i8 %y) {
404 ; CHECK-LABEL: @add3(
405 ; CHECK-NEXT: [[L:%.*]] = zext i8 [[X:%.*]] to i32
406 ; CHECK-NEXT: [[R:%.*]] = zext i8 [[Y:%.*]] to i32
407 ; CHECK-NEXT: [[S:%.*]] = add i32 [[L]], [[R]]
408 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[S]], 0
409 ; CHECK-NEXT: ret i1 [[C]]
411 %l = zext i8 %x to i32
412 %r = zext i8 %y to i32
414 %c = icmp eq i32 %s, 0
418 define i1 @add4(i32 %x, i32 %y) {
419 ; CHECK-LABEL: @add4(
420 ; CHECK-NEXT: ret i1 true
422 %z = add nsw i32 %y, 1
423 %s1 = add nsw i32 %x, %y
424 %s2 = add nsw i32 %x, %z
425 %c = icmp slt i32 %s1, %s2
429 define i1 @add5(i32 %x, i32 %y) {
430 ; CHECK-LABEL: @add5(
431 ; CHECK-NEXT: ret i1 true
433 %z = add nuw i32 %y, 1
434 %s1 = add nuw i32 %x, %z
435 %s2 = add nuw i32 %x, %y
436 %c = icmp ugt i32 %s1, %s2
440 define i1 @add6(i64 %A, i64 %B) {
441 ; CHECK-LABEL: @add6(
442 ; CHECK-NEXT: ret i1 true
446 %cmp = icmp eq i64 %s1, %s2
450 define i1 @addpowtwo(i32 %x, i32 %y) {
451 ; CHECK-LABEL: @addpowtwo(
452 ; CHECK-NEXT: ret i1 false
457 %c = icmp eq i32 %s, 0
461 define i1 @addpowtwov(<2 x i32> %x, <2 x i32> %y) {
462 ; CHECK-LABEL: @addpowtwov(
463 ; CHECK-NEXT: [[L:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 1, i32 0>
464 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i32> <i32 1, i32 0>, [[Y:%.*]]
465 ; CHECK-NEXT: [[S:%.*]] = add <2 x i32> [[L]], [[R]]
466 ; CHECK-NEXT: [[E:%.*]] = extractelement <2 x i32> [[S]], i32 0
467 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[E]], 0
468 ; CHECK-NEXT: ret i1 [[C]]
470 %l = lshr <2 x i32> %x, <i32 1, i32 0>
471 %r = shl <2 x i32> <i32 1, i32 0>, %y
472 %s = add <2 x i32> %l, %r
473 %e = extractelement <2 x i32> %s, i32 0
474 %c = icmp eq i32 %e, 0
478 define i1 @or(i32 %x) {
480 ; CHECK-NEXT: ret i1 false
483 %c = icmp eq i32 %o, 0
487 ; Do not simplify if we cannot guarantee that the ConstantExpr is a non-zero
489 @GV = common global ptr null
490 define i1 @or_constexp(i32 %x) {
491 ; CHECK-LABEL: @or_constexp(
493 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 ptrtoint (ptr @GV to i32), 32
494 ; CHECK-NEXT: [[O:%.*]] = or i32 [[X:%.*]], [[TMP0]]
495 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[O]], 0
496 ; CHECK-NEXT: ret i1 [[C]]
499 %0 = and i32 ptrtoint (ptr @GV to i32), 32
501 %c = icmp eq i32 %o, 0
505 define i1 @shl1(i32 %x) {
506 ; CHECK-LABEL: @shl1(
507 ; CHECK-NEXT: ret i1 false
510 %c = icmp eq i32 %s, 0
514 define i1 @lshr1(i32 %x) {
515 ; CHECK-LABEL: @lshr1(
516 ; CHECK-NEXT: ret i1 false
519 %c = icmp eq i32 %s, 0
523 define i1 @lshr3(i32 %x) {
524 ; CHECK-LABEL: @lshr3(
525 ; CHECK-NEXT: ret i1 true
528 %c = icmp eq i32 %s, 0
532 define i1 @lshr4(i32 %X, i32 %Y) {
533 ; CHECK-LABEL: @lshr4(
534 ; CHECK-NEXT: ret i1 true
537 %C = icmp ule i32 %A, %X
541 define i1 @lshr5(i32 %X, i32 %Y) {
542 ; CHECK-LABEL: @lshr5(
543 ; CHECK-NEXT: ret i1 false
546 %C = icmp ugt i32 %A, %X
550 define i1 @lshr6(i32 %X, i32 %Y) {
551 ; CHECK-LABEL: @lshr6(
552 ; CHECK-NEXT: ret i1 false
555 %C = icmp ult i32 %X, %A
559 define i1 @lshr7(i32 %X, i32 %Y) {
560 ; CHECK-LABEL: @lshr7(
561 ; CHECK-NEXT: ret i1 true
564 %C = icmp uge i32 %X, %A
568 define i1 @lshr_nonzero_eq(i32 %x) {
569 ; CHECK-LABEL: @lshr_nonzero_eq(
570 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
571 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
572 ; CHECK-NEXT: ret i1 false
574 %x_ne_0 = icmp ne i32 %x, 0
575 call void @llvm.assume(i1 %x_ne_0)
576 %lhs = lshr i32 %x, 1
577 %cmp = icmp eq i32 %lhs, %x
581 define i1 @lshr_nonzero_uge(i32 %x) {
582 ; CHECK-LABEL: @lshr_nonzero_uge(
583 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
584 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
585 ; CHECK-NEXT: ret i1 false
587 %x_ne_0 = icmp ne i32 %x, 0
588 call void @llvm.assume(i1 %x_ne_0)
589 %lhs = lshr i32 %x, 1
590 %cmp = icmp uge i32 %lhs, %x
594 define i1 @lshr_nonzero_ne(i32 %x) {
595 ; CHECK-LABEL: @lshr_nonzero_ne(
596 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
597 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
598 ; CHECK-NEXT: ret i1 true
600 %x_ne_0 = icmp ne i32 %x, 0
601 call void @llvm.assume(i1 %x_ne_0)
602 %lhs = lshr i32 %x, 1
603 %cmp = icmp ne i32 %lhs, %x
607 define i1 @lshr_nonzero_ult(i32 %x) {
608 ; CHECK-LABEL: @lshr_nonzero_ult(
609 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
610 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
611 ; CHECK-NEXT: ret i1 true
613 %x_ne_0 = icmp ne i32 %x, 0
614 call void @llvm.assume(i1 %x_ne_0)
615 %lhs = lshr i32 %x, 1
616 %cmp = icmp ult i32 %lhs, %x
620 ; Negative test - unknown shift amount
621 define i1 @lshr_nonzero_neg_unknown(i32 %x, i32 %c) {
622 ; CHECK-LABEL: @lshr_nonzero_neg_unknown(
623 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
624 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
625 ; CHECK-NEXT: [[LHS:%.*]] = lshr i32 [[X]], [[C:%.*]]
626 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
627 ; CHECK-NEXT: ret i1 [[CMP]]
629 %x_ne_0 = icmp ne i32 %x, 0
630 call void @llvm.assume(i1 %x_ne_0)
631 %lhs = lshr i32 %x, %c
632 %cmp = icmp ult i32 %lhs, %x
636 ; Negative test - x may be zero
637 define i1 @lshr_nonzero_neg_maybe_zero(i32 %x) {
638 ; CHECK-LABEL: @lshr_nonzero_neg_maybe_zero(
639 ; CHECK-NEXT: [[LHS:%.*]] = lshr i32 [[X:%.*]], 1
640 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
641 ; CHECK-NEXT: ret i1 [[CMP]]
643 %lhs = lshr i32 %x, 1
644 %cmp = icmp ult i32 %lhs, %x
648 ; Negative test - signed pred
649 define i1 @lshr_nonzero_neg_signed(i32 %x, i32 %c) {
650 ; CHECK-LABEL: @lshr_nonzero_neg_signed(
651 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
652 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
653 ; CHECK-NEXT: [[LHS:%.*]] = lshr i32 [[X]], 1
654 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[LHS]], [[X]]
655 ; CHECK-NEXT: ret i1 [[CMP]]
657 %x_ne_0 = icmp ne i32 %x, 0
658 call void @llvm.assume(i1 %x_ne_0)
659 %lhs = lshr i32 %x, 1
660 %cmp = icmp slt i32 %lhs, %x
664 define i1 @ashr1(i32 %x) {
665 ; CHECK-LABEL: @ashr1(
666 ; CHECK-NEXT: ret i1 false
669 %c = icmp eq i32 %s, 0
673 define i1 @ashr3(i32 %x) {
674 ; CHECK-LABEL: @ashr3(
675 ; CHECK-NEXT: ret i1 true
678 %c = icmp eq i32 %s, 0
682 define i1 @select1(i1 %cond) {
683 ; CHECK-LABEL: @select1(
684 ; CHECK-NEXT: ret i1 [[COND:%.*]]
686 %s = select i1 %cond, i32 1, i32 0
687 %c = icmp eq i32 %s, 1
691 define i1 @select2(i1 %cond) {
692 ; CHECK-LABEL: @select2(
693 ; CHECK-NEXT: ret i1 [[COND:%.*]]
695 %x = zext i1 %cond to i32
696 %s = select i1 %cond, i32 %x, i32 0
697 %c = icmp ne i32 %s, 0
701 define i1 @select3(i1 %cond) {
702 ; CHECK-LABEL: @select3(
703 ; CHECK-NEXT: ret i1 [[COND:%.*]]
705 %x = zext i1 %cond to i32
706 %s = select i1 %cond, i32 1, i32 %x
707 %c = icmp ne i32 %s, 0
711 define i1 @select4(i1 %cond) {
712 ; CHECK-LABEL: @select4(
713 ; CHECK-NEXT: ret i1 [[COND:%.*]]
715 %invert = xor i1 %cond, 1
716 %s = select i1 %invert, i32 0, i32 1
717 %c = icmp ne i32 %s, 0
721 define i1 @select5(i32 %x) {
722 ; CHECK-LABEL: @select5(
723 ; CHECK-NEXT: ret i1 false
725 %c = icmp eq i32 %x, 0
726 %s = select i1 %c, i32 1, i32 %x
727 %c2 = icmp eq i32 %s, 0
731 define i1 @select6(i32 %x) {
732 ; CHECK-LABEL: @select6(
733 ; CHECK-NEXT: ret i1 false
735 %c = icmp sgt i32 %x, 0
736 %s = select i1 %c, i32 %x, i32 4
737 %c2 = icmp eq i32 %s, 0
741 define i1 @urem1(i32 %X, i32 %Y) {
742 ; CHECK-LABEL: @urem1(
743 ; CHECK-NEXT: ret i1 true
746 %B = icmp ult i32 %A, %Y
750 define i1 @urem2(i32 %X, i32 %Y) {
751 ; CHECK-LABEL: @urem2(
752 ; CHECK-NEXT: ret i1 false
755 %B = icmp eq i32 %A, %Y
759 define i1 @urem4(i32 %X) {
760 ; CHECK-LABEL: @urem4(
761 ; CHECK-NEXT: [[A:%.*]] = urem i32 [[X:%.*]], 15
762 ; CHECK-NEXT: [[B:%.*]] = icmp ult i32 [[A]], 10
763 ; CHECK-NEXT: ret i1 [[B]]
766 %B = icmp ult i32 %A, 10
770 define i1 @urem5(i16 %X, i32 %Y) {
771 ; CHECK-LABEL: @urem5(
772 ; CHECK-NEXT: [[A:%.*]] = zext i16 [[X:%.*]] to i32
773 ; CHECK-NEXT: [[B:%.*]] = urem i32 [[A]], [[Y:%.*]]
774 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[B]], [[Y]]
775 ; CHECK-NEXT: ret i1 [[C]]
777 %A = zext i16 %X to i32
779 %C = icmp slt i32 %B, %Y
783 define i1 @urem6(i32 %X, i32 %Y) {
784 ; CHECK-LABEL: @urem6(
785 ; CHECK-NEXT: ret i1 true
788 %B = icmp ugt i32 %Y, %A
792 define i1 @urem7(i32 %X) {
793 ; CHECK-LABEL: @urem7(
794 ; CHECK-NEXT: [[A:%.*]] = urem i32 1, [[X:%.*]]
795 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 [[A]], [[X]]
796 ; CHECK-NEXT: ret i1 [[B]]
799 %B = icmp sgt i32 %A, %X
803 define i1 @urem8(i8 %X, i8 %Y) {
804 ; CHECK-LABEL: @urem8(
805 ; CHECK-NEXT: ret i1 true
808 %B = icmp ule i8 %A, %X
812 define i1 @urem9(i8 %X, i8 %Y) {
813 ; CHECK-LABEL: @urem9(
814 ; CHECK-NEXT: ret i1 false
817 %B = icmp ugt i8 %A, %X
821 define i1 @urem10(i8 %X, i8 %Y) {
822 ; CHECK-LABEL: @urem10(
823 ; CHECK-NEXT: ret i1 true
826 %B = icmp uge i8 %X, %A
830 define i1 @urem11(i8 %X, i8 %Y) {
831 ; CHECK-LABEL: @urem11(
832 ; CHECK-NEXT: ret i1 false
835 %B = icmp ult i8 %X, %A
840 define i1 @srem2(i16 %X, i32 %Y) {
841 ; CHECK-LABEL: @srem2(
842 ; CHECK-NEXT: ret i1 false
844 %A = zext i16 %X to i32
845 %B = add nsw i32 %A, 1
847 %D = icmp slt i32 %C, 0
851 define i1 @srem2v(<2 x i16> %X, <2 x i32> %Y) {
852 ; CHECK-LABEL: @srem2v(
853 ; CHECK-NEXT: ret i1 false
855 %A = zext <2 x i16> %X to <2 x i32>
856 %B = add nsw <2 x i32> %A, <i32 1, i32 0>
857 %C = srem <2 x i32> %B, %Y
858 %D = extractelement <2 x i32> %C, i32 0
859 %E = icmp slt i32 %D, 0
863 define i1 @srem3(i16 %X, i32 %Y) {
864 ; CHECK-LABEL: @srem3(
865 ; CHECK-NEXT: ret i1 false
867 %A = zext i16 %X to i32
868 %B = or i32 2147483648, %A
869 %C = sub nsw i32 1, %B
871 %E = icmp slt i32 %D, 0
875 define i1 @srem3v(<2 x i16> %X, <2 x i32> %Y) {
876 ; CHECK-LABEL: @srem3v(
877 ; CHECK-NEXT: ret i1 false
879 %A = zext <2 x i16> %X to <2 x i32>
880 %B = or <2 x i32> <i32 1, i32 2147483648>, %A
881 %C = sub nsw <2 x i32> <i32 0, i32 1>, %B
882 %D = srem <2 x i32> %C, %Y
883 %E = extractelement <2 x i32> %C, i32 1
884 %F = icmp slt i32 %E, 0
888 define i1 @udiv2(i32 %Z) {
889 ; CHECK-LABEL: @udiv2(
890 ; CHECK-NEXT: ret i1 true
892 %A = udiv exact i32 10, %Z
893 %B = udiv exact i32 20, %Z
894 %C = icmp ult i32 %A, %B
898 ; Exact sdiv and equality preds can simplify.
900 define i1 @sdiv_exact_equality(i32 %Z) {
901 ; CHECK-LABEL: @sdiv_exact_equality(
902 ; CHECK-NEXT: ret i1 false
904 %A = sdiv exact i32 10, %Z
905 %B = sdiv exact i32 20, %Z
906 %C = icmp eq i32 %A, %B
910 ; But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949
912 define i1 @sdiv_exact_not_equality(i32 %Z) {
913 ; CHECK-LABEL: @sdiv_exact_not_equality(
914 ; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 10, [[Z:%.*]]
915 ; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 20, [[Z]]
916 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]]
917 ; CHECK-NEXT: ret i1 [[C]]
919 %A = sdiv exact i32 10, %Z
920 %B = sdiv exact i32 20, %Z
921 %C = icmp ult i32 %A, %B
925 define i1 @udiv3(i32 %X, i32 %Y) {
926 ; CHECK-LABEL: @udiv3(
927 ; CHECK-NEXT: ret i1 false
930 %C = icmp ugt i32 %A, %X
934 define i1 @udiv4(i32 %X, i32 %Y) {
935 ; CHECK-LABEL: @udiv4(
936 ; CHECK-NEXT: ret i1 true
939 %C = icmp ule i32 %A, %X
944 define i1 @udiv6(i32 %X) nounwind {
945 ; CHECK-LABEL: @udiv6(
946 ; CHECK-NEXT: [[A:%.*]] = udiv i32 1, [[X:%.*]]
947 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[A]], 0
948 ; CHECK-NEXT: ret i1 [[C]]
951 %C = icmp eq i32 %A, 0
955 define i1 @udiv7(i32 %X, i32 %Y) {
956 ; CHECK-LABEL: @udiv7(
957 ; CHECK-NEXT: ret i1 false
960 %C = icmp ult i32 %X, %A
964 define i1 @udiv8(i32 %X, i32 %Y) {
965 ; CHECK-LABEL: @udiv8(
966 ; CHECK-NEXT: ret i1 true
969 %C = icmp uge i32 %X, %A
973 define i1 @udiv_nonzero_eq(i32 %x) {
974 ; CHECK-LABEL: @udiv_nonzero_eq(
975 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
976 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
977 ; CHECK-NEXT: ret i1 false
979 %x_ne_0 = icmp ne i32 %x, 0
980 call void @llvm.assume(i1 %x_ne_0)
981 %lhs = udiv i32 %x, 3
982 %cmp = icmp eq i32 %lhs, %x
986 define i1 @udiv_nonzero_uge(i32 %x) {
987 ; CHECK-LABEL: @udiv_nonzero_uge(
988 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
989 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
990 ; CHECK-NEXT: ret i1 false
992 %x_ne_0 = icmp ne i32 %x, 0
993 call void @llvm.assume(i1 %x_ne_0)
994 %lhs = udiv i32 %x, 3
995 %cmp = icmp uge i32 %lhs, %x
999 define i1 @udiv_nonzero_ne(i32 %x) {
1000 ; CHECK-LABEL: @udiv_nonzero_ne(
1001 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1002 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1003 ; CHECK-NEXT: ret i1 true
1005 %x_ne_0 = icmp ne i32 %x, 0
1006 call void @llvm.assume(i1 %x_ne_0)
1007 %lhs = udiv i32 %x, 3
1008 %cmp = icmp ne i32 %lhs, %x
1012 define i1 @udiv_nonzero_ult(i32 %x) {
1013 ; CHECK-LABEL: @udiv_nonzero_ult(
1014 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1015 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1016 ; CHECK-NEXT: ret i1 true
1018 %x_ne_0 = icmp ne i32 %x, 0
1019 call void @llvm.assume(i1 %x_ne_0)
1020 %lhs = udiv i32 %x, 3
1021 %cmp = icmp ult i32 %lhs, %x
1025 ; Negative test - unknown divisor
1026 define i1 @udiv_nonzero_neg_unknown(i32 %x, i32 %c) {
1027 ; CHECK-LABEL: @udiv_nonzero_neg_unknown(
1028 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1029 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1030 ; CHECK-NEXT: [[LHS:%.*]] = udiv i32 [[X]], [[C:%.*]]
1031 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
1032 ; CHECK-NEXT: ret i1 [[CMP]]
1034 %x_ne_0 = icmp ne i32 %x, 0
1035 call void @llvm.assume(i1 %x_ne_0)
1036 %lhs = udiv i32 %x, %c
1037 %cmp = icmp ult i32 %lhs, %x
1041 ; Negative test - x may be zero
1042 define i1 @udiv_nonzero_neg_maybe_zero(i32 %x) {
1043 ; CHECK-LABEL: @udiv_nonzero_neg_maybe_zero(
1044 ; CHECK-NEXT: [[LHS:%.*]] = udiv i32 [[X:%.*]], 3
1045 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
1046 ; CHECK-NEXT: ret i1 [[CMP]]
1048 %lhs = udiv i32 %x, 3
1049 %cmp = icmp ult i32 %lhs, %x
1053 ; Negative test - signed pred
1054 define i1 @udiv_nonzero_neg_signed(i32 %x) {
1055 ; CHECK-LABEL: @udiv_nonzero_neg_signed(
1056 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1057 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1058 ; CHECK-NEXT: [[LHS:%.*]] = udiv i32 [[X]], 3
1059 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[LHS]], [[X]]
1060 ; CHECK-NEXT: ret i1 [[CMP]]
1062 %x_ne_0 = icmp ne i32 %x, 0
1063 call void @llvm.assume(i1 %x_ne_0)
1064 %lhs = udiv i32 %x, 3
1065 %cmp = icmp slt i32 %lhs, %x
1069 ; Square of a non-zero number is non-zero if there is no overflow.
1070 define i1 @mul1(i32 %X) {
1071 ; CHECK-LABEL: @mul1(
1072 ; CHECK-NEXT: ret i1 false
1075 %M = mul nuw i32 %Y, %Y
1076 %C = icmp eq i32 %M, 0
1080 define i1 @mul1v(<2 x i32> %X) {
1081 ; CHECK-LABEL: @mul1v(
1082 ; CHECK-NEXT: ret i1 false
1084 %Y = or <2 x i32> %X, <i32 1, i32 0>
1085 %M = mul nuw <2 x i32> %Y, %Y
1086 %E = extractelement <2 x i32> %M, i32 0
1087 %C = icmp eq i32 %E, 0
1091 ; Square of a non-zero number is positive if there is no signed overflow.
1092 define i1 @mul2(i32 %X) {
1093 ; CHECK-LABEL: @mul2(
1094 ; CHECK-NEXT: ret i1 true
1097 %M = mul nsw i32 %Y, %Y
1098 %C = icmp sgt i32 %M, 0
1102 define i1 @mul2v(<2 x i32> %X) {
1103 ; CHECK-LABEL: @mul2v(
1104 ; CHECK-NEXT: ret i1 true
1106 %Y = or <2 x i32> %X, <i32 0, i32 1>
1107 %M = mul nsw <2 x i32> %Y, %Y
1108 %E = extractelement <2 x i32> %M, i32 1
1109 %C = icmp sgt i32 %E, 0
1113 ; Product of non-negative numbers is non-negative if there is no signed overflow.
1114 define i1 @mul3(i32 %X, i32 %Y) {
1115 ; CHECK-LABEL: @mul3(
1116 ; CHECK-NEXT: ret i1 true
1118 %XX = mul nsw i32 %X, %X
1119 %YY = mul nsw i32 %Y, %Y
1120 %M = mul nsw i32 %XX, %YY
1121 %C = icmp sge i32 %M, 0
1125 define <2 x i1> @mul3v(<2 x i32> %X, <2 x i32> %Y) {
1126 ; CHECK-LABEL: @mul3v(
1127 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1129 %XX = mul nsw <2 x i32> %X, %X
1130 %YY = mul nsw <2 x i32> %Y, %Y
1131 %M = mul nsw <2 x i32> %XX, %YY
1132 %C = icmp sge <2 x i32> %M, zeroinitializer
1136 define <2 x i1> @vectorselect1(<2 x i1> %cond) {
1137 ; CHECK-LABEL: @vectorselect1(
1138 ; CHECK-NEXT: ret <2 x i1> [[COND:%.*]]
1140 %invert = xor <2 x i1> %cond, <i1 1, i1 1>
1141 %s = select <2 x i1> %invert, <2 x i32> <i32 0, i32 0>, <2 x i32> <i32 1, i32 1>
1142 %c = icmp ne <2 x i32> %s, <i32 0, i32 0>
1147 define <2 x i1> @vectorselectcrash(i32 %arg1) {
1148 ; CHECK-LABEL: @vectorselectcrash(
1149 ; CHECK-NEXT: [[TOBOOL40:%.*]] = icmp ne i32 [[ARG1:%.*]], 0
1150 ; CHECK-NEXT: [[COND43:%.*]] = select i1 [[TOBOOL40]], <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1>
1151 ; CHECK-NEXT: [[CMP45:%.*]] = icmp ugt <2 x i16> [[COND43]], <i16 73, i16 21>
1152 ; CHECK-NEXT: ret <2 x i1> [[CMP45]]
1154 %tobool40 = icmp ne i32 %arg1, 0
1155 %cond43 = select i1 %tobool40, <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1>
1156 %cmp45 = icmp ugt <2 x i16> %cond43, <i16 73, i16 21>
1161 define i1 @alloca_compare(i64 %idx) {
1162 ; CHECK-LABEL: @alloca_compare(
1163 ; CHECK-NEXT: ret i1 false
1165 %sv = alloca { i32, i32, [124 x i32] }
1166 %1 = getelementptr inbounds { i32, i32, [124 x i32] }, ptr %sv, i32 0, i32 2, i64 %idx
1167 %2 = icmp eq ptr %1, null
1171 define i1 @alloca_compare_no_null_opt(i64 %idx) #0 {
1172 ; CHECK-LABEL: @alloca_compare_no_null_opt(
1173 ; CHECK-NEXT: [[SV:%.*]] = alloca { i32, i32, [124 x i32] }, align 8
1174 ; CHECK-NEXT: [[CMP:%.*]] = getelementptr inbounds { i32, i32, [124 x i32] }, ptr [[SV]], i32 0, i32 2, i64 [[IDX:%.*]]
1175 ; CHECK-NEXT: [[X:%.*]] = icmp eq ptr [[CMP]], null
1176 ; CHECK-NEXT: ret i1 [[X]]
1178 %sv = alloca { i32, i32, [124 x i32] }
1179 %cmp = getelementptr inbounds { i32, i32, [124 x i32] }, ptr %sv, i32 0, i32 2, i64 %idx
1180 %X = icmp eq ptr %cmp, null
1184 define i1 @infinite_gep() {
1185 ; CHECK-LABEL: @infinite_gep(
1186 ; CHECK-NEXT: ret i1 true
1187 ; CHECK: unreachableblock:
1188 ; CHECK-NEXT: [[X:%.*]] = getelementptr i32, ptr [[X]], i32 1
1189 ; CHECK-NEXT: [[Y:%.*]] = icmp eq ptr [[X]], null
1190 ; CHECK-NEXT: ret i1 [[Y]]
1195 %X = getelementptr i32, ptr%X, i32 1
1196 %Y = icmp eq ptr %X, null
1200 ; It's not valid to fold a comparison of an argument with an alloca, even though
1201 ; that's tempting. An argument can't *alias* an alloca, however the aliasing rule
1202 ; relies on restrictions against guessing an object's address and dereferencing.
1203 ; There are no restrictions against guessing an object's address and comparing.
1205 define i1 @alloca_argument_compare(ptr %arg) {
1206 ; CHECK-LABEL: @alloca_argument_compare(
1207 ; CHECK-NEXT: [[ALLOC:%.*]] = alloca i64, align 8
1208 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[ARG:%.*]], [[ALLOC]]
1209 ; CHECK-NEXT: ret i1 [[CMP]]
1212 %cmp = icmp eq ptr %arg, %alloc
1216 ; As above, but with the operands reversed.
1218 define i1 @alloca_argument_compare_swapped(ptr %arg) {
1219 ; CHECK-LABEL: @alloca_argument_compare_swapped(
1220 ; CHECK-NEXT: [[ALLOC:%.*]] = alloca i64, align 8
1221 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[ALLOC]], [[ARG:%.*]]
1222 ; CHECK-NEXT: ret i1 [[CMP]]
1225 %cmp = icmp eq ptr %alloc, %arg
1229 ; Don't assume that a noalias argument isn't equal to a global variable's
1230 ; address. This is an example where AliasAnalysis' NoAlias concept is
1231 ; different from actual pointer inequality.
1233 @y = external global i32
1234 define zeroext i1 @external_compare(ptr noalias %x) {
1235 ; CHECK-LABEL: @external_compare(
1236 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X:%.*]], @y
1237 ; CHECK-NEXT: ret i1 [[CMP]]
1239 %cmp = icmp eq ptr %x, @y
1243 define i1 @alloca_gep(i64 %a, i64 %b) {
1244 ; CHECK-LABEL: @alloca_gep(
1245 ; CHECK-NEXT: ret i1 false
1247 ; We can prove this GEP is non-null because it is inbounds and the pointer
1249 %strs = alloca [1000 x [1001 x i8]], align 16
1250 %x = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %a, i64 %b
1251 %cmp = icmp eq ptr %x, null
1255 define i1 @alloca_gep_no_null_opt(i64 %a, i64 %b) #0 {
1256 ; CHECK-LABEL: @alloca_gep_no_null_opt(
1257 ; CHECK-NEXT: [[STRS:%.*]] = alloca [1000 x [1001 x i8]], align 16
1258 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds [1000 x [1001 x i8]], ptr [[STRS]], i64 0, i64 [[A:%.*]], i64 [[B:%.*]]
1259 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
1260 ; CHECK-NEXT: ret i1 [[CMP]]
1262 ; We can't prove this GEP is non-null.
1263 %strs = alloca [1000 x [1001 x i8]], align 16
1264 %x = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %a, i64 %b
1265 %cmp = icmp eq ptr %x, null
1269 define i1 @non_inbounds_gep_compare(ptr %a) {
1270 ; CHECK-LABEL: @non_inbounds_gep_compare(
1271 ; CHECK-NEXT: ret i1 true
1273 ; Equality compares with non-inbounds GEPs can be folded.
1274 %x = getelementptr i64, ptr %a, i64 42
1275 %y = getelementptr inbounds i64, ptr %x, i64 -42
1276 %z = getelementptr i64, ptr %a, i64 -42
1277 %w = getelementptr inbounds i64, ptr %z, i64 42
1278 %cmp = icmp eq ptr %y, %w
1282 define i1 @non_inbounds_gep_compare2(ptr %a) {
1283 ; CHECK-LABEL: @non_inbounds_gep_compare2(
1284 ; CHECK-NEXT: ret i1 true
1286 ; Equality compares with non-inbounds GEPs can be folded.
1287 %x = getelementptr i64, ptr %a, i64 4294967297
1288 %y = getelementptr i64, ptr %a, i64 1
1289 %cmp = icmp eq ptr %y, %y
1293 define i1 @compare_always_true_slt(i16 %a) {
1294 ; CHECK-LABEL: @compare_always_true_slt(
1295 ; CHECK-NEXT: ret i1 true
1297 %t1 = zext i16 %a to i32
1298 %t2 = sub i32 0, %t1
1299 %t3 = icmp slt i32 %t2, 1
1303 define <2 x i1> @compare_always_true_slt_splat(<2 x i16> %a) {
1304 ; CHECK-LABEL: @compare_always_true_slt_splat(
1305 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1307 %t1 = zext <2 x i16> %a to <2 x i32>
1308 %t2 = sub <2 x i32> zeroinitializer, %t1
1309 %t3 = icmp slt <2 x i32> %t2, <i32 1, i32 1>
1313 define i1 @compare_always_true_sle(i16 %a) {
1314 ; CHECK-LABEL: @compare_always_true_sle(
1315 ; CHECK-NEXT: ret i1 true
1317 %t1 = zext i16 %a to i32
1318 %t2 = sub i32 0, %t1
1319 %t3 = icmp sle i32 %t2, 0
1323 define <2 x i1> @compare_always_true_sle_splat(<2 x i16> %a) {
1324 ; CHECK-LABEL: @compare_always_true_sle_splat(
1325 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1327 %t1 = zext <2 x i16> %a to <2 x i32>
1328 %t2 = sub <2 x i32> zeroinitializer, %t1
1329 %t3 = icmp sle <2 x i32> %t2, zeroinitializer
1333 define i1 @compare_always_false_sgt(i16 %a) {
1334 ; CHECK-LABEL: @compare_always_false_sgt(
1335 ; CHECK-NEXT: ret i1 false
1337 %t1 = zext i16 %a to i32
1338 %t2 = sub i32 0, %t1
1339 %t3 = icmp sgt i32 %t2, 0
1343 define <2 x i1> @compare_always_false_sgt_splat(<2 x i16> %a) {
1344 ; CHECK-LABEL: @compare_always_false_sgt_splat(
1345 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1347 %t1 = zext <2 x i16> %a to <2 x i32>
1348 %t2 = sub <2 x i32> zeroinitializer, %t1
1349 %t3 = icmp sgt <2 x i32> %t2, zeroinitializer
1353 define i1 @compare_always_false_sge(i16 %a) {
1354 ; CHECK-LABEL: @compare_always_false_sge(
1355 ; CHECK-NEXT: ret i1 false
1357 %t1 = zext i16 %a to i32
1358 %t2 = sub i32 0, %t1
1359 %t3 = icmp sge i32 %t2, 1
1363 define <2 x i1> @compare_always_false_sge_splat(<2 x i16> %a) {
1364 ; CHECK-LABEL: @compare_always_false_sge_splat(
1365 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1367 %t1 = zext <2 x i16> %a to <2 x i32>
1368 %t2 = sub <2 x i32> zeroinitializer, %t1
1369 %t3 = icmp sge <2 x i32> %t2, <i32 1, i32 1>
1373 define i1 @compare_always_false_eq(i16 %a) {
1374 ; CHECK-LABEL: @compare_always_false_eq(
1375 ; CHECK-NEXT: ret i1 false
1377 %t1 = zext i16 %a to i32
1378 %t2 = sub i32 0, %t1
1379 %t3 = icmp eq i32 %t2, 1
1383 define <2 x i1> @compare_always_false_eq_splat(<2 x i16> %a) {
1384 ; CHECK-LABEL: @compare_always_false_eq_splat(
1385 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1387 %t1 = zext <2 x i16> %a to <2 x i32>
1388 %t2 = sub <2 x i32> zeroinitializer, %t1
1389 %t3 = icmp eq <2 x i32> %t2, <i32 1, i32 1>
1393 define i1 @compare_always_true_ne(i16 %a) {
1394 ; CHECK-LABEL: @compare_always_true_ne(
1395 ; CHECK-NEXT: ret i1 true
1397 %t1 = zext i16 %a to i32
1398 %t2 = sub i32 0, %t1
1399 %t3 = icmp ne i32 %t2, 1
1403 define <2 x i1> @compare_always_true_ne_splat(<2 x i16> %a) {
1404 ; CHECK-LABEL: @compare_always_true_ne_splat(
1405 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1407 %t1 = zext <2 x i16> %a to <2 x i32>
1408 %t2 = sub <2 x i32> zeroinitializer, %t1
1409 %t3 = icmp ne <2 x i32> %t2, <i32 1, i32 1>
1413 define i1 @lshr_ugt_false(i32 %a) {
1414 ; CHECK-LABEL: @lshr_ugt_false(
1415 ; CHECK-NEXT: ret i1 false
1417 %shr = lshr i32 1, %a
1418 %cmp = icmp ugt i32 %shr, 1
1422 define i1 @nonnull_arg(ptr nonnull %i) {
1423 ; CHECK-LABEL: @nonnull_arg(
1424 ; CHECK-NEXT: ret i1 false
1426 %cmp = icmp eq ptr %i, null
1430 define i1 @nonnull_arg_no_null_opt(ptr nonnull %i) #0 {
1431 ; CHECK-LABEL: @nonnull_arg_no_null_opt(
1432 ; CHECK-NEXT: ret i1 false
1434 %cmp = icmp eq ptr %i, null
1438 define i1 @nonnull_deref_arg(ptr dereferenceable(4) %i) {
1439 ; CHECK-LABEL: @nonnull_deref_arg(
1440 ; CHECK-NEXT: ret i1 false
1442 %cmp = icmp eq ptr %i, null
1446 define i1 @nonnull_deref_arg_no_null_opt(ptr dereferenceable(4) %i) #0 {
1447 ; CHECK-LABEL: @nonnull_deref_arg_no_null_opt(
1448 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[I:%.*]], null
1449 ; CHECK-NEXT: ret i1 [[CMP]]
1451 %cmp = icmp eq ptr %i, null
1454 define i1 @nonnull_deref_as_arg(ptr addrspace(1) dereferenceable(4) %i) {
1455 ; CHECK-LABEL: @nonnull_deref_as_arg(
1456 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(1) [[I:%.*]], null
1457 ; CHECK-NEXT: ret i1 [[CMP]]
1459 %cmp = icmp eq ptr addrspace(1) %i, null
1463 declare nonnull ptr @returns_nonnull_helper()
1464 define i1 @returns_nonnull() {
1465 ; CHECK-LABEL: @returns_nonnull(
1466 ; CHECK-NEXT: [[CALL:%.*]] = call nonnull ptr @returns_nonnull_helper()
1467 ; CHECK-NEXT: ret i1 false
1469 %call = call nonnull ptr @returns_nonnull_helper()
1470 %cmp = icmp eq ptr %call, null
1474 declare dereferenceable(4) ptr @returns_nonnull_deref_helper()
1475 define i1 @returns_nonnull_deref() {
1476 ; CHECK-LABEL: @returns_nonnull_deref(
1477 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1478 ; CHECK-NEXT: ret i1 false
1480 %call = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1481 %cmp = icmp eq ptr %call, null
1485 define i1 @returns_nonnull_deref_no_null_opt () #0 {
1486 ; CHECK-LABEL: @returns_nonnull_deref_no_null_opt(
1487 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1488 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[CALL]], null
1489 ; CHECK-NEXT: ret i1 [[CMP]]
1491 %call = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1492 %cmp = icmp eq ptr %call, null
1496 declare dereferenceable(4) ptr addrspace(1) @returns_nonnull_deref_as_helper()
1497 define i1 @returns_nonnull_as_deref() {
1498 ; CHECK-LABEL: @returns_nonnull_as_deref(
1499 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) ptr addrspace(1) @returns_nonnull_deref_as_helper()
1500 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(1) [[CALL]], null
1501 ; CHECK-NEXT: ret i1 [[CMP]]
1503 %call = call dereferenceable(4) ptr addrspace(1) @returns_nonnull_deref_as_helper()
1504 %cmp = icmp eq ptr addrspace(1) %call, null
1508 define i1 @nonnull_load(ptr %addr) {
1509 ; CHECK-LABEL: @nonnull_load(
1510 ; CHECK-NEXT: ret i1 false
1512 %ptr = load ptr, ptr %addr, !nonnull !{}
1513 %cmp = icmp eq ptr %ptr, null
1517 define i1 @nonnull_load_as_outer(ptr addrspace(1) %addr) {
1518 ; CHECK-LABEL: @nonnull_load_as_outer(
1519 ; CHECK-NEXT: ret i1 false
1521 %ptr = load ptr, ptr addrspace(1) %addr, !nonnull !{}
1522 %cmp = icmp eq ptr %ptr, null
1525 define i1 @nonnull_load_as_inner(ptr %addr) {
1526 ; CHECK-LABEL: @nonnull_load_as_inner(
1527 ; CHECK-NEXT: ret i1 false
1529 %ptr = load ptr addrspace(1), ptr %addr, !nonnull !{}
1530 %cmp = icmp eq ptr addrspace(1) %ptr, null
1534 ; If a bit is known to be zero for A and known to be one for B,
1535 ; then A and B cannot be equal.
1536 define i1 @icmp_eq_const(i32 %a) {
1537 ; CHECK-LABEL: @icmp_eq_const(
1538 ; CHECK-NEXT: ret i1 false
1540 %b = mul nsw i32 %a, -2
1541 %c = icmp eq i32 %b, 1
1545 define <2 x i1> @icmp_eq_const_vec(<2 x i32> %a) {
1546 ; CHECK-LABEL: @icmp_eq_const_vec(
1547 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1549 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2>
1550 %c = icmp eq <2 x i32> %b, <i32 1, i32 1>
1554 define i1 @icmp_ne_const(i32 %a) {
1555 ; CHECK-LABEL: @icmp_ne_const(
1556 ; CHECK-NEXT: ret i1 true
1558 %b = mul nsw i32 %a, -2
1559 %c = icmp ne i32 %b, 1
1563 define <2 x i1> @icmp_ne_const_vec(<2 x i32> %a) {
1564 ; CHECK-LABEL: @icmp_ne_const_vec(
1565 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1567 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2>
1568 %c = icmp ne <2 x i32> %b, <i32 1, i32 1>
1572 define i1 @icmp_sdiv_int_min(i32 %a) {
1573 ; CHECK-LABEL: @icmp_sdiv_int_min(
1574 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 -2147483648, [[A:%.*]]
1575 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[DIV]], -1073741824
1576 ; CHECK-NEXT: ret i1 [[CMP]]
1578 %div = sdiv i32 -2147483648, %a
1579 %cmp = icmp ne i32 %div, -1073741824
1584 define i1 @icmp_sdiv_pr20288(i64 %a) {
1585 ; CHECK-LABEL: @icmp_sdiv_pr20288(
1586 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 [[A:%.*]], -8589934592
1587 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824
1588 ; CHECK-NEXT: ret i1 [[CMP]]
1590 %div = sdiv i64 %a, -8589934592
1591 %cmp = icmp ne i64 %div, 1073741824
1596 define i1 @icmp_sdiv_neg1(i64 %a) {
1597 ; CHECK-LABEL: @icmp_sdiv_neg1(
1598 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 [[A:%.*]], -1
1599 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824
1600 ; CHECK-NEXT: ret i1 [[CMP]]
1602 %div = sdiv i64 %a, -1
1603 %cmp = icmp ne i64 %div, 1073741824
1608 define i1 @icmp_known_bits(i4 %x, i4 %y) {
1609 ; CHECK-LABEL: @icmp_known_bits(
1610 ; CHECK-NEXT: ret i1 false
1612 %and1 = and i4 %y, -7
1613 %and2 = and i4 %x, -7
1614 %or1 = or i4 %and1, 2
1615 %or2 = or i4 %and2, 2
1616 %add = add i4 %or1, %or2
1617 %cmp = icmp eq i4 %add, 0
1621 define i1 @icmp_known_bits_vec(<2 x i4> %x, <2 x i4> %y) {
1622 ; CHECK-LABEL: @icmp_known_bits_vec(
1623 ; CHECK-NEXT: ret i1 false
1625 %and1 = and <2 x i4> %y, <i4 -7, i4 -1>
1626 %and2 = and <2 x i4> %x, <i4 -7, i4 -1>
1627 %or1 = or <2 x i4> %and1, <i4 2, i4 2>
1628 %or2 = or <2 x i4> %and2, <i4 2, i4 2>
1629 %add = add <2 x i4> %or1, %or2
1630 %ext = extractelement <2 x i4> %add,i32 0
1631 %cmp = icmp eq i4 %ext, 0
1635 define i1 @icmp_shl_nuw_1(i64 %a) {
1636 ; CHECK-LABEL: @icmp_shl_nuw_1(
1637 ; CHECK-NEXT: ret i1 true
1639 %shl = shl nuw i64 1, %a
1640 %cmp = icmp ne i64 %shl, 0
1644 define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) {
1645 ; CHECK-LABEL: @icmp_shl_1_V_ugt_2147483648(
1646 ; CHECK-NEXT: ret i1 false
1648 %shl = shl i32 1, %V
1649 %cmp = icmp ugt i32 %shl, 2147483648
1653 define <2 x i1> @icmp_shl_1_ugt_signmask(<2 x i8> %V) {
1654 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask(
1655 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1657 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1658 %cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 128>
1662 define <2 x i1> @icmp_shl_1_ugt_signmask_undef(<2 x i8> %V) {
1663 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask_undef(
1664 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1666 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1667 %cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 undef>
1671 define <2 x i1> @icmp_shl_1_ugt_signmask_undef2(<2 x i8> %V) {
1672 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask_undef2(
1673 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1675 %shl = shl <2 x i8> <i8 1, i8 undef>, %V
1676 %cmp = icmp ugt <2 x i8> %shl, <i8 undef, i8 128>
1680 define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) {
1681 ; CHECK-LABEL: @icmp_shl_1_V_ule_2147483648(
1682 ; CHECK-NEXT: ret i1 true
1684 %shl = shl i32 1, %V
1685 %cmp = icmp ule i32 %shl, 2147483648
1689 define <2 x i1> @icmp_shl_1_ule_signmask(<2 x i8> %V) {
1690 ; CHECK-LABEL: @icmp_shl_1_ule_signmask(
1691 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1693 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1694 %cmp = icmp ule <2 x i8> %shl, <i8 128, i8 128>
1698 define <2 x i1> @icmp_shl_1_ule_signmask_undef(<2 x i8> %V) {
1699 ; CHECK-LABEL: @icmp_shl_1_ule_signmask_undef(
1700 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1702 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1703 %cmp = icmp ule <2 x i8> %shl, <i8 128, i8 undef>
1707 define <2 x i1> @icmp_shl_1_ule_signmask_undef2(<2 x i8> %V) {
1708 ; CHECK-LABEL: @icmp_shl_1_ule_signmask_undef2(
1709 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1711 %shl = shl <2 x i8> <i8 1, i8 undef>, %V
1712 %cmp = icmp ule <2 x i8> %shl, <i8 undef, i8 128>
1716 define i1 @shl_1_cmp_eq_nonpow2(i32 %x) {
1717 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2(
1718 ; CHECK-NEXT: ret i1 false
1721 %c = icmp eq i32 %s, 31
1725 define <2 x i1> @shl_1_cmp_eq_nonpow2_splat(<2 x i32> %x) {
1726 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2_splat(
1727 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1729 %s = shl <2 x i32> <i32 1, i32 1>, %x
1730 %c = icmp eq <2 x i32> %s, <i32 31, i32 31>
1734 define <2 x i1> @shl_1_cmp_eq_nonpow2_splat_undef(<2 x i32> %x) {
1735 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2_splat_undef(
1736 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1738 %s = shl <2 x i32> <i32 1, i32 1>, %x
1739 %c = icmp eq <2 x i32> %s, <i32 31, i32 undef>
1743 define i1 @shl_1_cmp_ne_nonpow2(i32 %x) {
1744 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2(
1745 ; CHECK-NEXT: ret i1 true
1748 %c = icmp ne i32 %s, 42
1752 define <2 x i1> @shl_1_cmp_ne_nonpow2_splat(<2 x i32> %x) {
1753 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2_splat(
1754 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1756 %s = shl <2 x i32> <i32 1, i32 1>, %x
1757 %c = icmp ne <2 x i32> %s, <i32 42, i32 42>
1761 define <2 x i1> @shl_1_cmp_ne_nonpow2_splat_undef(<2 x i32> %x) {
1762 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2_splat_undef(
1763 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1765 %s = shl <2 x i32> <i32 undef, i32 1>, %x
1766 %c = icmp ne <2 x i32> %s, <i32 42, i32 undef>
1770 define i1 @shl_pow2_cmp_eq_nonpow2(i32 %x) {
1771 ; CHECK-LABEL: @shl_pow2_cmp_eq_nonpow2(
1772 ; CHECK-NEXT: ret i1 false
1775 %c = icmp eq i32 %s, 31
1779 define <2 x i1> @shl_pow21_cmp_ne_nonpow2_splat_undef(<2 x i32> %x) {
1780 ; CHECK-LABEL: @shl_pow21_cmp_ne_nonpow2_splat_undef(
1781 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1783 %s = shl <2 x i32> <i32 undef, i32 4>, %x
1784 %c = icmp ne <2 x i32> %s, <i32 31, i32 undef>
1788 ; Negative test - overflowing shift could be zero.
1790 define i1 @shl_pow2_cmp_ne_zero(i32 %x) {
1791 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero(
1792 ; CHECK-NEXT: [[S:%.*]] = shl i32 16, [[X:%.*]]
1793 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[S]], 0
1794 ; CHECK-NEXT: ret i1 [[C]]
1797 %c = icmp ne i32 %s, 0
1801 ; Negative test - overflowing shift could be zero.
1803 define <2 x i1> @shl_pow2_cmp_ne_zero_splat(<2 x i32> %x) {
1804 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_splat(
1805 ; CHECK-NEXT: [[S:%.*]] = shl <2 x i32> <i32 16, i32 16>, [[X:%.*]]
1806 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[S]], zeroinitializer
1807 ; CHECK-NEXT: ret <2 x i1> [[C]]
1809 %s = shl <2 x i32> <i32 16, i32 16>, %x
1810 %c = icmp ne <2 x i32> %s, zeroinitializer
1814 define i1 @shl_pow2_cmp_eq_zero_nuw(i32 %x) {
1815 ; CHECK-LABEL: @shl_pow2_cmp_eq_zero_nuw(
1816 ; CHECK-NEXT: ret i1 false
1818 %s = shl nuw i32 16, %x
1819 %c = icmp eq i32 %s, 0
1823 define <2 x i1> @shl_pow2_cmp_ne_zero_nuw_splat_undef(<2 x i32> %x) {
1824 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_nuw_splat_undef(
1825 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1827 %s = shl nuw <2 x i32> <i32 16, i32 undef>, %x
1828 %c = icmp ne <2 x i32> %s, <i32 undef, i32 0>
1832 define i1 @shl_pow2_cmp_ne_zero_nsw(i32 %x) {
1833 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_nsw(
1834 ; CHECK-NEXT: ret i1 true
1836 %s = shl nsw i32 16, %x
1837 %c = icmp ne i32 %s, 0
1841 define <2 x i1> @shl_pow2_cmp_eq_zero_nsw_splat_undef(<2 x i32> %x) {
1842 ; CHECK-LABEL: @shl_pow2_cmp_eq_zero_nsw_splat_undef(
1843 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1845 %s = shl nsw <2 x i32> <i32 undef, i32 16>, %x
1846 %c = icmp eq <2 x i32> %s, <i32 0, i32 undef>
1850 define i1 @tautological1(i32 %A, i32 %B) {
1851 ; CHECK-LABEL: @tautological1(
1852 ; CHECK-NEXT: ret i1 false
1855 %D = icmp ugt i32 %C, %A
1859 define i1 @tautological2(i32 %A, i32 %B) {
1860 ; CHECK-LABEL: @tautological2(
1861 ; CHECK-NEXT: ret i1 true
1864 %D = icmp ule i32 %C, %A
1868 define i1 @tautological3(i32 %A, i32 %B) {
1869 ; CHECK-LABEL: @tautological3(
1870 ; CHECK-NEXT: ret i1 true
1873 %D = icmp ule i32 %A, %C
1877 define i1 @tautological4(i32 %A, i32 %B) {
1878 ; CHECK-LABEL: @tautological4(
1879 ; CHECK-NEXT: ret i1 false
1882 %D = icmp ugt i32 %A, %C
1886 define i1 @tautological5(i32 %A, i32 %B) {
1887 ; CHECK-LABEL: @tautological5(
1888 ; CHECK-NEXT: ret i1 false
1891 %D = icmp ult i32 %C, %A
1895 define i1 @tautological6(i32 %A, i32 %B) {
1896 ; CHECK-LABEL: @tautological6(
1897 ; CHECK-NEXT: ret i1 true
1900 %D = icmp uge i32 %C, %A
1904 define i1 @tautological7(i32 %A, i32 %B) {
1905 ; CHECK-LABEL: @tautological7(
1906 ; CHECK-NEXT: ret i1 true
1909 %D = icmp uge i32 %A, %C
1913 define i1 @tautological8(i32 %A, i32 %B) {
1914 ; CHECK-LABEL: @tautological8(
1915 ; CHECK-NEXT: ret i1 false
1918 %D = icmp ult i32 %A, %C
1922 define i1 @tautological9(i32 %A) {
1923 ; CHECK-LABEL: @tautological9(
1924 ; CHECK-NEXT: ret i1 false
1928 %D = icmp ugt i32 %C1, %C2
1932 define <2 x i1> @tautological9_vec(<2 x i32> %A) {
1933 ; CHECK-LABEL: @tautological9_vec(
1934 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1936 %C1 = and <2 x i32> %A, <i32 1, i32 1>
1937 %C2 = and <2 x i32> %A, <i32 3, i32 3>
1938 %D = icmp ugt <2 x i32> %C1, %C2
1942 define i1 @tautological10(i32 %A) {
1943 ; CHECK-LABEL: @tautological10(
1944 ; CHECK-NEXT: ret i1 true
1948 %D = icmp ule i32 %C1, %C2
1952 define i1 @tautological11(i32 %A) {
1953 ; CHECK-LABEL: @tautological11(
1954 ; CHECK-NEXT: ret i1 true
1958 %D = icmp ule i32 %C1, %C2
1962 define i1 @tautological12(i32 %A) {
1963 ; CHECK-LABEL: @tautological12(
1964 ; CHECK-NEXT: ret i1 false
1968 %D = icmp ugt i32 %C1, %C2
1972 define i1 @tautological13(i32 %A) {
1973 ; CHECK-LABEL: @tautological13(
1974 ; CHECK-NEXT: ret i1 false
1978 %D = icmp ult i32 %C2, %C1
1982 define i1 @tautological14(i32 %A) {
1983 ; CHECK-LABEL: @tautological14(
1984 ; CHECK-NEXT: ret i1 true
1988 %D = icmp uge i32 %C2, %C1
1992 define i1 @tautological15(i32 %A) {
1993 ; CHECK-LABEL: @tautological15(
1994 ; CHECK-NEXT: ret i1 true
1998 %D = icmp uge i32 %C2, %C1
2002 define i1 @tautological16(i32 %A) {
2003 ; CHECK-LABEL: @tautological16(
2004 ; CHECK-NEXT: ret i1 false
2008 %D = icmp ult i32 %C2, %C1
2012 define i1 @tautological9_negative(i32 %A) {
2013 ; CHECK-LABEL: @tautological9_negative(
2014 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2015 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2016 ; CHECK-NEXT: [[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
2017 ; CHECK-NEXT: ret i1 [[D]]
2021 %D = icmp ugt i32 %C1, %C2
2025 define i1 @tautological10_negative(i32 %A) {
2026 ; CHECK-LABEL: @tautological10_negative(
2027 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2028 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2029 ; CHECK-NEXT: [[D:%.*]] = icmp ule i32 [[C1]], [[C2]]
2030 ; CHECK-NEXT: ret i1 [[D]]
2034 %D = icmp ule i32 %C1, %C2
2038 define i1 @tautological11_negative(i32 %A) {
2039 ; CHECK-LABEL: @tautological11_negative(
2040 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2041 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2042 ; CHECK-NEXT: [[D:%.*]] = icmp ule i32 [[C1]], [[C2]]
2043 ; CHECK-NEXT: ret i1 [[D]]
2047 %D = icmp ule i32 %C1, %C2
2051 define i1 @tautological12_negative(i32 %A) {
2052 ; CHECK-LABEL: @tautological12_negative(
2053 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2054 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2055 ; CHECK-NEXT: [[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
2056 ; CHECK-NEXT: ret i1 [[D]]
2060 %D = icmp ugt i32 %C1, %C2
2064 define i1 @tautological13_negative(i32 %A) {
2065 ; CHECK-LABEL: @tautological13_negative(
2066 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2067 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2068 ; CHECK-NEXT: [[D:%.*]] = icmp ult i32 [[C2]], [[C1]]
2069 ; CHECK-NEXT: ret i1 [[D]]
2073 %D = icmp ult i32 %C2, %C1
2077 define i1 @tautological14_negative(i32 %A) {
2078 ; CHECK-LABEL: @tautological14_negative(
2079 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2080 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2081 ; CHECK-NEXT: [[D:%.*]] = icmp uge i32 [[C2]], [[C1]]
2082 ; CHECK-NEXT: ret i1 [[D]]
2086 %D = icmp uge i32 %C2, %C1
2090 define i1 @tautological15_negative(i32 %A) {
2091 ; CHECK-LABEL: @tautological15_negative(
2092 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2093 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2094 ; CHECK-NEXT: [[D:%.*]] = icmp uge i32 [[C2]], [[C1]]
2095 ; CHECK-NEXT: ret i1 [[D]]
2099 %D = icmp uge i32 %C2, %C1
2103 define i1 @tautological16_negative(i32 %A) {
2104 ; CHECK-LABEL: @tautological16_negative(
2105 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2106 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2107 ; CHECK-NEXT: [[D:%.*]] = icmp ult i32 [[C2]], [[C1]]
2108 ; CHECK-NEXT: ret i1 [[D]]
2112 %D = icmp ult i32 %C2, %C1
2116 define i1 @tautological17_subset1(i32 %A) {
2117 ; CHECK-LABEL: @tautological17_subset1(
2118 ; CHECK-NEXT: ret i1 false
2122 %D = icmp sgt i32 %C1, %C2
2126 define i1 @tautological17_subset2(i32 %A) {
2127 ; CHECK-LABEL: @tautological17_subset2(
2128 ; CHECK-NEXT: ret i1 false
2130 %C1 = and i32 %A, -4
2131 %C2 = and i32 %A, -3
2132 %D = icmp sgt i32 %C1, %C2
2136 define i1 @tautological17_negative(i32 %A) {
2137 ; CHECK-LABEL: @tautological17_negative(
2138 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2139 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2140 ; CHECK-NEXT: [[D:%.*]] = icmp sgt i32 [[C1]], [[C2]]
2141 ; CHECK-NEXT: ret i1 [[D]]
2144 %C2 = and i32 %A, -3
2145 %D = icmp sgt i32 %C1, %C2
2149 define i1 @tautological18_subset1(i32 %A) {
2150 ; CHECK-LABEL: @tautological18_subset1(
2151 ; CHECK-NEXT: ret i1 true
2155 %D = icmp sle i32 %C1, %C2
2159 define i1 @tautological18_subset2(i32 %A) {
2160 ; CHECK-LABEL: @tautological18_subset2(
2161 ; CHECK-NEXT: ret i1 true
2163 %C1 = and i32 %A, -4
2164 %C2 = and i32 %A, -3
2165 %D = icmp sle i32 %C1, %C2
2169 define i1 @tautological18_negative(i32 %A) {
2170 ; CHECK-LABEL: @tautological18_negative(
2171 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2172 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2173 ; CHECK-NEXT: [[D:%.*]] = icmp sle i32 [[C1]], [[C2]]
2174 ; CHECK-NEXT: ret i1 [[D]]
2177 %C2 = and i32 %A, -3
2178 %D = icmp sle i32 %C1, %C2
2182 define i1 @tautological19_subset1(i32 %A) {
2183 ; CHECK-LABEL: @tautological19_subset1(
2184 ; CHECK-NEXT: ret i1 false
2188 %D = icmp sgt i32 %C1, %C2
2192 define i1 @tautological19_subset2(i32 %A) {
2193 ; CHECK-LABEL: @tautological19_subset2(
2194 ; CHECK-NEXT: ret i1 false
2196 %C1 = and i32 %A, -4
2197 %C2 = and i32 %A, -3
2198 %D = icmp sgt i32 %C1, %C2
2202 define i1 @tautological19_negative(i32 %A) {
2203 ; CHECK-LABEL: @tautological19_negative(
2204 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2205 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2206 ; CHECK-NEXT: [[D:%.*]] = icmp sgt i32 [[C1]], [[C2]]
2207 ; CHECK-NEXT: ret i1 [[D]]
2210 %C2 = and i32 %A, -3
2211 %D = icmp sgt i32 %C1, %C2
2215 define i1 @tautological20_subset1(i32 %A) {
2216 ; CHECK-LABEL: @tautological20_subset1(
2217 ; CHECK-NEXT: ret i1 true
2221 %D = icmp sle i32 %C1, %C2
2225 define i1 @tautological20_subset2(i32 %A) {
2226 ; CHECK-LABEL: @tautological20_subset2(
2227 ; CHECK-NEXT: ret i1 true
2229 %C1 = and i32 %A, -4
2230 %C2 = and i32 %A, -3
2231 %D = icmp sle i32 %C1, %C2
2235 define i1 @tautological20_negative(i32 %A) {
2236 ; CHECK-LABEL: @tautological20_negative(
2237 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2238 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2239 ; CHECK-NEXT: [[D:%.*]] = icmp sle i32 [[C1]], [[C2]]
2240 ; CHECK-NEXT: ret i1 [[D]]
2243 %C2 = and i32 %A, -3
2244 %D = icmp sle i32 %C1, %C2
2248 declare void @helper_i1(i1)
2249 ; Series of tests for icmp s[lt|ge] (or A, B), A and icmp s[gt|le] A, (or A, B)
2250 define void @icmp_slt_sge_or(i32 %Ax, i32 %Bx) {
2251 ; 'p' for positive, 'n' for negative, 'x' for potentially either.
2252 ; %D is 'icmp slt (or A, B), A'
2253 ; %E is 'icmp sge (or A, B), A' making it the not of %D
2254 ; %F is 'icmp sgt A, (or A, B)' making it the same as %D
2255 ; %G is 'icmp sle A, (or A, B)' making it the not of %D
2256 ; CHECK-LABEL: @icmp_slt_sge_or(
2257 ; CHECK-NEXT: [[APOS:%.*]] = and i32 [[AX:%.*]], 2147483647
2258 ; CHECK-NEXT: [[BNEG:%.*]] = or i32 [[BX:%.*]], -2147483648
2259 ; CHECK-NEXT: [[CPX:%.*]] = or i32 [[APOS]], [[BX]]
2260 ; CHECK-NEXT: [[DPX:%.*]] = icmp slt i32 [[CPX]], [[APOS]]
2261 ; CHECK-NEXT: [[EPX:%.*]] = icmp sge i32 [[CPX]], [[APOS]]
2262 ; CHECK-NEXT: [[FPX:%.*]] = icmp sgt i32 [[APOS]], [[CPX]]
2263 ; CHECK-NEXT: [[GPX:%.*]] = icmp sle i32 [[APOS]], [[CPX]]
2264 ; CHECK-NEXT: [[CXX:%.*]] = or i32 [[AX]], [[BX]]
2265 ; CHECK-NEXT: [[DXX:%.*]] = icmp slt i32 [[CXX]], [[AX]]
2266 ; CHECK-NEXT: [[EXX:%.*]] = icmp sge i32 [[CXX]], [[AX]]
2267 ; CHECK-NEXT: [[FXX:%.*]] = icmp sgt i32 [[AX]], [[CXX]]
2268 ; CHECK-NEXT: [[GXX:%.*]] = icmp sle i32 [[AX]], [[CXX]]
2269 ; CHECK-NEXT: [[CXN:%.*]] = or i32 [[AX]], [[BNEG]]
2270 ; CHECK-NEXT: [[DXN:%.*]] = icmp slt i32 [[CXN]], [[AX]]
2271 ; CHECK-NEXT: [[EXN:%.*]] = icmp sge i32 [[CXN]], [[AX]]
2272 ; CHECK-NEXT: [[FXN:%.*]] = icmp sgt i32 [[AX]], [[CXN]]
2273 ; CHECK-NEXT: [[GXN:%.*]] = icmp sle i32 [[AX]], [[CXN]]
2274 ; CHECK-NEXT: call void @helper_i1(i1 false)
2275 ; CHECK-NEXT: call void @helper_i1(i1 true)
2276 ; CHECK-NEXT: call void @helper_i1(i1 false)
2277 ; CHECK-NEXT: call void @helper_i1(i1 true)
2278 ; CHECK-NEXT: call void @helper_i1(i1 [[DPX]])
2279 ; CHECK-NEXT: call void @helper_i1(i1 [[EPX]])
2280 ; CHECK-NEXT: call void @helper_i1(i1 [[FPX]])
2281 ; CHECK-NEXT: call void @helper_i1(i1 [[GPX]])
2282 ; CHECK-NEXT: call void @helper_i1(i1 true)
2283 ; CHECK-NEXT: call void @helper_i1(i1 false)
2284 ; CHECK-NEXT: call void @helper_i1(i1 true)
2285 ; CHECK-NEXT: call void @helper_i1(i1 false)
2286 ; CHECK-NEXT: call void @helper_i1(i1 false)
2287 ; CHECK-NEXT: call void @helper_i1(i1 true)
2288 ; CHECK-NEXT: call void @helper_i1(i1 false)
2289 ; CHECK-NEXT: call void @helper_i1(i1 true)
2290 ; CHECK-NEXT: call void @helper_i1(i1 [[DXX]])
2291 ; CHECK-NEXT: call void @helper_i1(i1 [[EXX]])
2292 ; CHECK-NEXT: call void @helper_i1(i1 [[FXX]])
2293 ; CHECK-NEXT: call void @helper_i1(i1 [[GXX]])
2294 ; CHECK-NEXT: call void @helper_i1(i1 [[DXN]])
2295 ; CHECK-NEXT: call void @helper_i1(i1 [[EXN]])
2296 ; CHECK-NEXT: call void @helper_i1(i1 [[FXN]])
2297 ; CHECK-NEXT: call void @helper_i1(i1 [[GXN]])
2298 ; CHECK-NEXT: call void @helper_i1(i1 false)
2299 ; CHECK-NEXT: call void @helper_i1(i1 true)
2300 ; CHECK-NEXT: call void @helper_i1(i1 false)
2301 ; CHECK-NEXT: call void @helper_i1(i1 true)
2302 ; CHECK-NEXT: call void @helper_i1(i1 false)
2303 ; CHECK-NEXT: call void @helper_i1(i1 true)
2304 ; CHECK-NEXT: call void @helper_i1(i1 false)
2305 ; CHECK-NEXT: call void @helper_i1(i1 true)
2306 ; CHECK-NEXT: call void @helper_i1(i1 false)
2307 ; CHECK-NEXT: call void @helper_i1(i1 true)
2308 ; CHECK-NEXT: call void @helper_i1(i1 false)
2309 ; CHECK-NEXT: call void @helper_i1(i1 true)
2310 ; CHECK-NEXT: ret void
2312 %Aneg = or i32 %Ax, 2147483648
2313 %Apos = and i32 %Ax, 2147483647
2314 %Bneg = or i32 %Bx, 2147483648
2315 %Bpos = and i32 %Bx, 2147483647
2317 %Cpp = or i32 %Apos, %Bpos
2318 %Dpp = icmp slt i32 %Cpp, %Apos
2319 %Epp = icmp sge i32 %Cpp, %Apos
2320 %Fpp = icmp sgt i32 %Apos, %Cpp
2321 %Gpp = icmp sle i32 %Apos, %Cpp
2322 %Cpx = or i32 %Apos, %Bx
2323 %Dpx = icmp slt i32 %Cpx, %Apos
2324 %Epx = icmp sge i32 %Cpx, %Apos
2325 %Fpx = icmp sgt i32 %Apos, %Cpx
2326 %Gpx = icmp sle i32 %Apos, %Cpx
2327 %Cpn = or i32 %Apos, %Bneg
2328 %Dpn = icmp slt i32 %Cpn, %Apos
2329 %Epn = icmp sge i32 %Cpn, %Apos
2330 %Fpn = icmp sgt i32 %Apos, %Cpn
2331 %Gpn = icmp sle i32 %Apos, %Cpn
2333 %Cxp = or i32 %Ax, %Bpos
2334 %Dxp = icmp slt i32 %Cxp, %Ax
2335 %Exp = icmp sge i32 %Cxp, %Ax
2336 %Fxp = icmp sgt i32 %Ax, %Cxp
2337 %Gxp = icmp sle i32 %Ax, %Cxp
2338 %Cxx = or i32 %Ax, %Bx
2339 %Dxx = icmp slt i32 %Cxx, %Ax
2340 %Exx = icmp sge i32 %Cxx, %Ax
2341 %Fxx = icmp sgt i32 %Ax, %Cxx
2342 %Gxx = icmp sle i32 %Ax, %Cxx
2343 %Cxn = or i32 %Ax, %Bneg
2344 %Dxn = icmp slt i32 %Cxn, %Ax
2345 %Exn = icmp sge i32 %Cxn, %Ax
2346 %Fxn = icmp sgt i32 %Ax, %Cxn
2347 %Gxn = icmp sle i32 %Ax, %Cxn
2349 %Cnp = or i32 %Aneg, %Bpos
2350 %Dnp = icmp slt i32 %Cnp, %Aneg
2351 %Enp = icmp sge i32 %Cnp, %Aneg
2352 %Fnp = icmp sgt i32 %Aneg, %Cnp
2353 %Gnp = icmp sle i32 %Aneg, %Cnp
2354 %Cnx = or i32 %Aneg, %Bx
2355 %Dnx = icmp slt i32 %Cnx, %Aneg
2356 %Enx = icmp sge i32 %Cnx, %Aneg
2357 %Fnx = icmp sgt i32 %Aneg, %Cnx
2358 %Gnx = icmp sle i32 %Aneg, %Cnx
2359 %Cnn = or i32 %Aneg, %Bneg
2360 %Dnn = icmp slt i32 %Cnn, %Aneg
2361 %Enn = icmp sge i32 %Cnn, %Aneg
2362 %Fnn = icmp sgt i32 %Aneg, %Cnn
2363 %Gnn = icmp sle i32 %Aneg, %Cnn
2365 call void @helper_i1(i1 %Dpp)
2366 call void @helper_i1(i1 %Epp)
2367 call void @helper_i1(i1 %Fpp)
2368 call void @helper_i1(i1 %Gpp)
2369 call void @helper_i1(i1 %Dpx)
2370 call void @helper_i1(i1 %Epx)
2371 call void @helper_i1(i1 %Fpx)
2372 call void @helper_i1(i1 %Gpx)
2373 call void @helper_i1(i1 %Dpn)
2374 call void @helper_i1(i1 %Epn)
2375 call void @helper_i1(i1 %Fpn)
2376 call void @helper_i1(i1 %Gpn)
2377 call void @helper_i1(i1 %Dxp)
2378 call void @helper_i1(i1 %Exp)
2379 call void @helper_i1(i1 %Fxp)
2380 call void @helper_i1(i1 %Gxp)
2381 call void @helper_i1(i1 %Dxx)
2382 call void @helper_i1(i1 %Exx)
2383 call void @helper_i1(i1 %Fxx)
2384 call void @helper_i1(i1 %Gxx)
2385 call void @helper_i1(i1 %Dxn)
2386 call void @helper_i1(i1 %Exn)
2387 call void @helper_i1(i1 %Fxn)
2388 call void @helper_i1(i1 %Gxn)
2389 call void @helper_i1(i1 %Dnp)
2390 call void @helper_i1(i1 %Enp)
2391 call void @helper_i1(i1 %Fnp)
2392 call void @helper_i1(i1 %Gnp)
2393 call void @helper_i1(i1 %Dnx)
2394 call void @helper_i1(i1 %Enx)
2395 call void @helper_i1(i1 %Fnx)
2396 call void @helper_i1(i1 %Gnx)
2397 call void @helper_i1(i1 %Dnn)
2398 call void @helper_i1(i1 %Enn)
2399 call void @helper_i1(i1 %Fnn)
2400 call void @helper_i1(i1 %Gnn)
2404 define i1 @constant_fold_inttoptr_null() {
2405 ; CHECK-LABEL: @constant_fold_inttoptr_null(
2406 ; CHECK-NEXT: ret i1 false
2408 %x = icmp eq ptr inttoptr (i64 32 to ptr), null
2412 define i1 @constant_fold_null_inttoptr() {
2413 ; CHECK-LABEL: @constant_fold_null_inttoptr(
2414 ; CHECK-NEXT: ret i1 false
2416 %x = icmp eq ptr null, inttoptr (i64 32 to ptr)
2420 define i1 @cmp_through_addrspacecast(ptr addrspace(1) %p1) {
2421 ; CHECK-LABEL: @cmp_through_addrspacecast(
2422 ; CHECK-NEXT: ret i1 true
2424 %p0 = addrspacecast ptr addrspace(1) %p1 to ptr
2425 %p0.1 = getelementptr inbounds i32, ptr %p0, i64 1
2426 %cmp = icmp ne ptr %p0, %p0.1
2430 ; Test simplifications for: icmp (X+Y), (X+Z) -> icmp Y,Z
2431 ; Test the overflow check when the RHS has NSW set and constant Z is greater
2432 ; than Y, then we know X+Y also can't overflow.
2434 define i1 @icmp_nsw_1(i32 %V) {
2435 ; CHECK-LABEL: @icmp_nsw_1(
2436 ; CHECK-NEXT: ret i1 true
2438 %add5 = add i32 %V, 5
2439 %add6 = add nsw i32 %V, 6
2440 %s1 = sext i32 %add5 to i64
2441 %s2 = sext i32 %add6 to i64
2442 %cmp = icmp slt i64 %s1, %s2
2446 define i1 @icmp_nsw_2(i32 %V) {
2447 ; CHECK-LABEL: @icmp_nsw_2(
2448 ; CHECK-NEXT: ret i1 true
2450 %add5 = add i32 %V, 5
2451 %add6 = add nsw i32 %V, 6
2452 %cmp = icmp slt i32 %add5, %add6
2456 define i1 @icmp_nsw_commute(i32 %V) {
2457 ; CHECK-LABEL: @icmp_nsw_commute(
2458 ; CHECK-NEXT: ret i1 true
2460 %add5 = add i32 5, %V
2461 %add6 = add nsw i32 %V, 6
2462 %cmp = icmp slt i32 %add5, %add6
2466 define i1 @icmp_nsw_commute2(i32 %V) {
2467 ; CHECK-LABEL: @icmp_nsw_commute2(
2468 ; CHECK-NEXT: ret i1 true
2470 %add5 = add i32 %V, 5
2471 %add6 = add nsw i32 6, %V
2472 %cmp = icmp slt i32 %add5, %add6
2476 define i1 @icmp_nsw_commute3(i32 %V) {
2477 ; CHECK-LABEL: @icmp_nsw_commute3(
2478 ; CHECK-NEXT: ret i1 true
2480 %add5 = add i32 5, %V
2481 %add6 = add nsw i32 6, %V
2482 %cmp = icmp slt i32 %add5, %add6
2486 define i1 @icmp_nsw_22(i32 %V) {
2487 ; CHECK-LABEL: @icmp_nsw_22(
2488 ; CHECK-NEXT: ret i1 true
2490 %add5 = add nsw i32 %V, 5
2491 %add6 = add nsw i32 %V, 6
2492 %cmp = icmp slt i32 %add5, %add6
2496 define i1 @icmp_nsw_23(i32 %V) {
2497 ; CHECK-LABEL: @icmp_nsw_23(
2498 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2499 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 6
2500 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2501 ; CHECK-NEXT: ret i1 [[CMP]]
2503 %add5 = add nsw i32 %V, 5
2504 %add6 = add i32 %V, 6
2505 %cmp = icmp slt i32 %add5, %add6
2509 define i1 @icmp_nsw_false(i32 %V) {
2510 ; CHECK-LABEL: @icmp_nsw_false(
2511 ; CHECK-NEXT: ret i1 false
2513 %add5 = add nsw i32 %V, 6
2514 %add6 = add i32 %V, 5
2515 %cmp = icmp slt i32 %add5, %add6
2519 define i1 @icmp_nsw_false_2(i32 %V) {
2520 ; CHECK-LABEL: @icmp_nsw_false_2(
2521 ; CHECK-NEXT: ret i1 false
2523 %add5 = add nsw i32 %V, 6
2524 %add6 = add nsw i32 %V, 5
2525 %cmp = icmp slt i32 %add5, %add6
2529 define i1 @icmp_nsw_false_3(i32 %V) {
2530 ; CHECK-LABEL: @icmp_nsw_false_3(
2531 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2532 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 5
2533 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2534 ; CHECK-NEXT: ret i1 [[CMP]]
2536 %add5 = add nsw i32 %V, 5
2537 %add6 = add i32 %V, 5
2538 %cmp = icmp slt i32 %add5, %add6
2542 define i1 @icmp_nsw_false_4(i32 %V) {
2543 ; CHECK-LABEL: @icmp_nsw_false_4(
2544 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 6
2545 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 5
2546 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2547 ; CHECK-NEXT: ret i1 [[CMP]]
2549 %add5 = add i32 %V, 6
2550 %add6 = add nsw i32 %V, 5
2551 %cmp = icmp slt i32 %add5, %add6
2555 define i1 @icmp_nsw_false_5(i8 %V) {
2556 ; CHECK-LABEL: @icmp_nsw_false_5(
2557 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[V:%.*]], 121
2558 ; CHECK-NEXT: [[ADDNSW:%.*]] = add nsw i8 [[V]], -104
2559 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[ADD]], [[ADDNSW]]
2560 ; CHECK-NEXT: ret i1 [[CMP]]
2562 %add = add i8 %V, 121
2563 %addnsw = add nsw i8 %V, -104
2564 %cmp = icmp slt i8 %add, %addnsw
2568 define i1 @icmp_nsw_i8(i8 %V) {
2569 ; CHECK-LABEL: @icmp_nsw_i8(
2570 ; CHECK-NEXT: ret i1 true
2572 %add5 = add i8 %V, 5
2573 %add6 = add nsw i8 %V, 6
2574 %cmp = icmp slt i8 %add5, %add6
2578 define i1 @icmp_nsw_i16(i16 %V) {
2579 ; CHECK-LABEL: @icmp_nsw_i16(
2580 ; CHECK-NEXT: ret i1 true
2582 %add5 = add i16 %V, 0
2583 %add6 = add nsw i16 %V, 1
2584 %cmp = icmp slt i16 %add5, %add6
2588 define i1 @icmp_nsw_i64(i64 %V) {
2589 ; CHECK-LABEL: @icmp_nsw_i64(
2590 ; CHECK-NEXT: ret i1 true
2592 %add5 = add i64 %V, 5
2593 %add6 = add nsw i64 %V, 6
2594 %cmp = icmp slt i64 %add5, %add6
2598 define <4 x i1> @icmp_nsw_vec(<4 x i32> %V) {
2599 ; CHECK-LABEL: @icmp_nsw_vec(
2600 ; CHECK-NEXT: ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
2602 %add5 = add <4 x i32> %V, <i32 5, i32 5, i32 5, i32 5>
2603 %add6 = add nsw <4 x i32> %V, <i32 6, i32 6, i32 6, i32 6>
2604 %cmp = icmp slt <4 x i32> %add5, %add6
2608 define i1 @icmp_nsw_3(i32 %V) {
2609 ; CHECK-LABEL: @icmp_nsw_3(
2610 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2611 ; CHECK-NEXT: [[ADD5_2:%.*]] = add nsw i32 [[V]], 5
2612 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD5_2]]
2613 ; CHECK-NEXT: ret i1 [[CMP]]
2615 %add5 = add i32 %V, 5
2616 %add5_2 = add nsw i32 %V, 5
2617 %cmp = icmp slt i32 %add5, %add5_2
2621 define i1 @icmp_nsw_4(i32 %V) {
2622 ; CHECK-LABEL: @icmp_nsw_4(
2623 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2624 ; CHECK-NEXT: [[ADD4:%.*]] = add nsw i32 [[V]], 4
2625 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD4]]
2626 ; CHECK-NEXT: ret i1 [[CMP]]
2628 %add5 = add i32 %V, 5
2629 %add4 = add nsw i32 %V, 4
2630 %cmp = icmp slt i32 %add5, %add4
2634 define i1 @icmp_nsw_5(i32 %V) {
2635 ; CHECK-LABEL: @icmp_nsw_5(
2636 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2637 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 6
2638 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2639 ; CHECK-NEXT: ret i1 [[CMP]]
2641 %add5 = add nsw i32 %V, 5
2642 %add6 = add i32 %V, 6
2643 %cmp = icmp slt i32 %add5, %add6
2647 define i1 @icmp_nsw_7(i32 %V, i32 %arg) {
2648 ; CHECK-LABEL: @icmp_nsw_7(
2649 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2650 ; CHECK-NEXT: [[ADDARG:%.*]] = add nsw i32 [[V]], [[ARG:%.*]]
2651 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADDARG]]
2652 ; CHECK-NEXT: ret i1 [[CMP]]
2654 %add5 = add i32 %V, 5
2655 %addarg = add nsw i32 %V, %arg
2656 %cmp = icmp slt i32 %add5, %addarg
2660 define i1 @icmp_nsw_8(i32 %V, i32 %arg) {
2661 ; CHECK-LABEL: @icmp_nsw_8(
2662 ; CHECK-NEXT: [[ADDARG:%.*]] = add i32 [[V:%.*]], [[ARG:%.*]]
2663 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 5
2664 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADDARG]], [[ADD6]]
2665 ; CHECK-NEXT: ret i1 [[CMP]]
2667 %addarg = add i32 %V, %arg
2668 %add6 = add nsw i32 %V, 5
2669 %cmp = icmp slt i32 %addarg, %add6
2673 define i1 @icmp_nsw_9(i32 %V1, i32 %V2) {
2674 ; CHECK-LABEL: @icmp_nsw_9(
2675 ; CHECK-NEXT: [[ADD_V1:%.*]] = add i32 [[V1:%.*]], 5
2676 ; CHECK-NEXT: [[ADD_V2:%.*]] = add nsw i32 [[V2:%.*]], 6
2677 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD_V1]], [[ADD_V2]]
2678 ; CHECK-NEXT: ret i1 [[CMP]]
2680 %add_V1 = add i32 %V1, 5
2681 %add_V2 = add nsw i32 %V2, 6
2682 %cmp = icmp slt i32 %add_V1, %add_V2
2686 define i1 @icmp_nsw_10(i32 %V) {
2687 ; CHECK-LABEL: @icmp_nsw_10(
2688 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2689 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 6
2690 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[ADD6]], [[ADD5]]
2691 ; CHECK-NEXT: ret i1 [[CMP]]
2693 %add5 = add i32 %V, 5
2694 %add6 = add nsw i32 %V, 6
2695 %cmp = icmp sgt i32 %add6, %add5
2699 define i1 @icmp_nsw_11(i32 %V) {
2700 ; CHECK-LABEL: @icmp_nsw_11(
2701 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], -125
2702 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], -99
2703 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2704 ; CHECK-NEXT: ret i1 [[CMP]]
2706 %add5 = add i32 %V, -125
2707 %add6 = add nsw i32 %V, -99
2708 %cmp = icmp slt i32 %add5, %add6
2712 define i1 @icmp_nsw_nonpos(i32 %V) {
2713 ; CHECK-LABEL: @icmp_nsw_nonpos(
2714 ; CHECK-NEXT: ret i1 false
2716 %add5 = add i32 %V, 0
2717 %add6 = add nsw i32 %V, -1
2718 %cmp = icmp slt i32 %add5, %add6
2722 define i1 @icmp_nsw_nonpos2(i32 %V) {
2723 ; CHECK-LABEL: @icmp_nsw_nonpos2(
2724 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 1
2725 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[V]]
2726 ; CHECK-NEXT: ret i1 [[CMP]]
2728 %add5 = add i32 %V, 1
2729 %add6 = add nsw i32 %V, 0
2730 %cmp = icmp slt i32 %add5, %add6
2734 declare i11 @llvm.ctpop.i11(i11)
2735 declare i73 @llvm.ctpop.i73(i73)
2736 declare <2 x i13> @llvm.ctpop.v2i13(<2 x i13>)
2738 define i1 @ctpop_sgt_bitwidth(i11 %x) {
2739 ; CHECK-LABEL: @ctpop_sgt_bitwidth(
2740 ; CHECK-NEXT: ret i1 false
2742 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2743 %cmp = icmp sgt i11 %pop, 11
2747 define i1 @ctpop_sle_minus1(i11 %x) {
2748 ; CHECK-LABEL: @ctpop_sle_minus1(
2749 ; CHECK-NEXT: ret i1 false
2751 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2752 %cmp = icmp sle i11 %pop, -1
2756 define i1 @ctpop_ugt_bitwidth(i73 %x) {
2757 ; CHECK-LABEL: @ctpop_ugt_bitwidth(
2758 ; CHECK-NEXT: ret i1 false
2760 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2761 %cmp = icmp ugt i73 %pop, 73
2765 ; Negative test - does not simplify, but instcombine could reduce this.
2767 define i1 @ctpop_ugt_bitwidth_minus1(i73 %x) {
2768 ; CHECK-LABEL: @ctpop_ugt_bitwidth_minus1(
2769 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.ctpop.i73(i73 [[X:%.*]])
2770 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
2771 ; CHECK-NEXT: ret i1 [[CMP]]
2773 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2774 %cmp = icmp ugt i73 %pop, 72
2778 define <2 x i1> @ctpop_sgt_bitwidth_splat(<2 x i13> %x) {
2779 ; CHECK-LABEL: @ctpop_sgt_bitwidth_splat(
2780 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2782 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2783 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
2787 define i1 @ctpop_ult_plus1_bitwidth(i11 %x) {
2788 ; CHECK-LABEL: @ctpop_ult_plus1_bitwidth(
2789 ; CHECK-NEXT: ret i1 true
2791 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2792 %cmp = icmp ult i11 %pop, 12
2796 define i1 @ctpop_ne_big_bitwidth(i73 %x) {
2797 ; CHECK-LABEL: @ctpop_ne_big_bitwidth(
2798 ; CHECK-NEXT: ret i1 true
2800 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2801 %cmp = icmp ne i73 %pop, 75
2805 define <2 x i1> @ctpop_slt_bitwidth_plus1_splat(<2 x i13> %x) {
2806 ; CHECK-LABEL: @ctpop_slt_bitwidth_plus1_splat(
2807 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
2809 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2810 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
2814 ; Negative test - does not simplify, but instcombine could reduce this.
2816 define <2 x i1> @ctpop_slt_bitwidth_splat(<2 x i13> %x) {
2817 ; CHECK-LABEL: @ctpop_slt_bitwidth_splat(
2818 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> [[X:%.*]])
2819 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], <i13 13, i13 13>
2820 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2822 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2823 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
2827 declare i11 @llvm.ctlz.i11(i11)
2828 declare i73 @llvm.ctlz.i73(i73)
2829 declare <2 x i13> @llvm.ctlz.v2i13(<2 x i13>)
2831 define i1 @ctlz_sgt_bitwidth(i11 %x) {
2832 ; CHECK-LABEL: @ctlz_sgt_bitwidth(
2833 ; CHECK-NEXT: ret i1 false
2835 %pop = call i11 @llvm.ctlz.i11(i11 %x)
2836 %cmp = icmp sgt i11 %pop, 11
2840 define i1 @ctlz_sle_minus1(i11 %x) {
2841 ; CHECK-LABEL: @ctlz_sle_minus1(
2842 ; CHECK-NEXT: ret i1 false
2844 %pop = call i11 @llvm.ctlz.i11(i11 %x)
2845 %cmp = icmp sle i11 %pop, -1
2849 define i1 @ctlz_ugt_bitwidth(i73 %x) {
2850 ; CHECK-LABEL: @ctlz_ugt_bitwidth(
2851 ; CHECK-NEXT: ret i1 false
2853 %pop = call i73 @llvm.ctlz.i73(i73 %x)
2854 %cmp = icmp ugt i73 %pop, 73
2858 ; Negative test - does not simplify, but instcombine could reduce this.
2860 define i1 @ctlz_ugt_bitwidth_minus1(i73 %x) {
2861 ; CHECK-LABEL: @ctlz_ugt_bitwidth_minus1(
2862 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.ctlz.i73(i73 [[X:%.*]], i1 false)
2863 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
2864 ; CHECK-NEXT: ret i1 [[CMP]]
2866 %pop = call i73 @llvm.ctlz.i73(i73 %x)
2867 %cmp = icmp ugt i73 %pop, 72
2871 define <2 x i1> @ctlz_sgt_bitwidth_splat(<2 x i13> %x) {
2872 ; CHECK-LABEL: @ctlz_sgt_bitwidth_splat(
2873 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2875 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
2876 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
2880 define i1 @ctlz_ult_plus1_bitwidth(i11 %x) {
2881 ; CHECK-LABEL: @ctlz_ult_plus1_bitwidth(
2882 ; CHECK-NEXT: ret i1 true
2884 %pop = call i11 @llvm.ctlz.i11(i11 %x)
2885 %cmp = icmp ult i11 %pop, 12
2889 define i1 @ctlz_ne_big_bitwidth(i73 %x) {
2890 ; CHECK-LABEL: @ctlz_ne_big_bitwidth(
2891 ; CHECK-NEXT: ret i1 true
2893 %pop = call i73 @llvm.ctlz.i73(i73 %x)
2894 %cmp = icmp ne i73 %pop, 75
2898 define <2 x i1> @ctlz_slt_bitwidth_plus1_splat(<2 x i13> %x) {
2899 ; CHECK-LABEL: @ctlz_slt_bitwidth_plus1_splat(
2900 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
2902 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
2903 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
2907 ; Negative test - does not simplify, but instcombine could reduce this.
2909 define <2 x i1> @ctlz_slt_bitwidth_splat(<2 x i13> %x) {
2910 ; CHECK-LABEL: @ctlz_slt_bitwidth_splat(
2911 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> [[X:%.*]], i1 false)
2912 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], <i13 13, i13 13>
2913 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2915 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
2916 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
2920 declare i11 @llvm.cttz.i11(i11)
2921 declare i73 @llvm.cttz.i73(i73)
2922 declare <2 x i13> @llvm.cttz.v2i13(<2 x i13>)
2924 define i1 @cttz_sgt_bitwidth(i11 %x) {
2925 ; CHECK-LABEL: @cttz_sgt_bitwidth(
2926 ; CHECK-NEXT: ret i1 false
2928 %pop = call i11 @llvm.cttz.i11(i11 %x)
2929 %cmp = icmp sgt i11 %pop, 11
2933 define i1 @cttz_sle_minus1(i11 %x) {
2934 ; CHECK-LABEL: @cttz_sle_minus1(
2935 ; CHECK-NEXT: ret i1 false
2937 %pop = call i11 @llvm.cttz.i11(i11 %x)
2938 %cmp = icmp sle i11 %pop, -1
2942 define i1 @cttz_ugt_bitwidth(i73 %x) {
2943 ; CHECK-LABEL: @cttz_ugt_bitwidth(
2944 ; CHECK-NEXT: ret i1 false
2946 %pop = call i73 @llvm.cttz.i73(i73 %x)
2947 %cmp = icmp ugt i73 %pop, 73
2951 ; Negative test - does not simplify, but instcombine could reduce this.
2953 define i1 @cttz_ugt_bitwidth_minus1(i73 %x) {
2954 ; CHECK-LABEL: @cttz_ugt_bitwidth_minus1(
2955 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.cttz.i73(i73 [[X:%.*]], i1 false)
2956 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
2957 ; CHECK-NEXT: ret i1 [[CMP]]
2959 %pop = call i73 @llvm.cttz.i73(i73 %x)
2960 %cmp = icmp ugt i73 %pop, 72
2964 define <2 x i1> @cttz_sgt_bitwidth_splat(<2 x i13> %x) {
2965 ; CHECK-LABEL: @cttz_sgt_bitwidth_splat(
2966 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2968 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
2969 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
2973 define i1 @cttz_ult_plus1_bitwidth(i11 %x) {
2974 ; CHECK-LABEL: @cttz_ult_plus1_bitwidth(
2975 ; CHECK-NEXT: ret i1 true
2977 %pop = call i11 @llvm.cttz.i11(i11 %x)
2978 %cmp = icmp ult i11 %pop, 12
2982 define i1 @cttz_ne_big_bitwidth(i73 %x) {
2983 ; CHECK-LABEL: @cttz_ne_big_bitwidth(
2984 ; CHECK-NEXT: ret i1 true
2986 %pop = call i73 @llvm.cttz.i73(i73 %x)
2987 %cmp = icmp ne i73 %pop, 75
2991 define <2 x i1> @cttz_slt_bitwidth_plus1_splat(<2 x i13> %x) {
2992 ; CHECK-LABEL: @cttz_slt_bitwidth_plus1_splat(
2993 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
2995 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
2996 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
3000 ; Negative test - does not simplify, but instcombine could reduce this.
3002 define <2 x i1> @cttz_slt_bitwidth_splat(<2 x i13> %x) {
3003 ; CHECK-LABEL: @cttz_slt_bitwidth_splat(
3004 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> [[X:%.*]], i1 false)
3005 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], <i13 13, i13 13>
3006 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
3008 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
3009 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
3013 ; A zero sized alloca *can* be equal to another alloca
3014 define i1 @zero_sized_alloca1() {
3015 ; CHECK-LABEL: @zero_sized_alloca1(
3016 ; CHECK-NEXT: [[A:%.*]] = alloca i32, i32 0, align 4
3017 ; CHECK-NEXT: [[B:%.*]] = alloca i32, i32 0, align 4
3018 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A]], [[B]]
3019 ; CHECK-NEXT: ret i1 [[RES]]
3021 %a = alloca i32, i32 0
3022 %b = alloca i32, i32 0
3023 %res = icmp ne ptr %a, %b
3027 define i1 @zero_sized_alloca2() {
3028 ; CHECK-LABEL: @zero_sized_alloca2(
3029 ; CHECK-NEXT: [[A:%.*]] = alloca i32, i32 0, align 4
3030 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
3031 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A]], [[B]]
3032 ; CHECK-NEXT: ret i1 [[RES]]
3034 %a = alloca i32, i32 0
3036 %res = icmp ne ptr %a, %b
3040 define i1 @scalar_vectors_are_non_empty() {
3041 ; CHECK-LABEL: @scalar_vectors_are_non_empty(
3042 ; CHECK-NEXT: ret i1 true
3044 %a = alloca <vscale x 2 x i32>
3045 %b = alloca <vscale x 2 x i32>
3046 %res = icmp ne ptr %a, %b
3051 define i1 @byval_args_inequal(ptr byval(i32) %a, ptr byval(i32) %b) {
3052 ; CHECK-LABEL: @byval_args_inequal(
3053 ; CHECK-NEXT: ret i1 true
3055 %res = icmp ne ptr %a, %b
3059 ; Arguments can be adjacent on the stack
3060 define i1 @neg_args_adjacent(ptr byval(i32) %a, ptr byval(i32) %b) {
3061 ; CHECK-LABEL: @neg_args_adjacent(
3062 ; CHECK-NEXT: [[A_OFF:%.*]] = getelementptr i32, ptr [[A:%.*]], i32 1
3063 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A_OFF]], [[B:%.*]]
3064 ; CHECK-NEXT: ret i1 [[RES]]
3066 %a.off = getelementptr i32, ptr %a, i32 1
3067 %res = icmp ne ptr %a.off, %b
3072 define i1 @test_byval_alloca_inequal(ptr byval(i32) %a) {
3073 ; CHECK-LABEL: @test_byval_alloca_inequal(
3074 ; CHECK-NEXT: ret i1 true
3077 %res = icmp ne ptr %a, %b
3081 ; Byval argument can be immediately before alloca, and crossing
3083 define i1 @neg_byval_alloca_adjacent(ptr byval(i32) %a) {
3084 ; CHECK-LABEL: @neg_byval_alloca_adjacent(
3085 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
3086 ; CHECK-NEXT: [[A_OFF:%.*]] = getelementptr i32, ptr [[A:%.*]], i32 1
3087 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A_OFF]], [[B]]
3088 ; CHECK-NEXT: ret i1 [[RES]]
3091 %a.off = getelementptr i32, ptr %a, i32 1
3092 %res = icmp ne ptr %a.off, %b
3098 @A.alias = alias i32, ptr @A
3100 define i1 @globals_inequal() {
3101 ; CHECK-LABEL: @globals_inequal(
3102 ; CHECK-NEXT: ret i1 true
3104 %res = icmp ne ptr @A, @B
3109 define i1 @globals_offset_inequal() {
3110 ; CHECK-LABEL: @globals_offset_inequal(
3111 ; CHECK-NEXT: ret i1 icmp ne (ptr getelementptr (i8, ptr @A, i32 1), ptr getelementptr (i8, ptr @B, i32 1))
3113 %a.off = getelementptr i8, ptr @A, i32 1
3114 %b.off = getelementptr i8, ptr @B, i32 1
3115 %res = icmp ne ptr %a.off, %b.off
3121 define i1 @test_byval_global_inequal(ptr byval(i32) %a) {
3122 ; CHECK-LABEL: @test_byval_global_inequal(
3123 ; CHECK-NEXT: ret i1 true
3126 %res = icmp ne ptr %a, @B
3131 define i1 @neg_global_alias() {
3132 ; CHECK-LABEL: @neg_global_alias(
3133 ; CHECK-NEXT: ret i1 icmp ne (ptr @A, ptr @A.alias)
3135 %res = icmp ne ptr @A, @A.alias
3140 define i1 @icmp_lshr_known_non_zero_ult_true(i8 %x) {
3141 ; CHECK-LABEL: @icmp_lshr_known_non_zero_ult_true(
3142 ; CHECK-NEXT: ret i1 true
3145 %x1 = shl nuw i8 %or, 1
3146 %x2 = shl nuw i8 %or, 2
3147 %cmp = icmp ult i8 %x1, %x2
3151 define i1 @icmp_lshr_known_non_zero_ult_false(i8 %x) {
3152 ; CHECK-LABEL: @icmp_lshr_known_non_zero_ult_false(
3153 ; CHECK-NEXT: ret i1 false
3156 %x1 = shl nuw i8 %or, 1
3157 %x2 = shl nuw i8 %or, 2
3158 %cmp = icmp ugt i8 %x1, %x2
3162 define i1 @icmp_lshr_known_non_zero_slt_true(i8 %x) {
3163 ; CHECK-LABEL: @icmp_lshr_known_non_zero_slt_true(
3164 ; CHECK-NEXT: ret i1 true
3167 %x1 = shl nuw nsw i8 %or, 1
3168 %x2 = shl nuw nsw i8 %or, 2
3169 %cmp = icmp slt i8 %x1, %x2
3173 define i1 @icmp_lshr_known_non_zero_slt_false(i8 %x) {
3174 ; CHECK-LABEL: @icmp_lshr_known_non_zero_slt_false(
3175 ; CHECK-NEXT: ret i1 false
3178 %x1 = shl nuw nsw i8 %or, 2
3179 %x2 = shl nuw nsw i8 %or, 1
3180 %cmp = icmp slt i8 %x1, %x2
3184 define i1 @neg_icmp_lshr_known_non_zero_slt_no_nsw(i8 %x) {
3185 ; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_slt_no_nsw(
3186 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3187 ; CHECK-NEXT: [[X1:%.*]] = shl nuw i8 [[OR]], 1
3188 ; CHECK-NEXT: [[X2:%.*]] = shl nuw i8 [[OR]], 2
3189 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
3190 ; CHECK-NEXT: ret i1 [[CMP]]
3193 %x1 = shl nuw i8 %or, 1
3194 %x2 = shl nuw i8 %or, 2
3195 %cmp = icmp slt i8 %x1, %x2
3199 define i1 @neg_icmp_lshr_known_non_zero_ult_no_nuw(i8 %x) {
3200 ; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_ult_no_nuw(
3201 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3202 ; CHECK-NEXT: [[X1:%.*]] = shl i8 [[OR]], 1
3203 ; CHECK-NEXT: [[X2:%.*]] = shl i8 [[OR]], 2
3204 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X1]], [[X2]]
3205 ; CHECK-NEXT: ret i1 [[CMP]]
3210 %cmp = icmp ult i8 %x1, %x2
3214 define i1 @neg_icmp_lshr_known_non_zero_slt_no_nuw(i8 %x) {
3215 ; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_slt_no_nuw(
3216 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3217 ; CHECK-NEXT: [[X1:%.*]] = shl nsw i8 [[OR]], 1
3218 ; CHECK-NEXT: [[X2:%.*]] = shl nsw i8 [[OR]], 2
3219 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
3220 ; CHECK-NEXT: ret i1 [[CMP]]
3223 %x1 = shl nsw i8 %or, 1
3224 %x2 = shl nsw i8 %or, 2
3225 %cmp = icmp slt i8 %x1, %x2
3229 define i1 @neg_icmp_lshr_unknown_value(i8 %x) {
3230 ; CHECK-LABEL: @neg_icmp_lshr_unknown_value(
3231 ; CHECK-NEXT: [[X1:%.*]] = shl nuw i8 [[X:%.*]], 2
3232 ; CHECK-NEXT: [[X2:%.*]] = shl nuw i8 [[X]], 1
3233 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X1]], [[X2]]
3234 ; CHECK-NEXT: ret i1 [[CMP]]
3236 %x1 = shl nuw i8 %x, 2
3237 %x2 = shl nuw i8 %x, 1
3238 %cmp = icmp ugt i8 %x1, %x2
3242 define i1 @neg_icmp_lshr_unknown_shift(i8 %x, i8 %C1) {
3243 ; CHECK-LABEL: @neg_icmp_lshr_unknown_shift(
3244 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3245 ; CHECK-NEXT: [[X1:%.*]] = shl nuw i8 [[OR]], 2
3246 ; CHECK-NEXT: [[X2:%.*]] = shl nuw i8 [[OR]], [[C1:%.*]]
3247 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X1]], [[X2]]
3248 ; CHECK-NEXT: ret i1 [[CMP]]
3251 %x1 = shl nuw i8 %or, 2
3252 %x2 = shl nuw i8 %or, %C1
3253 %cmp = icmp ugt i8 %x1, %x2
3257 define i1 @neg_icmp_lshr_different_shift_values(i8 %x, i8 %y) {
3258 ; CHECK-LABEL: @neg_icmp_lshr_different_shift_values(
3259 ; CHECK-NEXT: [[X1:%.*]] = shl nuw nsw i8 [[X:%.*]], 1
3260 ; CHECK-NEXT: [[X2:%.*]] = shl nuw nsw i8 [[Y:%.*]], 2
3261 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X1]], [[X2]]
3262 ; CHECK-NEXT: ret i1 [[CMP]]
3264 %x1 = shl nuw nsw i8 %x, 1
3265 %x2 = shl nuw nsw i8 %y, 2
3266 %cmp = icmp ult i8 %x1, %x2
3270 define i1 @icmp_ult_vscale_true(i8 %x, i8 %y) {
3271 ; CHECK-LABEL: @icmp_ult_vscale_true(
3272 ; CHECK-NEXT: ret i1 true
3274 %vscale = call i64 @llvm.vscale.i64()
3275 %x1 = shl nuw nsw i64 %vscale, 1
3276 %x2 = shl nuw nsw i64 %vscale, 2
3277 %cmp = icmp ult i64 %x1, %x2
3281 define i1 @icmp_ult_vscale_false(i8 %x, i8 %y) {
3282 ; CHECK-LABEL: @icmp_ult_vscale_false(
3283 ; CHECK-NEXT: ret i1 false
3285 %vscale = call i64 @llvm.vscale.i64()
3286 %x1 = shl nuw nsw i64 %vscale, 1
3287 %x2 = shl nuw nsw i64 %vscale, 2
3288 %cmp = icmp ugt i64 %x1, %x2
3292 declare i64 @llvm.vscale.i64()
3294 ; TODO: Add coverage for global aliases, link once, etc..
3297 attributes #0 = { null_pointer_is_valid }