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 ; We can prove this GEP is non-null because it is nuw.
211 define i1 @gep_nuw_not_null(ptr %ptr) {
212 ; CHECK-LABEL: @gep_nuw_not_null(
213 ; CHECK-NEXT: ret i1 false
215 %x = getelementptr nuw i8, ptr %ptr, i32 1
216 %cmp = icmp eq ptr %x, null
220 ; Unlike the inbounds case, this holds even if the null pointer is valid.
221 define i1 @gep_nuw_null_pointer_valid(ptr %ptr) null_pointer_is_valid {
222 ; CHECK-LABEL: @gep_nuw_null_pointer_valid(
223 ; CHECK-NEXT: ret i1 false
225 %x = getelementptr nuw i8, ptr %ptr, i32 1
226 %cmp = icmp eq ptr %x, null
230 ; If the base pointer is non-null, the offset doesn't matter.
231 define i1 @gep_nuw_maybe_zero_offset(ptr nonnull %ptr, i32 %offset) {
232 ; CHECK-LABEL: @gep_nuw_maybe_zero_offset(
233 ; CHECK-NEXT: ret i1 false
235 %x = getelementptr nuw i8, ptr %ptr, i32 %offset
236 %cmp = icmp eq ptr %x, null
240 ; We can not prove non-null if both the base pointer may be null and the
242 define i1 @gep13_nuw_maybe_zero_offset(ptr %ptr, i32 %offset) {
243 ; CHECK-LABEL: @gep13_nuw_maybe_zero_offset(
244 ; CHECK-NEXT: [[X:%.*]] = getelementptr nuw i8, ptr [[PTR:%.*]], i32 [[OFFSET:%.*]]
245 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
246 ; CHECK-NEXT: ret i1 [[CMP]]
248 %x = getelementptr nuw i8, ptr %ptr, i32 %offset
249 %cmp = icmp eq ptr %x, null
253 ; For gep nusw we don't have any non-null information.
254 define i1 @gep_nusw_may_be_null(ptr %ptr) {
255 ; CHECK-LABEL: @gep_nusw_may_be_null(
256 ; CHECK-NEXT: [[X:%.*]] = getelementptr nusw i8, ptr [[PTR:%.*]], i32 1
257 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
258 ; CHECK-NEXT: ret i1 [[CMP]]
260 %x = getelementptr nusw i8, ptr %ptr, i32 1
261 %cmp = icmp eq ptr %x, null
265 define i1 @gep14(ptr %ptr) {
266 ; CHECK-LABEL: @gep14(
267 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds { {}, i8 }, ptr [[PTR:%.*]], i32 0, i32 1
268 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
269 ; CHECK-NEXT: ret i1 [[CMP]]
271 ; We can't simplify this because the offset of one in the GEP actually doesn't
273 %x = getelementptr inbounds { {}, i8 }, ptr %ptr, i32 0, i32 1
274 %cmp = icmp eq ptr %x, null
278 define i1 @gep15(ptr %ptr, i32 %y) {
279 ; CHECK-LABEL: @gep15(
280 ; CHECK-NEXT: ret i1 false
282 ; We can prove this GEP is non-null even though there is a user value, as we
283 ; would necessarily violate inbounds on one side or the other.
284 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, ptr %ptr, i32 0, i32 1, i32 %y, i32 1
285 %cmp = icmp eq ptr %x, null
289 define i1 @gep15_no_null_opt(ptr %ptr, i32 %y) #0 {
290 ; We can't prove this GEP is non-null.
291 ; CHECK-LABEL: @gep15_no_null_opt(
292 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds { {}, [4 x { i8, i8 }] }, ptr [[PTR:%.*]], i32 0, i32 1, i32 [[Y:%.*]], i32 1
293 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
294 ; CHECK-NEXT: ret i1 [[CMP]]
296 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, ptr %ptr, i32 0, i32 1, i32 %y, i32 1
297 %cmp = icmp eq ptr %x, null
301 define i1 @gep16(ptr %ptr, i32 %a) {
302 ; CHECK-LABEL: @gep16(
303 ; CHECK-NEXT: ret i1 false
305 ; We can prove this GEP is non-null because it is inbounds and because we know
306 ; %b is non-zero even though we don't know its value.
308 %x = getelementptr inbounds i8, ptr %ptr, i32 %b
309 %cmp = icmp eq ptr %x, null
313 define i1 @gep16_no_null_opt(ptr %ptr, i32 %a) #0 {
314 ; We can't prove this GEP is non-null.
315 ; CHECK-LABEL: @gep16_no_null_opt(
316 ; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 1
317 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i32 [[B]]
318 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
319 ; CHECK-NEXT: ret i1 [[CMP]]
322 %x = getelementptr inbounds i8, ptr %ptr, i32 %b
323 %cmp = icmp eq ptr %x, null
328 ; CHECK-LABEL: @gep17(
329 ; CHECK-NEXT: ret i1 true
331 %alloca = alloca i32, align 4
332 %gep1 = getelementptr inbounds i32, ptr %alloca, i32 1
333 %pti1 = ptrtoint ptr %gep1 to i32
334 %gep2 = getelementptr inbounds [4 x i8], ptr %alloca, i32 0, i32 1
335 %pti2 = ptrtoint ptr %gep2 to i32
336 %cmp = icmp ugt i32 %pti1, %pti2
340 @extern_weak = extern_weak global i8
342 define i1 @extern_weak_may_be_null() {
343 ; CHECK-LABEL: @extern_weak_may_be_null(
344 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr @extern_weak, null
345 ; CHECK-NEXT: ret i1 [[CMP]]
347 %cmp = icmp ne ptr @extern_weak, null
351 ; Don't fold this. @A might really be allocated next to @B, in which case the
352 ; icmp should return true. It's not valid to *dereference* in @B from a pointer
353 ; based on @A, but icmp isn't a dereference.
354 define i1 @globals_might_be_adjacent() {
355 ; CHECK-LABEL: @globals_might_be_adjacent(
356 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr getelementptr inbounds (i32, ptr @A, i64 1), @B
357 ; CHECK-NEXT: ret i1 [[CMP]]
359 %cmp = icmp eq ptr getelementptr inbounds (i32, ptr @A, i64 1), @B
363 define i1 @globals_might_be_adjacent2() {
364 ; CHECK-LABEL: @globals_might_be_adjacent2(
365 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr getelementptr inbounds (i64, ptr @A, i64 1), getelementptr inbounds (i64, ptr @B, i64 2)
366 ; CHECK-NEXT: ret i1 [[CMP]]
368 %cmp = icmp eq ptr getelementptr inbounds (i64, ptr @A, i64 1), getelementptr inbounds (i64, ptr @B, i64 2)
372 @weak = weak global i32 0
374 ; An object with weak linkage cannot have it's identity determined at compile time.
375 define i1 @weak_comparison() {
376 ; CHECK-LABEL: @weak_comparison(
377 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @weak, @A
378 ; CHECK-NEXT: ret i1 [[CMP]]
380 %cmp = icmp eq ptr @weak, @A
384 @empty.1 = external global [0 x i8], align 1
385 @empty.2 = external global [0 x i8], align 1
387 ; Empty globals might end up anywhere, even on top of another global.
388 define i1 @empty_global_comparison() {
389 ; CHECK-LABEL: @empty_global_comparison(
390 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @empty.1, @empty.2
391 ; CHECK-NEXT: ret i1 [[CMP]]
393 %cmp = icmp eq ptr @empty.1, @empty.2
397 @unnamed.1 = unnamed_addr constant [5 x i8] c"asdf\00"
398 @unnamed.2 = unnamed_addr constant [5 x i8] c"asdf\00"
400 ; Two unnamed_addr globals can share an address
401 define i1 @unnamed_addr_comparison() {
402 ; CHECK-LABEL: @unnamed_addr_comparison(
403 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @unnamed.1, @unnamed.2
404 ; CHECK-NEXT: ret i1 [[CMP]]
406 %cmp = icmp eq ptr @unnamed.1, @unnamed.2
410 @addrspace3 = internal addrspace(3) global i32 undef
412 define i1 @no.fold.addrspace.icmp.eq.gv.null() {
413 ; CHECK-LABEL: @no.fold.addrspace.icmp.eq.gv.null(
414 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(3) @addrspace3, null
415 ; CHECK-NEXT: ret i1 [[CMP]]
417 %cmp = icmp eq ptr addrspace(3) @addrspace3, null
421 define i1 @no.fold.addrspace.icmp.eq.null.gv() {
422 ; CHECK-LABEL: @no.fold.addrspace.icmp.eq.null.gv(
423 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(3) null, @addrspace3
424 ; CHECK-NEXT: ret i1 [[CMP]]
426 %cmp = icmp eq ptr addrspace(3) null, @addrspace3
430 define i1 @no.fold.addrspace.icmp.ne.gv.null() {
431 ; CHECK-LABEL: @no.fold.addrspace.icmp.ne.gv.null(
432 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(3) @addrspace3, null
433 ; CHECK-NEXT: ret i1 [[CMP]]
435 %cmp = icmp ne ptr addrspace(3) @addrspace3, null
439 define i1 @no.fold.addrspace.icmp.ne.null.gv() {
440 ; CHECK-LABEL: @no.fold.addrspace.icmp.ne.null.gv(
441 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(3) null, @addrspace3
442 ; CHECK-NEXT: ret i1 [[CMP]]
444 %cmp = icmp ne ptr addrspace(3) null, @addrspace3
448 ; Negative test: GEP inbounds may cross sign boundary.
449 define i1 @gep_same_base_constant_indices(ptr %a) {
450 ; CHECK-LABEL: @gep_same_base_constant_indices(
451 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i64 1
452 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 10
453 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt ptr [[ARRAYIDX1]], [[ARRAYIDX2]]
454 ; CHECK-NEXT: ret i1 [[CMP]]
456 %arrayidx1 = getelementptr inbounds i8, ptr %a, i64 1
457 %arrayidx2 = getelementptr inbounds i8, ptr %a, i64 10
458 %cmp = icmp slt ptr %arrayidx1, %arrayidx2
462 define i1 @zext(i32 %x) {
463 ; CHECK-LABEL: @zext(
464 ; CHECK-NEXT: ret i1 true
466 %e1 = zext i32 %x to i64
467 %e2 = zext i32 %x to i64
468 %r = icmp eq i64 %e1, %e2
472 define i1 @zext2(i1 %x) {
473 ; CHECK-LABEL: @zext2(
474 ; CHECK-NEXT: ret i1 [[X:%.*]]
476 %e = zext i1 %x to i32
477 %c = icmp ne i32 %e, 0
482 ; CHECK-LABEL: @zext3(
483 ; CHECK-NEXT: ret i1 true
485 %e = zext i1 1 to i32
486 %c = icmp ne i32 %e, 0
490 define i1 @sext(i32 %x) {
491 ; CHECK-LABEL: @sext(
492 ; CHECK-NEXT: ret i1 true
494 %e1 = sext i32 %x to i64
495 %e2 = sext i32 %x to i64
496 %r = icmp eq i64 %e1, %e2
500 define i1 @sext2(i1 %x) {
501 ; CHECK-LABEL: @sext2(
502 ; CHECK-NEXT: ret i1 [[X:%.*]]
504 %e = sext i1 %x to i32
505 %c = icmp ne i32 %e, 0
510 ; CHECK-LABEL: @sext3(
511 ; CHECK-NEXT: ret i1 true
513 %e = sext i1 1 to i32
514 %c = icmp ne i32 %e, 0
518 define i1 @add(i32 %x, i32 %y) {
520 ; CHECK-NEXT: ret i1 false
526 %c = icmp eq i32 %s, 0
530 define i1 @addv(<2 x i32> %x, <2 x i32> %y) {
531 ; CHECK-LABEL: @addv(
532 ; CHECK-NEXT: ret i1 false
534 %l = lshr <2 x i32> %x, <i32 1, i32 0>
535 %q = lshr <2 x i32> %y, <i32 1, i32 0>
536 %r = or <2 x i32> %q, <i32 1, i32 0>
537 %s = add <2 x i32> %l, %r
538 %e = extractelement <2 x i32> %s, i32 0
539 %c = icmp eq i32 %e, 0
543 define i1 @add2(i8 %x, i8 %y) {
544 ; CHECK-LABEL: @add2(
545 ; CHECK-NEXT: ret i1 false
550 %c = icmp eq i8 %s, 0
554 define i1 @add2v(<2 x i8> %x, <2 x i8> %y) {
555 ; CHECK-LABEL: @add2v(
556 ; CHECK-NEXT: ret i1 false
558 %l = or <2 x i8> %x, <i8 0, i8 128>
559 %r = or <2 x i8> %y, <i8 0, i8 129>
560 %s = add <2 x i8> %l, %r
561 %e = extractelement <2 x i8> %s, i32 1
562 %c = icmp eq i8 %e, 0
566 define i1 @add3(i8 %x, i8 %y) {
567 ; CHECK-LABEL: @add3(
568 ; CHECK-NEXT: [[L:%.*]] = zext i8 [[X:%.*]] to i32
569 ; CHECK-NEXT: [[R:%.*]] = zext i8 [[Y:%.*]] to i32
570 ; CHECK-NEXT: [[S:%.*]] = add i32 [[L]], [[R]]
571 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[S]], 0
572 ; CHECK-NEXT: ret i1 [[C]]
574 %l = zext i8 %x to i32
575 %r = zext i8 %y to i32
577 %c = icmp eq i32 %s, 0
581 define i1 @add4(i32 %x, i32 %y) {
582 ; CHECK-LABEL: @add4(
583 ; CHECK-NEXT: ret i1 true
585 %z = add nsw i32 %y, 1
586 %s1 = add nsw i32 %x, %y
587 %s2 = add nsw i32 %x, %z
588 %c = icmp slt i32 %s1, %s2
592 define i1 @add5(i32 %x, i32 %y) {
593 ; CHECK-LABEL: @add5(
594 ; CHECK-NEXT: ret i1 true
596 %z = add nuw i32 %y, 1
597 %s1 = add nuw i32 %x, %z
598 %s2 = add nuw i32 %x, %y
599 %c = icmp ugt i32 %s1, %s2
603 define i1 @add6(i64 %A, i64 %B) {
604 ; CHECK-LABEL: @add6(
605 ; CHECK-NEXT: ret i1 true
609 %cmp = icmp eq i64 %s1, %s2
613 define i1 @addpowtwo(i32 %x, i32 %y) {
614 ; CHECK-LABEL: @addpowtwo(
615 ; CHECK-NEXT: ret i1 false
620 %c = icmp eq i32 %s, 0
624 define i1 @addpowtwov(<2 x i32> %x, <2 x i32> %y) {
625 ; CHECK-LABEL: @addpowtwov(
626 ; CHECK-NEXT: [[L:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 1, i32 0>
627 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i32> <i32 1, i32 0>, [[Y:%.*]]
628 ; CHECK-NEXT: [[S:%.*]] = add <2 x i32> [[L]], [[R]]
629 ; CHECK-NEXT: [[E:%.*]] = extractelement <2 x i32> [[S]], i32 0
630 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[E]], 0
631 ; CHECK-NEXT: ret i1 [[C]]
633 %l = lshr <2 x i32> %x, <i32 1, i32 0>
634 %r = shl <2 x i32> <i32 1, i32 0>, %y
635 %s = add <2 x i32> %l, %r
636 %e = extractelement <2 x i32> %s, i32 0
637 %c = icmp eq i32 %e, 0
641 define i1 @or(i32 %x) {
643 ; CHECK-NEXT: ret i1 false
646 %c = icmp eq i32 %o, 0
650 ; Do not simplify if we cannot guarantee that the ConstantExpr is a non-zero
652 @GV = common global ptr null
653 define i1 @or_constexp(i32 %x) {
654 ; CHECK-LABEL: @or_constexp(
656 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 ptrtoint (ptr @GV to i32), 32
657 ; CHECK-NEXT: [[O:%.*]] = or i32 [[X:%.*]], [[TMP0]]
658 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[O]], 0
659 ; CHECK-NEXT: ret i1 [[C]]
662 %0 = and i32 ptrtoint (ptr @GV to i32), 32
664 %c = icmp eq i32 %o, 0
668 define i1 @shl1(i32 %x) {
669 ; CHECK-LABEL: @shl1(
670 ; CHECK-NEXT: ret i1 false
673 %c = icmp eq i32 %s, 0
677 define i1 @lshr1(i32 %x) {
678 ; CHECK-LABEL: @lshr1(
679 ; CHECK-NEXT: ret i1 false
682 %c = icmp eq i32 %s, 0
686 define i1 @lshr3(i32 %x) {
687 ; CHECK-LABEL: @lshr3(
688 ; CHECK-NEXT: ret i1 true
691 %c = icmp eq i32 %s, 0
695 define i1 @lshr4(i32 %X, i32 %Y) {
696 ; CHECK-LABEL: @lshr4(
697 ; CHECK-NEXT: ret i1 true
700 %C = icmp ule i32 %A, %X
704 define i1 @lshr5(i32 %X, i32 %Y) {
705 ; CHECK-LABEL: @lshr5(
706 ; CHECK-NEXT: ret i1 false
709 %C = icmp ugt i32 %A, %X
713 define i1 @lshr6(i32 %X, i32 %Y) {
714 ; CHECK-LABEL: @lshr6(
715 ; CHECK-NEXT: ret i1 false
718 %C = icmp ult i32 %X, %A
722 define i1 @lshr7(i32 %X, i32 %Y) {
723 ; CHECK-LABEL: @lshr7(
724 ; CHECK-NEXT: ret i1 true
727 %C = icmp uge i32 %X, %A
731 define i1 @lshr_nonzero_eq(i32 %x) {
732 ; CHECK-LABEL: @lshr_nonzero_eq(
733 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
734 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
735 ; CHECK-NEXT: ret i1 false
737 %x_ne_0 = icmp ne i32 %x, 0
738 call void @llvm.assume(i1 %x_ne_0)
739 %lhs = lshr i32 %x, 1
740 %cmp = icmp eq i32 %lhs, %x
744 define i1 @lshr_nonzero_uge(i32 %x) {
745 ; CHECK-LABEL: @lshr_nonzero_uge(
746 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
747 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
748 ; CHECK-NEXT: ret i1 false
750 %x_ne_0 = icmp ne i32 %x, 0
751 call void @llvm.assume(i1 %x_ne_0)
752 %lhs = lshr i32 %x, 1
753 %cmp = icmp uge i32 %lhs, %x
757 define i1 @lshr_nonzero_ne(i32 %x) {
758 ; CHECK-LABEL: @lshr_nonzero_ne(
759 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
760 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
761 ; CHECK-NEXT: ret i1 true
763 %x_ne_0 = icmp ne i32 %x, 0
764 call void @llvm.assume(i1 %x_ne_0)
765 %lhs = lshr i32 %x, 1
766 %cmp = icmp ne i32 %lhs, %x
770 define i1 @lshr_nonzero_ult(i32 %x) {
771 ; CHECK-LABEL: @lshr_nonzero_ult(
772 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
773 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
774 ; CHECK-NEXT: ret i1 true
776 %x_ne_0 = icmp ne i32 %x, 0
777 call void @llvm.assume(i1 %x_ne_0)
778 %lhs = lshr i32 %x, 1
779 %cmp = icmp ult i32 %lhs, %x
783 define i1 @lshr_nonzero_ugt(i32 %x) {
784 ; CHECK-LABEL: @lshr_nonzero_ugt(
785 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
786 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
787 ; CHECK-NEXT: ret i1 false
789 %x_ne_0 = icmp ne i32 %x, 0
790 call void @llvm.assume(i1 %x_ne_0)
791 %lhs = lshr i32 %x, 1
792 %cmp = icmp ugt i32 %lhs, %x
796 define i1 @lshr_nonzero_ule(i32 %x) {
797 ; CHECK-LABEL: @lshr_nonzero_ule(
798 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
799 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
800 ; CHECK-NEXT: ret i1 true
802 %x_ne_0 = icmp ne i32 %x, 0
803 call void @llvm.assume(i1 %x_ne_0)
804 %lhs = lshr i32 %x, 1
805 %cmp = icmp ule i32 %lhs, %x
809 ; Negative test - unknown shift amount
810 define i1 @lshr_nonzero_neg_unknown(i32 %x, i32 %c) {
811 ; CHECK-LABEL: @lshr_nonzero_neg_unknown(
812 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
813 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
814 ; CHECK-NEXT: [[LHS:%.*]] = lshr i32 [[X]], [[C:%.*]]
815 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
816 ; CHECK-NEXT: ret i1 [[CMP]]
818 %x_ne_0 = icmp ne i32 %x, 0
819 call void @llvm.assume(i1 %x_ne_0)
820 %lhs = lshr i32 %x, %c
821 %cmp = icmp ult i32 %lhs, %x
825 ; Negative test - x may be zero
826 define i1 @lshr_nonzero_neg_maybe_zero(i32 %x) {
827 ; CHECK-LABEL: @lshr_nonzero_neg_maybe_zero(
828 ; CHECK-NEXT: [[LHS:%.*]] = lshr i32 [[X:%.*]], 1
829 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
830 ; CHECK-NEXT: ret i1 [[CMP]]
832 %lhs = lshr i32 %x, 1
833 %cmp = icmp ult i32 %lhs, %x
837 ; Negative test - signed pred
838 define i1 @lshr_nonzero_neg_signed(i32 %x, i32 %c) {
839 ; CHECK-LABEL: @lshr_nonzero_neg_signed(
840 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
841 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
842 ; CHECK-NEXT: [[LHS:%.*]] = lshr i32 [[X]], 1
843 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[LHS]], [[X]]
844 ; CHECK-NEXT: ret i1 [[CMP]]
846 %x_ne_0 = icmp ne i32 %x, 0
847 call void @llvm.assume(i1 %x_ne_0)
848 %lhs = lshr i32 %x, 1
849 %cmp = icmp slt i32 %lhs, %x
853 define i1 @ashr1(i32 %x) {
854 ; CHECK-LABEL: @ashr1(
855 ; CHECK-NEXT: ret i1 false
858 %c = icmp eq i32 %s, 0
862 define i1 @ashr3(i32 %x) {
863 ; CHECK-LABEL: @ashr3(
864 ; CHECK-NEXT: ret i1 true
867 %c = icmp eq i32 %s, 0
871 define i1 @select1(i1 %cond) {
872 ; CHECK-LABEL: @select1(
873 ; CHECK-NEXT: ret i1 [[COND:%.*]]
875 %s = select i1 %cond, i32 1, i32 0
876 %c = icmp eq i32 %s, 1
880 define i1 @select2(i1 %cond) {
881 ; CHECK-LABEL: @select2(
882 ; CHECK-NEXT: ret i1 [[COND:%.*]]
884 %x = zext i1 %cond to i32
885 %s = select i1 %cond, i32 %x, i32 0
886 %c = icmp ne i32 %s, 0
890 define i1 @select3(i1 %cond) {
891 ; CHECK-LABEL: @select3(
892 ; CHECK-NEXT: ret i1 [[COND:%.*]]
894 %x = zext i1 %cond to i32
895 %s = select i1 %cond, i32 1, i32 %x
896 %c = icmp ne i32 %s, 0
900 define i1 @select4(i1 %cond) {
901 ; CHECK-LABEL: @select4(
902 ; CHECK-NEXT: ret i1 [[COND:%.*]]
904 %invert = xor i1 %cond, 1
905 %s = select i1 %invert, i32 0, i32 1
906 %c = icmp ne i32 %s, 0
910 define i1 @select5(i32 %x) {
911 ; CHECK-LABEL: @select5(
912 ; CHECK-NEXT: ret i1 false
914 %c = icmp eq i32 %x, 0
915 %s = select i1 %c, i32 1, i32 %x
916 %c2 = icmp eq i32 %s, 0
920 define i1 @select6(i32 %x) {
921 ; CHECK-LABEL: @select6(
922 ; CHECK-NEXT: ret i1 false
924 %c = icmp sgt i32 %x, 0
925 %s = select i1 %c, i32 %x, i32 4
926 %c2 = icmp eq i32 %s, 0
930 define i1 @urem1(i32 %X, i32 %Y) {
931 ; CHECK-LABEL: @urem1(
932 ; CHECK-NEXT: ret i1 true
935 %B = icmp ult i32 %A, %Y
939 define i1 @urem2(i32 %X, i32 %Y) {
940 ; CHECK-LABEL: @urem2(
941 ; CHECK-NEXT: ret i1 false
944 %B = icmp eq i32 %A, %Y
948 define i1 @urem4(i32 %X) {
949 ; CHECK-LABEL: @urem4(
950 ; CHECK-NEXT: [[A:%.*]] = urem i32 [[X:%.*]], 15
951 ; CHECK-NEXT: [[B:%.*]] = icmp ult i32 [[A]], 10
952 ; CHECK-NEXT: ret i1 [[B]]
955 %B = icmp ult i32 %A, 10
959 define i1 @urem5(i16 %X, i32 %Y) {
960 ; CHECK-LABEL: @urem5(
961 ; CHECK-NEXT: [[A:%.*]] = zext i16 [[X:%.*]] to i32
962 ; CHECK-NEXT: [[B:%.*]] = urem i32 [[A]], [[Y:%.*]]
963 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[B]], [[Y]]
964 ; CHECK-NEXT: ret i1 [[C]]
966 %A = zext i16 %X to i32
968 %C = icmp slt i32 %B, %Y
972 define i1 @urem6(i32 %X, i32 %Y) {
973 ; CHECK-LABEL: @urem6(
974 ; CHECK-NEXT: ret i1 true
977 %B = icmp ugt i32 %Y, %A
981 define i1 @urem7(i32 %X) {
982 ; CHECK-LABEL: @urem7(
983 ; CHECK-NEXT: [[A:%.*]] = urem i32 1, [[X:%.*]]
984 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 [[A]], [[X]]
985 ; CHECK-NEXT: ret i1 [[B]]
988 %B = icmp sgt i32 %A, %X
992 define i1 @urem8(i8 %X, i8 %Y) {
993 ; CHECK-LABEL: @urem8(
994 ; CHECK-NEXT: ret i1 true
997 %B = icmp ule i8 %A, %X
1001 define i1 @urem9(i8 %X, i8 %Y) {
1002 ; CHECK-LABEL: @urem9(
1003 ; CHECK-NEXT: ret i1 false
1006 %B = icmp ugt i8 %A, %X
1010 define i1 @urem10(i8 %X, i8 %Y) {
1011 ; CHECK-LABEL: @urem10(
1012 ; CHECK-NEXT: ret i1 true
1015 %B = icmp uge i8 %X, %A
1019 define i1 @urem11(i8 %X, i8 %Y) {
1020 ; CHECK-LABEL: @urem11(
1021 ; CHECK-NEXT: ret i1 false
1024 %B = icmp ult i8 %X, %A
1029 define i1 @srem2(i16 %X, i32 %Y) {
1030 ; CHECK-LABEL: @srem2(
1031 ; CHECK-NEXT: ret i1 false
1033 %A = zext i16 %X to i32
1034 %B = add nsw i32 %A, 1
1035 %C = srem i32 %B, %Y
1036 %D = icmp slt i32 %C, 0
1040 define i1 @srem2v(<2 x i16> %X, <2 x i32> %Y) {
1041 ; CHECK-LABEL: @srem2v(
1042 ; CHECK-NEXT: ret i1 false
1044 %A = zext <2 x i16> %X to <2 x i32>
1045 %B = add nsw <2 x i32> %A, <i32 1, i32 0>
1046 %C = srem <2 x i32> %B, %Y
1047 %D = extractelement <2 x i32> %C, i32 0
1048 %E = icmp slt i32 %D, 0
1052 define i1 @srem3(i16 %X, i32 %Y) {
1053 ; CHECK-LABEL: @srem3(
1054 ; CHECK-NEXT: ret i1 false
1056 %A = zext i16 %X to i32
1057 %B = or i32 2147483648, %A
1058 %C = sub nsw i32 1, %B
1059 %D = srem i32 %C, %Y
1060 %E = icmp slt i32 %D, 0
1064 define i1 @srem3v(<2 x i16> %X, <2 x i32> %Y) {
1065 ; CHECK-LABEL: @srem3v(
1066 ; CHECK-NEXT: ret i1 false
1068 %A = zext <2 x i16> %X to <2 x i32>
1069 %B = or <2 x i32> <i32 1, i32 2147483648>, %A
1070 %C = sub nsw <2 x i32> <i32 0, i32 1>, %B
1071 %D = srem <2 x i32> %C, %Y
1072 %E = extractelement <2 x i32> %C, i32 1
1073 %F = icmp slt i32 %E, 0
1077 define i1 @udiv2(i32 %Z) {
1078 ; CHECK-LABEL: @udiv2(
1079 ; CHECK-NEXT: ret i1 true
1081 %A = udiv exact i32 10, %Z
1082 %B = udiv exact i32 20, %Z
1083 %C = icmp ult i32 %A, %B
1087 ; Exact sdiv and equality preds can simplify.
1089 define i1 @sdiv_exact_equality(i32 %Z) {
1090 ; CHECK-LABEL: @sdiv_exact_equality(
1091 ; CHECK-NEXT: ret i1 false
1093 %A = sdiv exact i32 10, %Z
1094 %B = sdiv exact i32 20, %Z
1095 %C = icmp eq i32 %A, %B
1099 ; But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949
1101 define i1 @sdiv_exact_not_equality(i32 %Z) {
1102 ; CHECK-LABEL: @sdiv_exact_not_equality(
1103 ; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 10, [[Z:%.*]]
1104 ; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 20, [[Z]]
1105 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]]
1106 ; CHECK-NEXT: ret i1 [[C]]
1108 %A = sdiv exact i32 10, %Z
1109 %B = sdiv exact i32 20, %Z
1110 %C = icmp ult i32 %A, %B
1114 define i1 @udiv3(i32 %X, i32 %Y) {
1115 ; CHECK-LABEL: @udiv3(
1116 ; CHECK-NEXT: ret i1 false
1118 %A = udiv i32 %X, %Y
1119 %C = icmp ugt i32 %A, %X
1123 define i1 @udiv4(i32 %X, i32 %Y) {
1124 ; CHECK-LABEL: @udiv4(
1125 ; CHECK-NEXT: ret i1 true
1127 %A = udiv i32 %X, %Y
1128 %C = icmp ule i32 %A, %X
1133 define i1 @udiv6(i32 %X) nounwind {
1134 ; CHECK-LABEL: @udiv6(
1135 ; CHECK-NEXT: [[A:%.*]] = udiv i32 1, [[X:%.*]]
1136 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[A]], 0
1137 ; CHECK-NEXT: ret i1 [[C]]
1140 %C = icmp eq i32 %A, 0
1144 define i1 @udiv7(i32 %X, i32 %Y) {
1145 ; CHECK-LABEL: @udiv7(
1146 ; CHECK-NEXT: ret i1 false
1148 %A = udiv i32 %X, %Y
1149 %C = icmp ult i32 %X, %A
1153 define i1 @udiv8(i32 %X, i32 %Y) {
1154 ; CHECK-LABEL: @udiv8(
1155 ; CHECK-NEXT: ret i1 true
1157 %A = udiv i32 %X, %Y
1158 %C = icmp uge i32 %X, %A
1162 define i1 @udiv_nonzero_eq(i32 %x) {
1163 ; CHECK-LABEL: @udiv_nonzero_eq(
1164 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1165 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1166 ; CHECK-NEXT: ret i1 false
1168 %x_ne_0 = icmp ne i32 %x, 0
1169 call void @llvm.assume(i1 %x_ne_0)
1170 %lhs = udiv i32 %x, 3
1171 %cmp = icmp eq i32 %lhs, %x
1175 define i1 @udiv_nonzero_uge(i32 %x) {
1176 ; CHECK-LABEL: @udiv_nonzero_uge(
1177 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1178 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1179 ; CHECK-NEXT: ret i1 false
1181 %x_ne_0 = icmp ne i32 %x, 0
1182 call void @llvm.assume(i1 %x_ne_0)
1183 %lhs = udiv i32 %x, 3
1184 %cmp = icmp uge i32 %lhs, %x
1188 define i1 @udiv_nonzero_ne(i32 %x) {
1189 ; CHECK-LABEL: @udiv_nonzero_ne(
1190 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1191 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1192 ; CHECK-NEXT: ret i1 true
1194 %x_ne_0 = icmp ne i32 %x, 0
1195 call void @llvm.assume(i1 %x_ne_0)
1196 %lhs = udiv i32 %x, 3
1197 %cmp = icmp ne i32 %lhs, %x
1201 define i1 @udiv_nonzero_ult(i32 %x) {
1202 ; CHECK-LABEL: @udiv_nonzero_ult(
1203 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1204 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1205 ; CHECK-NEXT: ret i1 true
1207 %x_ne_0 = icmp ne i32 %x, 0
1208 call void @llvm.assume(i1 %x_ne_0)
1209 %lhs = udiv i32 %x, 3
1210 %cmp = icmp ult i32 %lhs, %x
1214 ; Negative test - unknown divisor
1215 define i1 @udiv_nonzero_neg_unknown(i32 %x, i32 %c) {
1216 ; CHECK-LABEL: @udiv_nonzero_neg_unknown(
1217 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1218 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1219 ; CHECK-NEXT: [[LHS:%.*]] = udiv i32 [[X]], [[C:%.*]]
1220 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
1221 ; CHECK-NEXT: ret i1 [[CMP]]
1223 %x_ne_0 = icmp ne i32 %x, 0
1224 call void @llvm.assume(i1 %x_ne_0)
1225 %lhs = udiv i32 %x, %c
1226 %cmp = icmp ult i32 %lhs, %x
1230 ; Negative test - x may be zero
1231 define i1 @udiv_nonzero_neg_maybe_zero(i32 %x) {
1232 ; CHECK-LABEL: @udiv_nonzero_neg_maybe_zero(
1233 ; CHECK-NEXT: [[LHS:%.*]] = udiv i32 [[X:%.*]], 3
1234 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LHS]], [[X]]
1235 ; CHECK-NEXT: ret i1 [[CMP]]
1237 %lhs = udiv i32 %x, 3
1238 %cmp = icmp ult i32 %lhs, %x
1242 ; Negative test - signed pred
1243 define i1 @udiv_nonzero_neg_signed(i32 %x) {
1244 ; CHECK-LABEL: @udiv_nonzero_neg_signed(
1245 ; CHECK-NEXT: [[X_NE_0:%.*]] = icmp ne i32 [[X:%.*]], 0
1246 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NE_0]])
1247 ; CHECK-NEXT: [[LHS:%.*]] = udiv i32 [[X]], 3
1248 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[LHS]], [[X]]
1249 ; CHECK-NEXT: ret i1 [[CMP]]
1251 %x_ne_0 = icmp ne i32 %x, 0
1252 call void @llvm.assume(i1 %x_ne_0)
1253 %lhs = udiv i32 %x, 3
1254 %cmp = icmp slt i32 %lhs, %x
1258 ; Square of a non-zero number is non-zero if there is no overflow.
1259 define i1 @mul1(i32 %X) {
1260 ; CHECK-LABEL: @mul1(
1261 ; CHECK-NEXT: ret i1 false
1264 %M = mul nuw i32 %Y, %Y
1265 %C = icmp eq i32 %M, 0
1269 define i1 @mul1v(<2 x i32> %X) {
1270 ; CHECK-LABEL: @mul1v(
1271 ; CHECK-NEXT: ret i1 false
1273 %Y = or <2 x i32> %X, <i32 1, i32 0>
1274 %M = mul nuw <2 x i32> %Y, %Y
1275 %E = extractelement <2 x i32> %M, i32 0
1276 %C = icmp eq i32 %E, 0
1280 ; Square of a non-zero number is positive if there is no signed overflow.
1281 define i1 @mul2(i32 %X) {
1282 ; CHECK-LABEL: @mul2(
1283 ; CHECK-NEXT: ret i1 true
1286 %M = mul nsw i32 %Y, %Y
1287 %C = icmp sgt i32 %M, 0
1291 define i1 @mul2v(<2 x i32> %X) {
1292 ; CHECK-LABEL: @mul2v(
1293 ; CHECK-NEXT: ret i1 true
1295 %Y = or <2 x i32> %X, <i32 0, i32 1>
1296 %M = mul nsw <2 x i32> %Y, %Y
1297 %E = extractelement <2 x i32> %M, i32 1
1298 %C = icmp sgt i32 %E, 0
1302 ; Product of non-negative numbers is non-negative if there is no signed overflow.
1303 define i1 @mul3(i32 %X, i32 %Y) {
1304 ; CHECK-LABEL: @mul3(
1305 ; CHECK-NEXT: ret i1 true
1307 %XX = mul nsw i32 %X, %X
1308 %YY = mul nsw i32 %Y, %Y
1309 %M = mul nsw i32 %XX, %YY
1310 %C = icmp sge i32 %M, 0
1314 define <2 x i1> @mul3v(<2 x i32> %X, <2 x i32> %Y) {
1315 ; CHECK-LABEL: @mul3v(
1316 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1318 %XX = mul nsw <2 x i32> %X, %X
1319 %YY = mul nsw <2 x i32> %Y, %Y
1320 %M = mul nsw <2 x i32> %XX, %YY
1321 %C = icmp sge <2 x i32> %M, zeroinitializer
1325 define <2 x i1> @vectorselect1(<2 x i1> %cond) {
1326 ; CHECK-LABEL: @vectorselect1(
1327 ; CHECK-NEXT: ret <2 x i1> [[COND:%.*]]
1329 %invert = xor <2 x i1> %cond, <i1 1, i1 1>
1330 %s = select <2 x i1> %invert, <2 x i32> <i32 0, i32 0>, <2 x i32> <i32 1, i32 1>
1331 %c = icmp ne <2 x i32> %s, <i32 0, i32 0>
1336 define <2 x i1> @vectorselectcrash(i32 %arg1) {
1337 ; CHECK-LABEL: @vectorselectcrash(
1338 ; CHECK-NEXT: [[TOBOOL40:%.*]] = icmp ne i32 [[ARG1:%.*]], 0
1339 ; CHECK-NEXT: [[COND43:%.*]] = select i1 [[TOBOOL40]], <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1>
1340 ; CHECK-NEXT: [[CMP45:%.*]] = icmp ugt <2 x i16> [[COND43]], <i16 73, i16 21>
1341 ; CHECK-NEXT: ret <2 x i1> [[CMP45]]
1343 %tobool40 = icmp ne i32 %arg1, 0
1344 %cond43 = select i1 %tobool40, <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1>
1345 %cmp45 = icmp ugt <2 x i16> %cond43, <i16 73, i16 21>
1350 define i1 @alloca_compare(i64 %idx) {
1351 ; CHECK-LABEL: @alloca_compare(
1352 ; CHECK-NEXT: ret i1 false
1354 %sv = alloca { i32, i32, [124 x i32] }
1355 %1 = getelementptr inbounds { i32, i32, [124 x i32] }, ptr %sv, i32 0, i32 2, i64 %idx
1356 %2 = icmp eq ptr %1, null
1360 define i1 @alloca_compare_no_null_opt(i64 %idx) #0 {
1361 ; CHECK-LABEL: @alloca_compare_no_null_opt(
1362 ; CHECK-NEXT: [[SV:%.*]] = alloca { i32, i32, [124 x i32] }, align 8
1363 ; CHECK-NEXT: [[CMP:%.*]] = getelementptr inbounds { i32, i32, [124 x i32] }, ptr [[SV]], i32 0, i32 2, i64 [[IDX:%.*]]
1364 ; CHECK-NEXT: [[X:%.*]] = icmp eq ptr [[CMP]], null
1365 ; CHECK-NEXT: ret i1 [[X]]
1367 %sv = alloca { i32, i32, [124 x i32] }
1368 %cmp = getelementptr inbounds { i32, i32, [124 x i32] }, ptr %sv, i32 0, i32 2, i64 %idx
1369 %X = icmp eq ptr %cmp, null
1373 define i1 @infinite_gep() {
1374 ; CHECK-LABEL: @infinite_gep(
1375 ; CHECK-NEXT: ret i1 true
1376 ; CHECK: unreachableblock:
1377 ; CHECK-NEXT: [[X:%.*]] = getelementptr i32, ptr [[X]], i32 1
1378 ; CHECK-NEXT: [[Y:%.*]] = icmp eq ptr [[X]], null
1379 ; CHECK-NEXT: ret i1 [[Y]]
1384 %X = getelementptr i32, ptr%X, i32 1
1385 %Y = icmp eq ptr %X, null
1389 ; It's not valid to fold a comparison of an argument with an alloca, even though
1390 ; that's tempting. An argument can't *alias* an alloca, however the aliasing rule
1391 ; relies on restrictions against guessing an object's address and dereferencing.
1392 ; There are no restrictions against guessing an object's address and comparing.
1394 define i1 @alloca_argument_compare(ptr %arg) {
1395 ; CHECK-LABEL: @alloca_argument_compare(
1396 ; CHECK-NEXT: [[ALLOC:%.*]] = alloca i64, align 8
1397 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[ARG:%.*]], [[ALLOC]]
1398 ; CHECK-NEXT: ret i1 [[CMP]]
1401 %cmp = icmp eq ptr %arg, %alloc
1405 ; As above, but with the operands reversed.
1407 define i1 @alloca_argument_compare_swapped(ptr %arg) {
1408 ; CHECK-LABEL: @alloca_argument_compare_swapped(
1409 ; CHECK-NEXT: [[ALLOC:%.*]] = alloca i64, align 8
1410 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[ALLOC]], [[ARG:%.*]]
1411 ; CHECK-NEXT: ret i1 [[CMP]]
1414 %cmp = icmp eq ptr %alloc, %arg
1418 ; Don't assume that a noalias argument isn't equal to a global variable's
1419 ; address. This is an example where AliasAnalysis' NoAlias concept is
1420 ; different from actual pointer inequality.
1422 @y = external global i32
1423 define zeroext i1 @external_compare(ptr noalias %x) {
1424 ; CHECK-LABEL: @external_compare(
1425 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X:%.*]], @y
1426 ; CHECK-NEXT: ret i1 [[CMP]]
1428 %cmp = icmp eq ptr %x, @y
1432 define i1 @alloca_gep(i64 %a, i64 %b) {
1433 ; CHECK-LABEL: @alloca_gep(
1434 ; CHECK-NEXT: ret i1 false
1436 ; We can prove this GEP is non-null because it is inbounds and the pointer
1438 %strs = alloca [1000 x [1001 x i8]], align 16
1439 %x = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %a, i64 %b
1440 %cmp = icmp eq ptr %x, null
1444 define i1 @alloca_gep_no_null_opt(i64 %a, i64 %b) #0 {
1445 ; CHECK-LABEL: @alloca_gep_no_null_opt(
1446 ; CHECK-NEXT: [[STRS:%.*]] = alloca [1000 x [1001 x i8]], align 16
1447 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds [1000 x [1001 x i8]], ptr [[STRS]], i64 0, i64 [[A:%.*]], i64 [[B:%.*]]
1448 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[X]], null
1449 ; CHECK-NEXT: ret i1 [[CMP]]
1451 ; We can't prove this GEP is non-null.
1452 %strs = alloca [1000 x [1001 x i8]], align 16
1453 %x = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %a, i64 %b
1454 %cmp = icmp eq ptr %x, null
1458 define i1 @non_inbounds_gep_compare(ptr %a) {
1459 ; CHECK-LABEL: @non_inbounds_gep_compare(
1460 ; CHECK-NEXT: ret i1 true
1462 ; Equality compares with non-inbounds GEPs can be folded.
1463 %x = getelementptr i64, ptr %a, i64 42
1464 %y = getelementptr inbounds i64, ptr %x, i64 -42
1465 %z = getelementptr i64, ptr %a, i64 -42
1466 %w = getelementptr inbounds i64, ptr %z, i64 42
1467 %cmp = icmp eq ptr %y, %w
1471 define i1 @non_inbounds_gep_compare2(ptr %a) {
1472 ; CHECK-LABEL: @non_inbounds_gep_compare2(
1473 ; CHECK-NEXT: ret i1 true
1475 ; Equality compares with non-inbounds GEPs can be folded.
1476 %x = getelementptr i64, ptr %a, i64 4294967297
1477 %y = getelementptr i64, ptr %a, i64 1
1478 %cmp = icmp eq ptr %y, %y
1482 define i1 @compare_always_true_slt(i16 %a) {
1483 ; CHECK-LABEL: @compare_always_true_slt(
1484 ; CHECK-NEXT: ret i1 true
1486 %t1 = zext i16 %a to i32
1487 %t2 = sub i32 0, %t1
1488 %t3 = icmp slt i32 %t2, 1
1492 define <2 x i1> @compare_always_true_slt_splat(<2 x i16> %a) {
1493 ; CHECK-LABEL: @compare_always_true_slt_splat(
1494 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1496 %t1 = zext <2 x i16> %a to <2 x i32>
1497 %t2 = sub <2 x i32> zeroinitializer, %t1
1498 %t3 = icmp slt <2 x i32> %t2, <i32 1, i32 1>
1502 define i1 @compare_always_true_sle(i16 %a) {
1503 ; CHECK-LABEL: @compare_always_true_sle(
1504 ; CHECK-NEXT: ret i1 true
1506 %t1 = zext i16 %a to i32
1507 %t2 = sub i32 0, %t1
1508 %t3 = icmp sle i32 %t2, 0
1512 define <2 x i1> @compare_always_true_sle_splat(<2 x i16> %a) {
1513 ; CHECK-LABEL: @compare_always_true_sle_splat(
1514 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1516 %t1 = zext <2 x i16> %a to <2 x i32>
1517 %t2 = sub <2 x i32> zeroinitializer, %t1
1518 %t3 = icmp sle <2 x i32> %t2, zeroinitializer
1522 define i1 @compare_always_false_sgt(i16 %a) {
1523 ; CHECK-LABEL: @compare_always_false_sgt(
1524 ; CHECK-NEXT: ret i1 false
1526 %t1 = zext i16 %a to i32
1527 %t2 = sub i32 0, %t1
1528 %t3 = icmp sgt i32 %t2, 0
1532 define <2 x i1> @compare_always_false_sgt_splat(<2 x i16> %a) {
1533 ; CHECK-LABEL: @compare_always_false_sgt_splat(
1534 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1536 %t1 = zext <2 x i16> %a to <2 x i32>
1537 %t2 = sub <2 x i32> zeroinitializer, %t1
1538 %t3 = icmp sgt <2 x i32> %t2, zeroinitializer
1542 define i1 @compare_always_false_sge(i16 %a) {
1543 ; CHECK-LABEL: @compare_always_false_sge(
1544 ; CHECK-NEXT: ret i1 false
1546 %t1 = zext i16 %a to i32
1547 %t2 = sub i32 0, %t1
1548 %t3 = icmp sge i32 %t2, 1
1552 define <2 x i1> @compare_always_false_sge_splat(<2 x i16> %a) {
1553 ; CHECK-LABEL: @compare_always_false_sge_splat(
1554 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1556 %t1 = zext <2 x i16> %a to <2 x i32>
1557 %t2 = sub <2 x i32> zeroinitializer, %t1
1558 %t3 = icmp sge <2 x i32> %t2, <i32 1, i32 1>
1562 define i1 @compare_always_false_eq(i16 %a) {
1563 ; CHECK-LABEL: @compare_always_false_eq(
1564 ; CHECK-NEXT: ret i1 false
1566 %t1 = zext i16 %a to i32
1567 %t2 = sub i32 0, %t1
1568 %t3 = icmp eq i32 %t2, 1
1572 define <2 x i1> @compare_always_false_eq_splat(<2 x i16> %a) {
1573 ; CHECK-LABEL: @compare_always_false_eq_splat(
1574 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1576 %t1 = zext <2 x i16> %a to <2 x i32>
1577 %t2 = sub <2 x i32> zeroinitializer, %t1
1578 %t3 = icmp eq <2 x i32> %t2, <i32 1, i32 1>
1582 define i1 @compare_always_true_ne(i16 %a) {
1583 ; CHECK-LABEL: @compare_always_true_ne(
1584 ; CHECK-NEXT: ret i1 true
1586 %t1 = zext i16 %a to i32
1587 %t2 = sub i32 0, %t1
1588 %t3 = icmp ne i32 %t2, 1
1592 define <2 x i1> @compare_always_true_ne_splat(<2 x i16> %a) {
1593 ; CHECK-LABEL: @compare_always_true_ne_splat(
1594 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1596 %t1 = zext <2 x i16> %a to <2 x i32>
1597 %t2 = sub <2 x i32> zeroinitializer, %t1
1598 %t3 = icmp ne <2 x i32> %t2, <i32 1, i32 1>
1602 define i1 @lshr_ugt_false(i32 %a) {
1603 ; CHECK-LABEL: @lshr_ugt_false(
1604 ; CHECK-NEXT: ret i1 false
1606 %shr = lshr i32 1, %a
1607 %cmp = icmp ugt i32 %shr, 1
1611 define i1 @nonnull_arg(ptr nonnull %i) {
1612 ; CHECK-LABEL: @nonnull_arg(
1613 ; CHECK-NEXT: ret i1 false
1615 %cmp = icmp eq ptr %i, null
1619 define i1 @nonnull_arg_no_null_opt(ptr nonnull %i) #0 {
1620 ; CHECK-LABEL: @nonnull_arg_no_null_opt(
1621 ; CHECK-NEXT: ret i1 false
1623 %cmp = icmp eq ptr %i, null
1627 define i1 @nonnull_deref_arg(ptr dereferenceable(4) %i) {
1628 ; CHECK-LABEL: @nonnull_deref_arg(
1629 ; CHECK-NEXT: ret i1 false
1631 %cmp = icmp eq ptr %i, null
1635 define i1 @nonnull_deref_arg_no_null_opt(ptr dereferenceable(4) %i) #0 {
1636 ; CHECK-LABEL: @nonnull_deref_arg_no_null_opt(
1637 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[I:%.*]], null
1638 ; CHECK-NEXT: ret i1 [[CMP]]
1640 %cmp = icmp eq ptr %i, null
1643 define i1 @nonnull_deref_as_arg(ptr addrspace(1) dereferenceable(4) %i) {
1644 ; CHECK-LABEL: @nonnull_deref_as_arg(
1645 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(1) [[I:%.*]], null
1646 ; CHECK-NEXT: ret i1 [[CMP]]
1648 %cmp = icmp eq ptr addrspace(1) %i, null
1652 declare nonnull ptr @returns_nonnull_helper()
1653 define i1 @returns_nonnull() {
1654 ; CHECK-LABEL: @returns_nonnull(
1655 ; CHECK-NEXT: [[CALL:%.*]] = call nonnull ptr @returns_nonnull_helper()
1656 ; CHECK-NEXT: ret i1 false
1658 %call = call nonnull ptr @returns_nonnull_helper()
1659 %cmp = icmp eq ptr %call, null
1663 declare dereferenceable(4) ptr @returns_nonnull_deref_helper()
1664 define i1 @returns_nonnull_deref() {
1665 ; CHECK-LABEL: @returns_nonnull_deref(
1666 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1667 ; CHECK-NEXT: ret i1 false
1669 %call = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1670 %cmp = icmp eq ptr %call, null
1674 define i1 @returns_nonnull_deref_no_null_opt () #0 {
1675 ; CHECK-LABEL: @returns_nonnull_deref_no_null_opt(
1676 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1677 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[CALL]], null
1678 ; CHECK-NEXT: ret i1 [[CMP]]
1680 %call = call dereferenceable(4) ptr @returns_nonnull_deref_helper()
1681 %cmp = icmp eq ptr %call, null
1685 declare dereferenceable(4) ptr addrspace(1) @returns_nonnull_deref_as_helper()
1686 define i1 @returns_nonnull_as_deref() {
1687 ; CHECK-LABEL: @returns_nonnull_as_deref(
1688 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) ptr addrspace(1) @returns_nonnull_deref_as_helper()
1689 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(1) [[CALL]], null
1690 ; CHECK-NEXT: ret i1 [[CMP]]
1692 %call = call dereferenceable(4) ptr addrspace(1) @returns_nonnull_deref_as_helper()
1693 %cmp = icmp eq ptr addrspace(1) %call, null
1697 define i1 @nonnull_load(ptr %addr) {
1698 ; CHECK-LABEL: @nonnull_load(
1699 ; CHECK-NEXT: ret i1 false
1701 %ptr = load ptr, ptr %addr, !nonnull !{}
1702 %cmp = icmp eq ptr %ptr, null
1706 define i1 @nonnull_load_as_outer(ptr addrspace(1) %addr) {
1707 ; CHECK-LABEL: @nonnull_load_as_outer(
1708 ; CHECK-NEXT: ret i1 false
1710 %ptr = load ptr, ptr addrspace(1) %addr, !nonnull !{}
1711 %cmp = icmp eq ptr %ptr, null
1714 define i1 @nonnull_load_as_inner(ptr %addr) {
1715 ; CHECK-LABEL: @nonnull_load_as_inner(
1716 ; CHECK-NEXT: ret i1 false
1718 %ptr = load ptr addrspace(1), ptr %addr, !nonnull !{}
1719 %cmp = icmp eq ptr addrspace(1) %ptr, null
1723 ; If a bit is known to be zero for A and known to be one for B,
1724 ; then A and B cannot be equal.
1725 define i1 @icmp_eq_const(i32 %a) {
1726 ; CHECK-LABEL: @icmp_eq_const(
1727 ; CHECK-NEXT: ret i1 false
1729 %b = mul nsw i32 %a, -2
1730 %c = icmp eq i32 %b, 1
1734 define <2 x i1> @icmp_eq_const_vec(<2 x i32> %a) {
1735 ; CHECK-LABEL: @icmp_eq_const_vec(
1736 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1738 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2>
1739 %c = icmp eq <2 x i32> %b, <i32 1, i32 1>
1743 define i1 @icmp_ne_const(i32 %a) {
1744 ; CHECK-LABEL: @icmp_ne_const(
1745 ; CHECK-NEXT: ret i1 true
1747 %b = mul nsw i32 %a, -2
1748 %c = icmp ne i32 %b, 1
1752 define <2 x i1> @icmp_ne_const_vec(<2 x i32> %a) {
1753 ; CHECK-LABEL: @icmp_ne_const_vec(
1754 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1756 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2>
1757 %c = icmp ne <2 x i32> %b, <i32 1, i32 1>
1761 define i1 @icmp_sdiv_int_min(i32 %a) {
1762 ; CHECK-LABEL: @icmp_sdiv_int_min(
1763 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 -2147483648, [[A:%.*]]
1764 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[DIV]], -1073741824
1765 ; CHECK-NEXT: ret i1 [[CMP]]
1767 %div = sdiv i32 -2147483648, %a
1768 %cmp = icmp ne i32 %div, -1073741824
1773 define i1 @icmp_sdiv_pr20288(i64 %a) {
1774 ; CHECK-LABEL: @icmp_sdiv_pr20288(
1775 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 [[A:%.*]], -8589934592
1776 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824
1777 ; CHECK-NEXT: ret i1 [[CMP]]
1779 %div = sdiv i64 %a, -8589934592
1780 %cmp = icmp ne i64 %div, 1073741824
1785 define i1 @icmp_sdiv_neg1(i64 %a) {
1786 ; CHECK-LABEL: @icmp_sdiv_neg1(
1787 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 [[A:%.*]], -1
1788 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824
1789 ; CHECK-NEXT: ret i1 [[CMP]]
1791 %div = sdiv i64 %a, -1
1792 %cmp = icmp ne i64 %div, 1073741824
1797 define i1 @icmp_known_bits(i4 %x, i4 %y) {
1798 ; CHECK-LABEL: @icmp_known_bits(
1799 ; CHECK-NEXT: ret i1 false
1801 %and1 = and i4 %y, -7
1802 %and2 = and i4 %x, -7
1803 %or1 = or i4 %and1, 2
1804 %or2 = or i4 %and2, 2
1805 %add = add i4 %or1, %or2
1806 %cmp = icmp eq i4 %add, 0
1810 define i1 @icmp_known_bits_vec(<2 x i4> %x, <2 x i4> %y) {
1811 ; CHECK-LABEL: @icmp_known_bits_vec(
1812 ; CHECK-NEXT: ret i1 false
1814 %and1 = and <2 x i4> %y, <i4 -7, i4 -1>
1815 %and2 = and <2 x i4> %x, <i4 -7, i4 -1>
1816 %or1 = or <2 x i4> %and1, <i4 2, i4 2>
1817 %or2 = or <2 x i4> %and2, <i4 2, i4 2>
1818 %add = add <2 x i4> %or1, %or2
1819 %ext = extractelement <2 x i4> %add,i32 0
1820 %cmp = icmp eq i4 %ext, 0
1824 define i1 @icmp_shl_nuw_1(i64 %a) {
1825 ; CHECK-LABEL: @icmp_shl_nuw_1(
1826 ; CHECK-NEXT: ret i1 true
1828 %shl = shl nuw i64 1, %a
1829 %cmp = icmp ne i64 %shl, 0
1833 define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) {
1834 ; CHECK-LABEL: @icmp_shl_1_V_ugt_2147483648(
1835 ; CHECK-NEXT: ret i1 false
1837 %shl = shl i32 1, %V
1838 %cmp = icmp ugt i32 %shl, 2147483648
1842 define <2 x i1> @icmp_shl_1_ugt_signmask(<2 x i8> %V) {
1843 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask(
1844 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1846 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1847 %cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 128>
1851 define <2 x i1> @icmp_shl_1_ugt_signmask_poison(<2 x i8> %V) {
1852 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask_poison(
1853 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1855 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1856 %cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 poison>
1860 define <2 x i1> @icmp_shl_1_ugt_signmask_poison2(<2 x i8> %V) {
1861 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask_poison2(
1862 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1864 %shl = shl <2 x i8> <i8 1, i8 poison>, %V
1865 %cmp = icmp ugt <2 x i8> %shl, <i8 poison, i8 128>
1869 define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) {
1870 ; CHECK-LABEL: @icmp_shl_1_V_ule_2147483648(
1871 ; CHECK-NEXT: ret i1 true
1873 %shl = shl i32 1, %V
1874 %cmp = icmp ule i32 %shl, 2147483648
1878 define <2 x i1> @icmp_shl_1_ule_signmask(<2 x i8> %V) {
1879 ; CHECK-LABEL: @icmp_shl_1_ule_signmask(
1880 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1882 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1883 %cmp = icmp ule <2 x i8> %shl, <i8 128, i8 128>
1887 define <2 x i1> @icmp_shl_1_ule_signmask_poison(<2 x i8> %V) {
1888 ; CHECK-LABEL: @icmp_shl_1_ule_signmask_poison(
1889 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1891 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1892 %cmp = icmp ule <2 x i8> %shl, <i8 128, i8 poison>
1896 define <2 x i1> @icmp_shl_1_ule_signmask_poison2(<2 x i8> %V) {
1897 ; CHECK-LABEL: @icmp_shl_1_ule_signmask_poison2(
1898 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1900 %shl = shl <2 x i8> <i8 1, i8 poison>, %V
1901 %cmp = icmp ule <2 x i8> %shl, <i8 poison, i8 128>
1905 define i1 @shl_1_cmp_eq_nonpow2(i32 %x) {
1906 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2(
1907 ; CHECK-NEXT: ret i1 false
1910 %c = icmp eq i32 %s, 31
1914 define <2 x i1> @shl_1_cmp_eq_nonpow2_splat(<2 x i32> %x) {
1915 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2_splat(
1916 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1918 %s = shl <2 x i32> <i32 1, i32 1>, %x
1919 %c = icmp eq <2 x i32> %s, <i32 31, i32 31>
1923 define <2 x i1> @shl_1_cmp_eq_nonpow2_splat_poison(<2 x i32> %x) {
1924 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2_splat_poison(
1925 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1927 %s = shl <2 x i32> <i32 1, i32 1>, %x
1928 %c = icmp eq <2 x i32> %s, <i32 31, i32 poison>
1932 define i1 @shl_1_cmp_ne_nonpow2(i32 %x) {
1933 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2(
1934 ; CHECK-NEXT: ret i1 true
1937 %c = icmp ne i32 %s, 42
1941 define <2 x i1> @shl_1_cmp_ne_nonpow2_splat(<2 x i32> %x) {
1942 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2_splat(
1943 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1945 %s = shl <2 x i32> <i32 1, i32 1>, %x
1946 %c = icmp ne <2 x i32> %s, <i32 42, i32 42>
1950 define <2 x i1> @shl_1_cmp_ne_nonpow2_splat_poison(<2 x i32> %x) {
1951 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2_splat_poison(
1952 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1954 %s = shl <2 x i32> <i32 poison, i32 1>, %x
1955 %c = icmp ne <2 x i32> %s, <i32 42, i32 poison>
1959 define i1 @shl_pow2_cmp_eq_nonpow2(i32 %x) {
1960 ; CHECK-LABEL: @shl_pow2_cmp_eq_nonpow2(
1961 ; CHECK-NEXT: ret i1 false
1964 %c = icmp eq i32 %s, 31
1968 define <2 x i1> @shl_pow21_cmp_ne_nonpow2_splat_poison(<2 x i32> %x) {
1969 ; CHECK-LABEL: @shl_pow21_cmp_ne_nonpow2_splat_poison(
1970 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
1972 %s = shl <2 x i32> <i32 poison, i32 4>, %x
1973 %c = icmp ne <2 x i32> %s, <i32 31, i32 poison>
1977 ; Negative test - overflowing shift could be zero.
1979 define i1 @shl_pow2_cmp_ne_zero(i32 %x) {
1980 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero(
1981 ; CHECK-NEXT: [[S:%.*]] = shl i32 16, [[X:%.*]]
1982 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[S]], 0
1983 ; CHECK-NEXT: ret i1 [[C]]
1986 %c = icmp ne i32 %s, 0
1990 ; Negative test - overflowing shift could be zero.
1992 define <2 x i1> @shl_pow2_cmp_ne_zero_splat(<2 x i32> %x) {
1993 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_splat(
1994 ; CHECK-NEXT: [[S:%.*]] = shl <2 x i32> splat (i32 16), [[X:%.*]]
1995 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[S]], zeroinitializer
1996 ; CHECK-NEXT: ret <2 x i1> [[C]]
1998 %s = shl <2 x i32> <i32 16, i32 16>, %x
1999 %c = icmp ne <2 x i32> %s, zeroinitializer
2003 define i1 @shl_pow2_cmp_eq_zero_nuw(i32 %x) {
2004 ; CHECK-LABEL: @shl_pow2_cmp_eq_zero_nuw(
2005 ; CHECK-NEXT: ret i1 false
2007 %s = shl nuw i32 16, %x
2008 %c = icmp eq i32 %s, 0
2012 define <2 x i1> @shl_pow2_cmp_ne_zero_nuw_splat_poison(<2 x i32> %x) {
2013 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_nuw_splat_poison(
2014 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
2016 %s = shl nuw <2 x i32> <i32 16, i32 poison>, %x
2017 %c = icmp ne <2 x i32> %s, <i32 poison, i32 0>
2021 define i1 @shl_pow2_cmp_ne_zero_nsw(i32 %x) {
2022 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_nsw(
2023 ; CHECK-NEXT: ret i1 true
2025 %s = shl nsw i32 16, %x
2026 %c = icmp ne i32 %s, 0
2030 define <2 x i1> @shl_pow2_cmp_eq_zero_nsw_splat_poison(<2 x i32> %x) {
2031 ; CHECK-LABEL: @shl_pow2_cmp_eq_zero_nsw_splat_poison(
2032 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2034 %s = shl nsw <2 x i32> <i32 poison, i32 16>, %x
2035 %c = icmp eq <2 x i32> %s, <i32 0, i32 poison>
2039 define i1 @tautological1(i32 %A, i32 %B) {
2040 ; CHECK-LABEL: @tautological1(
2041 ; CHECK-NEXT: ret i1 false
2044 %D = icmp ugt i32 %C, %A
2048 define i1 @tautological2(i32 %A, i32 %B) {
2049 ; CHECK-LABEL: @tautological2(
2050 ; CHECK-NEXT: ret i1 true
2053 %D = icmp ule i32 %C, %A
2057 define i1 @tautological3(i32 %A, i32 %B) {
2058 ; CHECK-LABEL: @tautological3(
2059 ; CHECK-NEXT: ret i1 true
2062 %D = icmp ule i32 %A, %C
2066 define i1 @tautological4(i32 %A, i32 %B) {
2067 ; CHECK-LABEL: @tautological4(
2068 ; CHECK-NEXT: ret i1 false
2071 %D = icmp ugt i32 %A, %C
2075 define i1 @tautological5(i32 %A, i32 %B) {
2076 ; CHECK-LABEL: @tautological5(
2077 ; CHECK-NEXT: ret i1 false
2080 %D = icmp ult i32 %C, %A
2084 define i1 @tautological6(i32 %A, i32 %B) {
2085 ; CHECK-LABEL: @tautological6(
2086 ; CHECK-NEXT: ret i1 true
2089 %D = icmp uge i32 %C, %A
2093 define i1 @tautological7(i32 %A, i32 %B) {
2094 ; CHECK-LABEL: @tautological7(
2095 ; CHECK-NEXT: ret i1 true
2098 %D = icmp uge i32 %A, %C
2102 define i1 @tautological8(i32 %A, i32 %B) {
2103 ; CHECK-LABEL: @tautological8(
2104 ; CHECK-NEXT: ret i1 false
2107 %D = icmp ult i32 %A, %C
2111 define i1 @tautological9(i32 %A) {
2112 ; CHECK-LABEL: @tautological9(
2113 ; CHECK-NEXT: ret i1 false
2117 %D = icmp ugt i32 %C1, %C2
2121 define <2 x i1> @tautological9_vec(<2 x i32> %A) {
2122 ; CHECK-LABEL: @tautological9_vec(
2123 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2125 %C1 = and <2 x i32> %A, <i32 1, i32 1>
2126 %C2 = and <2 x i32> %A, <i32 3, i32 3>
2127 %D = icmp ugt <2 x i32> %C1, %C2
2131 define i1 @tautological10(i32 %A) {
2132 ; CHECK-LABEL: @tautological10(
2133 ; CHECK-NEXT: ret i1 true
2137 %D = icmp ule i32 %C1, %C2
2141 define i1 @tautological11(i32 %A) {
2142 ; CHECK-LABEL: @tautological11(
2143 ; CHECK-NEXT: ret i1 true
2147 %D = icmp ule i32 %C1, %C2
2151 define i1 @tautological12(i32 %A) {
2152 ; CHECK-LABEL: @tautological12(
2153 ; CHECK-NEXT: ret i1 false
2157 %D = icmp ugt i32 %C1, %C2
2161 define i1 @tautological13(i32 %A) {
2162 ; CHECK-LABEL: @tautological13(
2163 ; CHECK-NEXT: ret i1 false
2167 %D = icmp ult i32 %C2, %C1
2171 define i1 @tautological14(i32 %A) {
2172 ; CHECK-LABEL: @tautological14(
2173 ; CHECK-NEXT: ret i1 true
2177 %D = icmp uge i32 %C2, %C1
2181 define i1 @tautological15(i32 %A) {
2182 ; CHECK-LABEL: @tautological15(
2183 ; CHECK-NEXT: ret i1 true
2187 %D = icmp uge i32 %C2, %C1
2191 define i1 @tautological16(i32 %A) {
2192 ; CHECK-LABEL: @tautological16(
2193 ; CHECK-NEXT: ret i1 false
2197 %D = icmp ult i32 %C2, %C1
2201 define i1 @tautological9_negative(i32 %A) {
2202 ; CHECK-LABEL: @tautological9_negative(
2203 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2204 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2205 ; CHECK-NEXT: [[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
2206 ; CHECK-NEXT: ret i1 [[D]]
2210 %D = icmp ugt i32 %C1, %C2
2214 define i1 @tautological10_negative(i32 %A) {
2215 ; CHECK-LABEL: @tautological10_negative(
2216 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2217 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2218 ; CHECK-NEXT: [[D:%.*]] = icmp ule i32 [[C1]], [[C2]]
2219 ; CHECK-NEXT: ret i1 [[D]]
2223 %D = icmp ule i32 %C1, %C2
2227 define i1 @tautological11_negative(i32 %A) {
2228 ; CHECK-LABEL: @tautological11_negative(
2229 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2230 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2231 ; CHECK-NEXT: [[D:%.*]] = icmp ule i32 [[C1]], [[C2]]
2232 ; CHECK-NEXT: ret i1 [[D]]
2236 %D = icmp ule i32 %C1, %C2
2240 define i1 @tautological12_negative(i32 %A) {
2241 ; CHECK-LABEL: @tautological12_negative(
2242 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2243 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2244 ; CHECK-NEXT: [[D:%.*]] = icmp ugt i32 [[C1]], [[C2]]
2245 ; CHECK-NEXT: ret i1 [[D]]
2249 %D = icmp ugt i32 %C1, %C2
2253 define i1 @tautological13_negative(i32 %A) {
2254 ; CHECK-LABEL: @tautological13_negative(
2255 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2256 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2257 ; CHECK-NEXT: [[D:%.*]] = icmp ult i32 [[C2]], [[C1]]
2258 ; CHECK-NEXT: ret i1 [[D]]
2262 %D = icmp ult i32 %C2, %C1
2266 define i1 @tautological14_negative(i32 %A) {
2267 ; CHECK-LABEL: @tautological14_negative(
2268 ; CHECK-NEXT: [[C1:%.*]] = or i32 [[A:%.*]], 1
2269 ; CHECK-NEXT: [[C2:%.*]] = or i32 [[A]], 2
2270 ; CHECK-NEXT: [[D:%.*]] = icmp uge i32 [[C2]], [[C1]]
2271 ; CHECK-NEXT: ret i1 [[D]]
2275 %D = icmp uge i32 %C2, %C1
2279 define i1 @tautological15_negative(i32 %A) {
2280 ; CHECK-LABEL: @tautological15_negative(
2281 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2282 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2283 ; CHECK-NEXT: [[D:%.*]] = icmp uge i32 [[C2]], [[C1]]
2284 ; CHECK-NEXT: ret i1 [[D]]
2288 %D = icmp uge i32 %C2, %C1
2292 define i1 @tautological16_negative(i32 %A) {
2293 ; CHECK-LABEL: @tautological16_negative(
2294 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2295 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], 2
2296 ; CHECK-NEXT: [[D:%.*]] = icmp ult i32 [[C2]], [[C1]]
2297 ; CHECK-NEXT: ret i1 [[D]]
2301 %D = icmp ult i32 %C2, %C1
2305 define i1 @tautological17_subset1(i32 %A) {
2306 ; CHECK-LABEL: @tautological17_subset1(
2307 ; CHECK-NEXT: ret i1 false
2311 %D = icmp sgt i32 %C1, %C2
2315 define i1 @tautological17_subset2(i32 %A) {
2316 ; CHECK-LABEL: @tautological17_subset2(
2317 ; CHECK-NEXT: ret i1 false
2319 %C1 = and i32 %A, -4
2320 %C2 = and i32 %A, -3
2321 %D = icmp sgt i32 %C1, %C2
2325 define i1 @tautological17_negative(i32 %A) {
2326 ; CHECK-LABEL: @tautological17_negative(
2327 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2328 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2329 ; CHECK-NEXT: [[D:%.*]] = icmp sgt i32 [[C1]], [[C2]]
2330 ; CHECK-NEXT: ret i1 [[D]]
2333 %C2 = and i32 %A, -3
2334 %D = icmp sgt i32 %C1, %C2
2338 define i1 @tautological18_subset1(i32 %A) {
2339 ; CHECK-LABEL: @tautological18_subset1(
2340 ; CHECK-NEXT: ret i1 true
2344 %D = icmp sle i32 %C1, %C2
2348 define i1 @tautological18_subset2(i32 %A) {
2349 ; CHECK-LABEL: @tautological18_subset2(
2350 ; CHECK-NEXT: ret i1 true
2352 %C1 = and i32 %A, -4
2353 %C2 = and i32 %A, -3
2354 %D = icmp sle i32 %C1, %C2
2358 define i1 @tautological18_negative(i32 %A) {
2359 ; CHECK-LABEL: @tautological18_negative(
2360 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2361 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2362 ; CHECK-NEXT: [[D:%.*]] = icmp sle i32 [[C1]], [[C2]]
2363 ; CHECK-NEXT: ret i1 [[D]]
2366 %C2 = and i32 %A, -3
2367 %D = icmp sle i32 %C1, %C2
2371 define i1 @tautological19_subset1(i32 %A) {
2372 ; CHECK-LABEL: @tautological19_subset1(
2373 ; CHECK-NEXT: ret i1 false
2377 %D = icmp sgt i32 %C1, %C2
2381 define i1 @tautological19_subset2(i32 %A) {
2382 ; CHECK-LABEL: @tautological19_subset2(
2383 ; CHECK-NEXT: ret i1 false
2385 %C1 = and i32 %A, -4
2386 %C2 = and i32 %A, -3
2387 %D = icmp sgt i32 %C1, %C2
2391 define i1 @tautological19_negative(i32 %A) {
2392 ; CHECK-LABEL: @tautological19_negative(
2393 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2394 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2395 ; CHECK-NEXT: [[D:%.*]] = icmp sgt i32 [[C1]], [[C2]]
2396 ; CHECK-NEXT: ret i1 [[D]]
2399 %C2 = and i32 %A, -3
2400 %D = icmp sgt i32 %C1, %C2
2404 define i1 @tautological20_subset1(i32 %A) {
2405 ; CHECK-LABEL: @tautological20_subset1(
2406 ; CHECK-NEXT: ret i1 true
2410 %D = icmp sle i32 %C1, %C2
2414 define i1 @tautological20_subset2(i32 %A) {
2415 ; CHECK-LABEL: @tautological20_subset2(
2416 ; CHECK-NEXT: ret i1 true
2418 %C1 = and i32 %A, -4
2419 %C2 = and i32 %A, -3
2420 %D = icmp sle i32 %C1, %C2
2424 define i1 @tautological20_negative(i32 %A) {
2425 ; CHECK-LABEL: @tautological20_negative(
2426 ; CHECK-NEXT: [[C1:%.*]] = and i32 [[A:%.*]], 1
2427 ; CHECK-NEXT: [[C2:%.*]] = and i32 [[A]], -3
2428 ; CHECK-NEXT: [[D:%.*]] = icmp sle i32 [[C1]], [[C2]]
2429 ; CHECK-NEXT: ret i1 [[D]]
2432 %C2 = and i32 %A, -3
2433 %D = icmp sle i32 %C1, %C2
2437 declare void @helper_i1(i1)
2438 ; Series of tests for icmp s[lt|ge] (or A, B), A and icmp s[gt|le] A, (or A, B)
2439 define void @icmp_slt_sge_or(i32 %Ax, i32 %Bx) {
2440 ; 'p' for positive, 'n' for negative, 'x' for potentially either.
2441 ; %D is 'icmp slt (or A, B), A'
2442 ; %E is 'icmp sge (or A, B), A' making it the not of %D
2443 ; %F is 'icmp sgt A, (or A, B)' making it the same as %D
2444 ; %G is 'icmp sle A, (or A, B)' making it the not of %D
2445 ; CHECK-LABEL: @icmp_slt_sge_or(
2446 ; CHECK-NEXT: [[APOS:%.*]] = and i32 [[AX:%.*]], 2147483647
2447 ; CHECK-NEXT: [[BNEG:%.*]] = or i32 [[BX:%.*]], -2147483648
2448 ; CHECK-NEXT: [[CPX:%.*]] = or i32 [[APOS]], [[BX]]
2449 ; CHECK-NEXT: [[DPX:%.*]] = icmp slt i32 [[CPX]], [[APOS]]
2450 ; CHECK-NEXT: [[EPX:%.*]] = icmp sge i32 [[CPX]], [[APOS]]
2451 ; CHECK-NEXT: [[FPX:%.*]] = icmp sgt i32 [[APOS]], [[CPX]]
2452 ; CHECK-NEXT: [[GPX:%.*]] = icmp sle i32 [[APOS]], [[CPX]]
2453 ; CHECK-NEXT: [[CXX:%.*]] = or i32 [[AX]], [[BX]]
2454 ; CHECK-NEXT: [[DXX:%.*]] = icmp slt i32 [[CXX]], [[AX]]
2455 ; CHECK-NEXT: [[EXX:%.*]] = icmp sge i32 [[CXX]], [[AX]]
2456 ; CHECK-NEXT: [[FXX:%.*]] = icmp sgt i32 [[AX]], [[CXX]]
2457 ; CHECK-NEXT: [[GXX:%.*]] = icmp sle i32 [[AX]], [[CXX]]
2458 ; CHECK-NEXT: [[CXN:%.*]] = or i32 [[AX]], [[BNEG]]
2459 ; CHECK-NEXT: [[DXN:%.*]] = icmp slt i32 [[CXN]], [[AX]]
2460 ; CHECK-NEXT: [[EXN:%.*]] = icmp sge i32 [[CXN]], [[AX]]
2461 ; CHECK-NEXT: [[FXN:%.*]] = icmp sgt i32 [[AX]], [[CXN]]
2462 ; CHECK-NEXT: [[GXN:%.*]] = icmp sle i32 [[AX]], [[CXN]]
2463 ; CHECK-NEXT: call void @helper_i1(i1 false)
2464 ; CHECK-NEXT: call void @helper_i1(i1 true)
2465 ; CHECK-NEXT: call void @helper_i1(i1 false)
2466 ; CHECK-NEXT: call void @helper_i1(i1 true)
2467 ; CHECK-NEXT: call void @helper_i1(i1 [[DPX]])
2468 ; CHECK-NEXT: call void @helper_i1(i1 [[EPX]])
2469 ; CHECK-NEXT: call void @helper_i1(i1 [[FPX]])
2470 ; CHECK-NEXT: call void @helper_i1(i1 [[GPX]])
2471 ; CHECK-NEXT: call void @helper_i1(i1 true)
2472 ; CHECK-NEXT: call void @helper_i1(i1 false)
2473 ; CHECK-NEXT: call void @helper_i1(i1 true)
2474 ; CHECK-NEXT: call void @helper_i1(i1 false)
2475 ; CHECK-NEXT: call void @helper_i1(i1 false)
2476 ; CHECK-NEXT: call void @helper_i1(i1 true)
2477 ; CHECK-NEXT: call void @helper_i1(i1 false)
2478 ; CHECK-NEXT: call void @helper_i1(i1 true)
2479 ; CHECK-NEXT: call void @helper_i1(i1 [[DXX]])
2480 ; CHECK-NEXT: call void @helper_i1(i1 [[EXX]])
2481 ; CHECK-NEXT: call void @helper_i1(i1 [[FXX]])
2482 ; CHECK-NEXT: call void @helper_i1(i1 [[GXX]])
2483 ; CHECK-NEXT: call void @helper_i1(i1 [[DXN]])
2484 ; CHECK-NEXT: call void @helper_i1(i1 [[EXN]])
2485 ; CHECK-NEXT: call void @helper_i1(i1 [[FXN]])
2486 ; CHECK-NEXT: call void @helper_i1(i1 [[GXN]])
2487 ; CHECK-NEXT: call void @helper_i1(i1 false)
2488 ; CHECK-NEXT: call void @helper_i1(i1 true)
2489 ; CHECK-NEXT: call void @helper_i1(i1 false)
2490 ; CHECK-NEXT: call void @helper_i1(i1 true)
2491 ; CHECK-NEXT: call void @helper_i1(i1 false)
2492 ; CHECK-NEXT: call void @helper_i1(i1 true)
2493 ; CHECK-NEXT: call void @helper_i1(i1 false)
2494 ; CHECK-NEXT: call void @helper_i1(i1 true)
2495 ; CHECK-NEXT: call void @helper_i1(i1 false)
2496 ; CHECK-NEXT: call void @helper_i1(i1 true)
2497 ; CHECK-NEXT: call void @helper_i1(i1 false)
2498 ; CHECK-NEXT: call void @helper_i1(i1 true)
2499 ; CHECK-NEXT: ret void
2501 %Aneg = or i32 %Ax, 2147483648
2502 %Apos = and i32 %Ax, 2147483647
2503 %Bneg = or i32 %Bx, 2147483648
2504 %Bpos = and i32 %Bx, 2147483647
2506 %Cpp = or i32 %Apos, %Bpos
2507 %Dpp = icmp slt i32 %Cpp, %Apos
2508 %Epp = icmp sge i32 %Cpp, %Apos
2509 %Fpp = icmp sgt i32 %Apos, %Cpp
2510 %Gpp = icmp sle i32 %Apos, %Cpp
2511 %Cpx = or i32 %Apos, %Bx
2512 %Dpx = icmp slt i32 %Cpx, %Apos
2513 %Epx = icmp sge i32 %Cpx, %Apos
2514 %Fpx = icmp sgt i32 %Apos, %Cpx
2515 %Gpx = icmp sle i32 %Apos, %Cpx
2516 %Cpn = or i32 %Apos, %Bneg
2517 %Dpn = icmp slt i32 %Cpn, %Apos
2518 %Epn = icmp sge i32 %Cpn, %Apos
2519 %Fpn = icmp sgt i32 %Apos, %Cpn
2520 %Gpn = icmp sle i32 %Apos, %Cpn
2522 %Cxp = or i32 %Ax, %Bpos
2523 %Dxp = icmp slt i32 %Cxp, %Ax
2524 %Exp = icmp sge i32 %Cxp, %Ax
2525 %Fxp = icmp sgt i32 %Ax, %Cxp
2526 %Gxp = icmp sle i32 %Ax, %Cxp
2527 %Cxx = or i32 %Ax, %Bx
2528 %Dxx = icmp slt i32 %Cxx, %Ax
2529 %Exx = icmp sge i32 %Cxx, %Ax
2530 %Fxx = icmp sgt i32 %Ax, %Cxx
2531 %Gxx = icmp sle i32 %Ax, %Cxx
2532 %Cxn = or i32 %Ax, %Bneg
2533 %Dxn = icmp slt i32 %Cxn, %Ax
2534 %Exn = icmp sge i32 %Cxn, %Ax
2535 %Fxn = icmp sgt i32 %Ax, %Cxn
2536 %Gxn = icmp sle i32 %Ax, %Cxn
2538 %Cnp = or i32 %Aneg, %Bpos
2539 %Dnp = icmp slt i32 %Cnp, %Aneg
2540 %Enp = icmp sge i32 %Cnp, %Aneg
2541 %Fnp = icmp sgt i32 %Aneg, %Cnp
2542 %Gnp = icmp sle i32 %Aneg, %Cnp
2543 %Cnx = or i32 %Aneg, %Bx
2544 %Dnx = icmp slt i32 %Cnx, %Aneg
2545 %Enx = icmp sge i32 %Cnx, %Aneg
2546 %Fnx = icmp sgt i32 %Aneg, %Cnx
2547 %Gnx = icmp sle i32 %Aneg, %Cnx
2548 %Cnn = or i32 %Aneg, %Bneg
2549 %Dnn = icmp slt i32 %Cnn, %Aneg
2550 %Enn = icmp sge i32 %Cnn, %Aneg
2551 %Fnn = icmp sgt i32 %Aneg, %Cnn
2552 %Gnn = icmp sle i32 %Aneg, %Cnn
2554 call void @helper_i1(i1 %Dpp)
2555 call void @helper_i1(i1 %Epp)
2556 call void @helper_i1(i1 %Fpp)
2557 call void @helper_i1(i1 %Gpp)
2558 call void @helper_i1(i1 %Dpx)
2559 call void @helper_i1(i1 %Epx)
2560 call void @helper_i1(i1 %Fpx)
2561 call void @helper_i1(i1 %Gpx)
2562 call void @helper_i1(i1 %Dpn)
2563 call void @helper_i1(i1 %Epn)
2564 call void @helper_i1(i1 %Fpn)
2565 call void @helper_i1(i1 %Gpn)
2566 call void @helper_i1(i1 %Dxp)
2567 call void @helper_i1(i1 %Exp)
2568 call void @helper_i1(i1 %Fxp)
2569 call void @helper_i1(i1 %Gxp)
2570 call void @helper_i1(i1 %Dxx)
2571 call void @helper_i1(i1 %Exx)
2572 call void @helper_i1(i1 %Fxx)
2573 call void @helper_i1(i1 %Gxx)
2574 call void @helper_i1(i1 %Dxn)
2575 call void @helper_i1(i1 %Exn)
2576 call void @helper_i1(i1 %Fxn)
2577 call void @helper_i1(i1 %Gxn)
2578 call void @helper_i1(i1 %Dnp)
2579 call void @helper_i1(i1 %Enp)
2580 call void @helper_i1(i1 %Fnp)
2581 call void @helper_i1(i1 %Gnp)
2582 call void @helper_i1(i1 %Dnx)
2583 call void @helper_i1(i1 %Enx)
2584 call void @helper_i1(i1 %Fnx)
2585 call void @helper_i1(i1 %Gnx)
2586 call void @helper_i1(i1 %Dnn)
2587 call void @helper_i1(i1 %Enn)
2588 call void @helper_i1(i1 %Fnn)
2589 call void @helper_i1(i1 %Gnn)
2593 define i1 @constant_fold_inttoptr_null() {
2594 ; CHECK-LABEL: @constant_fold_inttoptr_null(
2595 ; CHECK-NEXT: ret i1 false
2597 %x = icmp eq ptr inttoptr (i64 32 to ptr), null
2601 define i1 @constant_fold_null_inttoptr() {
2602 ; CHECK-LABEL: @constant_fold_null_inttoptr(
2603 ; CHECK-NEXT: ret i1 false
2605 %x = icmp eq ptr null, inttoptr (i64 32 to ptr)
2609 define i1 @cmp_through_addrspacecast(ptr addrspace(1) %p1) {
2610 ; CHECK-LABEL: @cmp_through_addrspacecast(
2611 ; CHECK-NEXT: ret i1 true
2613 %p0 = addrspacecast ptr addrspace(1) %p1 to ptr
2614 %p0.1 = getelementptr inbounds i32, ptr %p0, i64 1
2615 %cmp = icmp ne ptr %p0, %p0.1
2619 ; Test simplifications for: icmp (X+Y), (X+Z) -> icmp Y,Z
2620 ; Test the overflow check when the RHS has NSW set and constant Z is greater
2621 ; than Y, then we know X+Y also can't overflow.
2623 define i1 @icmp_nsw_1(i32 %V) {
2624 ; CHECK-LABEL: @icmp_nsw_1(
2625 ; CHECK-NEXT: ret i1 true
2627 %add5 = add i32 %V, 5
2628 %add6 = add nsw i32 %V, 6
2629 %s1 = sext i32 %add5 to i64
2630 %s2 = sext i32 %add6 to i64
2631 %cmp = icmp slt i64 %s1, %s2
2635 define i1 @icmp_nsw_2(i32 %V) {
2636 ; CHECK-LABEL: @icmp_nsw_2(
2637 ; CHECK-NEXT: ret i1 true
2639 %add5 = add i32 %V, 5
2640 %add6 = add nsw i32 %V, 6
2641 %cmp = icmp slt i32 %add5, %add6
2645 define i1 @icmp_nsw_22(i32 %V) {
2646 ; CHECK-LABEL: @icmp_nsw_22(
2647 ; CHECK-NEXT: ret i1 true
2649 %add5 = add nsw i32 %V, 5
2650 %add6 = add nsw i32 %V, 6
2651 %cmp = icmp slt i32 %add5, %add6
2655 define i1 @icmp_nsw_23(i32 %V) {
2656 ; CHECK-LABEL: @icmp_nsw_23(
2657 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2658 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 6
2659 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2660 ; CHECK-NEXT: ret i1 [[CMP]]
2662 %add5 = add nsw i32 %V, 5
2663 %add6 = add i32 %V, 6
2664 %cmp = icmp slt i32 %add5, %add6
2668 define i1 @icmp_nsw_false(i32 %V) {
2669 ; CHECK-LABEL: @icmp_nsw_false(
2670 ; CHECK-NEXT: ret i1 false
2672 %add5 = add nsw i32 %V, 6
2673 %add6 = add i32 %V, 5
2674 %cmp = icmp slt i32 %add5, %add6
2678 define i1 @icmp_nsw_false_2(i32 %V) {
2679 ; CHECK-LABEL: @icmp_nsw_false_2(
2680 ; CHECK-NEXT: ret i1 false
2682 %add5 = add nsw i32 %V, 6
2683 %add6 = add nsw i32 %V, 5
2684 %cmp = icmp slt i32 %add5, %add6
2688 define i1 @icmp_nsw_false_3(i32 %V) {
2689 ; CHECK-LABEL: @icmp_nsw_false_3(
2690 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2691 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 5
2692 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2693 ; CHECK-NEXT: ret i1 [[CMP]]
2695 %add5 = add nsw i32 %V, 5
2696 %add6 = add i32 %V, 5
2697 %cmp = icmp slt i32 %add5, %add6
2701 define i1 @icmp_nsw_false_4(i32 %V) {
2702 ; CHECK-LABEL: @icmp_nsw_false_4(
2703 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 6
2704 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 5
2705 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2706 ; CHECK-NEXT: ret i1 [[CMP]]
2708 %add5 = add i32 %V, 6
2709 %add6 = add nsw i32 %V, 5
2710 %cmp = icmp slt i32 %add5, %add6
2714 define i1 @icmp_nsw_false_5(i8 %V) {
2715 ; CHECK-LABEL: @icmp_nsw_false_5(
2716 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[V:%.*]], 121
2717 ; CHECK-NEXT: [[ADDNSW:%.*]] = add nsw i8 [[V]], -104
2718 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[ADD]], [[ADDNSW]]
2719 ; CHECK-NEXT: ret i1 [[CMP]]
2721 %add = add i8 %V, 121
2722 %addnsw = add nsw i8 %V, -104
2723 %cmp = icmp slt i8 %add, %addnsw
2727 define i1 @icmp_nsw_i8(i8 %V) {
2728 ; CHECK-LABEL: @icmp_nsw_i8(
2729 ; CHECK-NEXT: ret i1 true
2731 %add5 = add i8 %V, 5
2732 %add6 = add nsw i8 %V, 6
2733 %cmp = icmp slt i8 %add5, %add6
2737 define i1 @icmp_nsw_i16(i16 %V) {
2738 ; CHECK-LABEL: @icmp_nsw_i16(
2739 ; CHECK-NEXT: ret i1 true
2741 %add5 = add i16 %V, 0
2742 %add6 = add nsw i16 %V, 1
2743 %cmp = icmp slt i16 %add5, %add6
2747 define i1 @icmp_nsw_i64(i64 %V) {
2748 ; CHECK-LABEL: @icmp_nsw_i64(
2749 ; CHECK-NEXT: ret i1 true
2751 %add5 = add i64 %V, 5
2752 %add6 = add nsw i64 %V, 6
2753 %cmp = icmp slt i64 %add5, %add6
2757 define <4 x i1> @icmp_nsw_vec(<4 x i32> %V) {
2758 ; CHECK-LABEL: @icmp_nsw_vec(
2759 ; CHECK-NEXT: ret <4 x i1> splat (i1 true)
2761 %add5 = add <4 x i32> %V, <i32 5, i32 5, i32 5, i32 5>
2762 %add6 = add nsw <4 x i32> %V, <i32 6, i32 6, i32 6, i32 6>
2763 %cmp = icmp slt <4 x i32> %add5, %add6
2767 define i1 @icmp_nsw_3(i32 %V) {
2768 ; CHECK-LABEL: @icmp_nsw_3(
2769 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2770 ; CHECK-NEXT: [[ADD5_2:%.*]] = add nsw i32 [[V]], 5
2771 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD5_2]]
2772 ; CHECK-NEXT: ret i1 [[CMP]]
2774 %add5 = add i32 %V, 5
2775 %add5_2 = add nsw i32 %V, 5
2776 %cmp = icmp slt i32 %add5, %add5_2
2780 define i1 @icmp_nsw_4(i32 %V) {
2781 ; CHECK-LABEL: @icmp_nsw_4(
2782 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2783 ; CHECK-NEXT: [[ADD4:%.*]] = add nsw i32 [[V]], 4
2784 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD4]]
2785 ; CHECK-NEXT: ret i1 [[CMP]]
2787 %add5 = add i32 %V, 5
2788 %add4 = add nsw i32 %V, 4
2789 %cmp = icmp slt i32 %add5, %add4
2793 define i1 @icmp_nsw_5(i32 %V) {
2794 ; CHECK-LABEL: @icmp_nsw_5(
2795 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2796 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 6
2797 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2798 ; CHECK-NEXT: ret i1 [[CMP]]
2800 %add5 = add nsw i32 %V, 5
2801 %add6 = add i32 %V, 6
2802 %cmp = icmp slt i32 %add5, %add6
2806 define i1 @icmp_nsw_7(i32 %V, i32 %arg) {
2807 ; CHECK-LABEL: @icmp_nsw_7(
2808 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2809 ; CHECK-NEXT: [[ADDARG:%.*]] = add nsw i32 [[V]], [[ARG:%.*]]
2810 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADDARG]]
2811 ; CHECK-NEXT: ret i1 [[CMP]]
2813 %add5 = add i32 %V, 5
2814 %addarg = add nsw i32 %V, %arg
2815 %cmp = icmp slt i32 %add5, %addarg
2819 define i1 @icmp_nsw_8(i32 %V, i32 %arg) {
2820 ; CHECK-LABEL: @icmp_nsw_8(
2821 ; CHECK-NEXT: [[ADDARG:%.*]] = add i32 [[V:%.*]], [[ARG:%.*]]
2822 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 5
2823 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADDARG]], [[ADD6]]
2824 ; CHECK-NEXT: ret i1 [[CMP]]
2826 %addarg = add i32 %V, %arg
2827 %add6 = add nsw i32 %V, 5
2828 %cmp = icmp slt i32 %addarg, %add6
2832 define i1 @icmp_nsw_9(i32 %V1, i32 %V2) {
2833 ; CHECK-LABEL: @icmp_nsw_9(
2834 ; CHECK-NEXT: [[ADD_V1:%.*]] = add i32 [[V1:%.*]], 5
2835 ; CHECK-NEXT: [[ADD_V2:%.*]] = add nsw i32 [[V2:%.*]], 6
2836 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD_V1]], [[ADD_V2]]
2837 ; CHECK-NEXT: ret i1 [[CMP]]
2839 %add_V1 = add i32 %V1, 5
2840 %add_V2 = add nsw i32 %V2, 6
2841 %cmp = icmp slt i32 %add_V1, %add_V2
2845 define i1 @icmp_nsw_10(i32 %V) {
2846 ; CHECK-LABEL: @icmp_nsw_10(
2847 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2848 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 6
2849 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[ADD6]], [[ADD5]]
2850 ; CHECK-NEXT: ret i1 [[CMP]]
2852 %add5 = add i32 %V, 5
2853 %add6 = add nsw i32 %V, 6
2854 %cmp = icmp sgt i32 %add6, %add5
2858 define i1 @icmp_nsw_11(i32 %V) {
2859 ; CHECK-LABEL: @icmp_nsw_11(
2860 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], -125
2861 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], -99
2862 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2863 ; CHECK-NEXT: ret i1 [[CMP]]
2865 %add5 = add i32 %V, -125
2866 %add6 = add nsw i32 %V, -99
2867 %cmp = icmp slt i32 %add5, %add6
2871 define i1 @icmp_nsw_nonpos(i32 %V) {
2872 ; CHECK-LABEL: @icmp_nsw_nonpos(
2873 ; CHECK-NEXT: ret i1 false
2875 %add5 = add i32 %V, 0
2876 %add6 = add nsw i32 %V, -1
2877 %cmp = icmp slt i32 %add5, %add6
2881 define i1 @icmp_nsw_nonpos2(i32 %V) {
2882 ; CHECK-LABEL: @icmp_nsw_nonpos2(
2883 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 1
2884 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[V]]
2885 ; CHECK-NEXT: ret i1 [[CMP]]
2887 %add5 = add i32 %V, 1
2888 %add6 = add nsw i32 %V, 0
2889 %cmp = icmp slt i32 %add5, %add6
2893 declare i11 @llvm.ctpop.i11(i11)
2894 declare i73 @llvm.ctpop.i73(i73)
2895 declare <2 x i13> @llvm.ctpop.v2i13(<2 x i13>)
2897 define i1 @ctpop_sgt_bitwidth(i11 %x) {
2898 ; CHECK-LABEL: @ctpop_sgt_bitwidth(
2899 ; CHECK-NEXT: ret i1 false
2901 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2902 %cmp = icmp sgt i11 %pop, 11
2906 define i1 @ctpop_sle_minus1(i11 %x) {
2907 ; CHECK-LABEL: @ctpop_sle_minus1(
2908 ; CHECK-NEXT: ret i1 false
2910 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2911 %cmp = icmp sle i11 %pop, -1
2915 define i1 @ctpop_ugt_bitwidth(i73 %x) {
2916 ; CHECK-LABEL: @ctpop_ugt_bitwidth(
2917 ; CHECK-NEXT: ret i1 false
2919 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2920 %cmp = icmp ugt i73 %pop, 73
2924 ; Negative test - does not simplify, but instcombine could reduce this.
2926 define i1 @ctpop_ugt_bitwidth_minus1(i73 %x) {
2927 ; CHECK-LABEL: @ctpop_ugt_bitwidth_minus1(
2928 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.ctpop.i73(i73 [[X:%.*]])
2929 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
2930 ; CHECK-NEXT: ret i1 [[CMP]]
2932 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2933 %cmp = icmp ugt i73 %pop, 72
2937 define <2 x i1> @ctpop_sgt_bitwidth_splat(<2 x i13> %x) {
2938 ; CHECK-LABEL: @ctpop_sgt_bitwidth_splat(
2939 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2941 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2942 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
2946 define i1 @ctpop_ult_plus1_bitwidth(i11 %x) {
2947 ; CHECK-LABEL: @ctpop_ult_plus1_bitwidth(
2948 ; CHECK-NEXT: ret i1 true
2950 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2951 %cmp = icmp ult i11 %pop, 12
2955 define i1 @ctpop_ne_big_bitwidth(i73 %x) {
2956 ; CHECK-LABEL: @ctpop_ne_big_bitwidth(
2957 ; CHECK-NEXT: ret i1 true
2959 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2960 %cmp = icmp ne i73 %pop, 75
2964 define <2 x i1> @ctpop_slt_bitwidth_plus1_splat(<2 x i13> %x) {
2965 ; CHECK-LABEL: @ctpop_slt_bitwidth_plus1_splat(
2966 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
2968 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2969 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
2973 ; Negative test - does not simplify, but instcombine could reduce this.
2975 define <2 x i1> @ctpop_slt_bitwidth_splat(<2 x i13> %x) {
2976 ; CHECK-LABEL: @ctpop_slt_bitwidth_splat(
2977 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> [[X:%.*]])
2978 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], splat (i13 13)
2979 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2981 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2982 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
2986 declare i11 @llvm.ctlz.i11(i11)
2987 declare i73 @llvm.ctlz.i73(i73)
2988 declare <2 x i13> @llvm.ctlz.v2i13(<2 x i13>)
2990 define i1 @ctlz_sgt_bitwidth(i11 %x) {
2991 ; CHECK-LABEL: @ctlz_sgt_bitwidth(
2992 ; CHECK-NEXT: ret i1 false
2994 %pop = call i11 @llvm.ctlz.i11(i11 %x)
2995 %cmp = icmp sgt i11 %pop, 11
2999 define i1 @ctlz_sle_minus1(i11 %x) {
3000 ; CHECK-LABEL: @ctlz_sle_minus1(
3001 ; CHECK-NEXT: ret i1 false
3003 %pop = call i11 @llvm.ctlz.i11(i11 %x)
3004 %cmp = icmp sle i11 %pop, -1
3008 define i1 @ctlz_ugt_bitwidth(i73 %x) {
3009 ; CHECK-LABEL: @ctlz_ugt_bitwidth(
3010 ; CHECK-NEXT: ret i1 false
3012 %pop = call i73 @llvm.ctlz.i73(i73 %x)
3013 %cmp = icmp ugt i73 %pop, 73
3017 ; Negative test - does not simplify, but instcombine could reduce this.
3019 define i1 @ctlz_ugt_bitwidth_minus1(i73 %x) {
3020 ; CHECK-LABEL: @ctlz_ugt_bitwidth_minus1(
3021 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.ctlz.i73(i73 [[X:%.*]], i1 false)
3022 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
3023 ; CHECK-NEXT: ret i1 [[CMP]]
3025 %pop = call i73 @llvm.ctlz.i73(i73 %x)
3026 %cmp = icmp ugt i73 %pop, 72
3030 define <2 x i1> @ctlz_sgt_bitwidth_splat(<2 x i13> %x) {
3031 ; CHECK-LABEL: @ctlz_sgt_bitwidth_splat(
3032 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
3034 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
3035 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
3039 define i1 @ctlz_ult_plus1_bitwidth(i11 %x) {
3040 ; CHECK-LABEL: @ctlz_ult_plus1_bitwidth(
3041 ; CHECK-NEXT: ret i1 true
3043 %pop = call i11 @llvm.ctlz.i11(i11 %x)
3044 %cmp = icmp ult i11 %pop, 12
3048 define i1 @ctlz_ne_big_bitwidth(i73 %x) {
3049 ; CHECK-LABEL: @ctlz_ne_big_bitwidth(
3050 ; CHECK-NEXT: ret i1 true
3052 %pop = call i73 @llvm.ctlz.i73(i73 %x)
3053 %cmp = icmp ne i73 %pop, 75
3057 define <2 x i1> @ctlz_slt_bitwidth_plus1_splat(<2 x i13> %x) {
3058 ; CHECK-LABEL: @ctlz_slt_bitwidth_plus1_splat(
3059 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
3061 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
3062 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
3066 ; Negative test - does not simplify, but instcombine could reduce this.
3068 define <2 x i1> @ctlz_slt_bitwidth_splat(<2 x i13> %x) {
3069 ; CHECK-LABEL: @ctlz_slt_bitwidth_splat(
3070 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> [[X:%.*]], i1 false)
3071 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], splat (i13 13)
3072 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
3074 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
3075 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
3079 declare i11 @llvm.cttz.i11(i11)
3080 declare i73 @llvm.cttz.i73(i73)
3081 declare <2 x i13> @llvm.cttz.v2i13(<2 x i13>)
3083 define i1 @cttz_sgt_bitwidth(i11 %x) {
3084 ; CHECK-LABEL: @cttz_sgt_bitwidth(
3085 ; CHECK-NEXT: ret i1 false
3087 %pop = call i11 @llvm.cttz.i11(i11 %x)
3088 %cmp = icmp sgt i11 %pop, 11
3092 define i1 @cttz_sle_minus1(i11 %x) {
3093 ; CHECK-LABEL: @cttz_sle_minus1(
3094 ; CHECK-NEXT: ret i1 false
3096 %pop = call i11 @llvm.cttz.i11(i11 %x)
3097 %cmp = icmp sle i11 %pop, -1
3101 define i1 @cttz_ugt_bitwidth(i73 %x) {
3102 ; CHECK-LABEL: @cttz_ugt_bitwidth(
3103 ; CHECK-NEXT: ret i1 false
3105 %pop = call i73 @llvm.cttz.i73(i73 %x)
3106 %cmp = icmp ugt i73 %pop, 73
3110 ; Negative test - does not simplify, but instcombine could reduce this.
3112 define i1 @cttz_ugt_bitwidth_minus1(i73 %x) {
3113 ; CHECK-LABEL: @cttz_ugt_bitwidth_minus1(
3114 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.cttz.i73(i73 [[X:%.*]], i1 false)
3115 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
3116 ; CHECK-NEXT: ret i1 [[CMP]]
3118 %pop = call i73 @llvm.cttz.i73(i73 %x)
3119 %cmp = icmp ugt i73 %pop, 72
3123 define <2 x i1> @cttz_sgt_bitwidth_splat(<2 x i13> %x) {
3124 ; CHECK-LABEL: @cttz_sgt_bitwidth_splat(
3125 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
3127 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
3128 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
3132 define i1 @cttz_ult_plus1_bitwidth(i11 %x) {
3133 ; CHECK-LABEL: @cttz_ult_plus1_bitwidth(
3134 ; CHECK-NEXT: ret i1 true
3136 %pop = call i11 @llvm.cttz.i11(i11 %x)
3137 %cmp = icmp ult i11 %pop, 12
3141 define i1 @cttz_ne_big_bitwidth(i73 %x) {
3142 ; CHECK-LABEL: @cttz_ne_big_bitwidth(
3143 ; CHECK-NEXT: ret i1 true
3145 %pop = call i73 @llvm.cttz.i73(i73 %x)
3146 %cmp = icmp ne i73 %pop, 75
3150 define <2 x i1> @cttz_slt_bitwidth_plus1_splat(<2 x i13> %x) {
3151 ; CHECK-LABEL: @cttz_slt_bitwidth_plus1_splat(
3152 ; CHECK-NEXT: ret <2 x i1> splat (i1 true)
3154 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
3155 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
3159 ; Negative test - does not simplify, but instcombine could reduce this.
3161 define <2 x i1> @cttz_slt_bitwidth_splat(<2 x i13> %x) {
3162 ; CHECK-LABEL: @cttz_slt_bitwidth_splat(
3163 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> [[X:%.*]], i1 false)
3164 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], splat (i13 13)
3165 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
3167 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
3168 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
3172 ; A zero sized alloca *can* be equal to another alloca
3173 define i1 @zero_sized_alloca1() {
3174 ; CHECK-LABEL: @zero_sized_alloca1(
3175 ; CHECK-NEXT: [[A:%.*]] = alloca i32, i32 0, align 4
3176 ; CHECK-NEXT: [[B:%.*]] = alloca i32, i32 0, align 4
3177 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A]], [[B]]
3178 ; CHECK-NEXT: ret i1 [[RES]]
3180 %a = alloca i32, i32 0
3181 %b = alloca i32, i32 0
3182 %res = icmp ne ptr %a, %b
3186 define i1 @zero_sized_alloca2() {
3187 ; CHECK-LABEL: @zero_sized_alloca2(
3188 ; CHECK-NEXT: [[A:%.*]] = alloca i32, i32 0, align 4
3189 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
3190 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A]], [[B]]
3191 ; CHECK-NEXT: ret i1 [[RES]]
3193 %a = alloca i32, i32 0
3195 %res = icmp ne ptr %a, %b
3199 define i1 @scalar_vectors_are_non_empty() {
3200 ; CHECK-LABEL: @scalar_vectors_are_non_empty(
3201 ; CHECK-NEXT: ret i1 true
3203 %a = alloca <vscale x 2 x i32>
3204 %b = alloca <vscale x 2 x i32>
3205 %res = icmp ne ptr %a, %b
3210 define i1 @byval_args_inequal(ptr byval(i32) %a, ptr byval(i32) %b) {
3211 ; CHECK-LABEL: @byval_args_inequal(
3212 ; CHECK-NEXT: ret i1 true
3214 %res = icmp ne ptr %a, %b
3218 ; Arguments can be adjacent on the stack
3219 define i1 @neg_args_adjacent(ptr byval(i32) %a, ptr byval(i32) %b) {
3220 ; CHECK-LABEL: @neg_args_adjacent(
3221 ; CHECK-NEXT: [[A_OFF:%.*]] = getelementptr i32, ptr [[A:%.*]], i32 1
3222 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A_OFF]], [[B:%.*]]
3223 ; CHECK-NEXT: ret i1 [[RES]]
3225 %a.off = getelementptr i32, ptr %a, i32 1
3226 %res = icmp ne ptr %a.off, %b
3231 define i1 @test_byval_alloca_inequal(ptr byval(i32) %a) {
3232 ; CHECK-LABEL: @test_byval_alloca_inequal(
3233 ; CHECK-NEXT: ret i1 true
3236 %res = icmp ne ptr %a, %b
3240 ; Byval argument can be immediately before alloca, and crossing
3242 define i1 @neg_byval_alloca_adjacent(ptr byval(i32) %a) {
3243 ; CHECK-LABEL: @neg_byval_alloca_adjacent(
3244 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
3245 ; CHECK-NEXT: [[A_OFF:%.*]] = getelementptr i32, ptr [[A:%.*]], i32 1
3246 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr [[A_OFF]], [[B]]
3247 ; CHECK-NEXT: ret i1 [[RES]]
3250 %a.off = getelementptr i32, ptr %a, i32 1
3251 %res = icmp ne ptr %a.off, %b
3257 @A.alias = alias i32, ptr @A
3259 define i1 @globals_inequal() {
3260 ; CHECK-LABEL: @globals_inequal(
3261 ; CHECK-NEXT: ret i1 true
3263 %res = icmp ne ptr @A, @B
3268 define i1 @globals_offset_inequal() {
3269 ; CHECK-LABEL: @globals_offset_inequal(
3270 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr getelementptr inbounds (i8, ptr @A, i32 1), getelementptr inbounds (i8, ptr @B, i32 1)
3271 ; CHECK-NEXT: ret i1 [[RES]]
3273 %a.off = getelementptr i8, ptr @A, i32 1
3274 %b.off = getelementptr i8, ptr @B, i32 1
3275 %res = icmp ne ptr %a.off, %b.off
3281 define i1 @test_byval_global_inequal(ptr byval(i32) %a) {
3282 ; CHECK-LABEL: @test_byval_global_inequal(
3283 ; CHECK-NEXT: ret i1 true
3286 %res = icmp ne ptr %a, @B
3291 define i1 @neg_global_alias() {
3292 ; CHECK-LABEL: @neg_global_alias(
3293 ; CHECK-NEXT: [[RES:%.*]] = icmp ne ptr @A, @A.alias
3294 ; CHECK-NEXT: ret i1 [[RES]]
3296 %res = icmp ne ptr @A, @A.alias
3301 define i1 @icmp_lshr_known_non_zero_ult_true(i8 %x) {
3302 ; CHECK-LABEL: @icmp_lshr_known_non_zero_ult_true(
3303 ; CHECK-NEXT: ret i1 true
3306 %x1 = shl nuw i8 %or, 1
3307 %x2 = shl nuw i8 %or, 2
3308 %cmp = icmp ult i8 %x1, %x2
3312 define i1 @icmp_lshr_known_non_zero_ult_false(i8 %x) {
3313 ; CHECK-LABEL: @icmp_lshr_known_non_zero_ult_false(
3314 ; CHECK-NEXT: ret i1 false
3317 %x1 = shl nuw i8 %or, 1
3318 %x2 = shl nuw i8 %or, 2
3319 %cmp = icmp ugt i8 %x1, %x2
3323 define i1 @icmp_lshr_known_non_zero_slt_true(i8 %x) {
3324 ; CHECK-LABEL: @icmp_lshr_known_non_zero_slt_true(
3325 ; CHECK-NEXT: ret i1 true
3328 %x1 = shl nuw nsw i8 %or, 1
3329 %x2 = shl nuw nsw i8 %or, 2
3330 %cmp = icmp slt i8 %x1, %x2
3334 define i1 @icmp_lshr_known_non_zero_slt_false(i8 %x) {
3335 ; CHECK-LABEL: @icmp_lshr_known_non_zero_slt_false(
3336 ; CHECK-NEXT: ret i1 false
3339 %x1 = shl nuw nsw i8 %or, 2
3340 %x2 = shl nuw nsw i8 %or, 1
3341 %cmp = icmp slt i8 %x1, %x2
3345 define i1 @neg_icmp_lshr_known_non_zero_slt_no_nsw(i8 %x) {
3346 ; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_slt_no_nsw(
3347 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3348 ; CHECK-NEXT: [[X1:%.*]] = shl nuw i8 [[OR]], 1
3349 ; CHECK-NEXT: [[X2:%.*]] = shl nuw i8 [[OR]], 2
3350 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
3351 ; CHECK-NEXT: ret i1 [[CMP]]
3354 %x1 = shl nuw i8 %or, 1
3355 %x2 = shl nuw i8 %or, 2
3356 %cmp = icmp slt i8 %x1, %x2
3360 define i1 @neg_icmp_lshr_known_non_zero_ult_no_nuw(i8 %x) {
3361 ; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_ult_no_nuw(
3362 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3363 ; CHECK-NEXT: [[X1:%.*]] = shl i8 [[OR]], 1
3364 ; CHECK-NEXT: [[X2:%.*]] = shl i8 [[OR]], 2
3365 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X1]], [[X2]]
3366 ; CHECK-NEXT: ret i1 [[CMP]]
3371 %cmp = icmp ult i8 %x1, %x2
3375 define i1 @neg_icmp_lshr_known_non_zero_slt_no_nuw(i8 %x) {
3376 ; CHECK-LABEL: @neg_icmp_lshr_known_non_zero_slt_no_nuw(
3377 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3378 ; CHECK-NEXT: [[X1:%.*]] = shl nsw i8 [[OR]], 1
3379 ; CHECK-NEXT: [[X2:%.*]] = shl nsw i8 [[OR]], 2
3380 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X1]], [[X2]]
3381 ; CHECK-NEXT: ret i1 [[CMP]]
3384 %x1 = shl nsw i8 %or, 1
3385 %x2 = shl nsw i8 %or, 2
3386 %cmp = icmp slt i8 %x1, %x2
3390 define i1 @neg_icmp_lshr_unknown_value(i8 %x) {
3391 ; CHECK-LABEL: @neg_icmp_lshr_unknown_value(
3392 ; CHECK-NEXT: [[X1:%.*]] = shl nuw i8 [[X:%.*]], 2
3393 ; CHECK-NEXT: [[X2:%.*]] = shl nuw i8 [[X]], 1
3394 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X1]], [[X2]]
3395 ; CHECK-NEXT: ret i1 [[CMP]]
3397 %x1 = shl nuw i8 %x, 2
3398 %x2 = shl nuw i8 %x, 1
3399 %cmp = icmp ugt i8 %x1, %x2
3403 define i1 @neg_icmp_lshr_unknown_shift(i8 %x, i8 %C1) {
3404 ; CHECK-LABEL: @neg_icmp_lshr_unknown_shift(
3405 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[X:%.*]], 1
3406 ; CHECK-NEXT: [[X1:%.*]] = shl nuw i8 [[OR]], 2
3407 ; CHECK-NEXT: [[X2:%.*]] = shl nuw i8 [[OR]], [[C1:%.*]]
3408 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X1]], [[X2]]
3409 ; CHECK-NEXT: ret i1 [[CMP]]
3412 %x1 = shl nuw i8 %or, 2
3413 %x2 = shl nuw i8 %or, %C1
3414 %cmp = icmp ugt i8 %x1, %x2
3418 define i1 @neg_icmp_lshr_different_shift_values(i8 %x, i8 %y) {
3419 ; CHECK-LABEL: @neg_icmp_lshr_different_shift_values(
3420 ; CHECK-NEXT: [[X1:%.*]] = shl nuw nsw i8 [[X:%.*]], 1
3421 ; CHECK-NEXT: [[X2:%.*]] = shl nuw nsw i8 [[Y:%.*]], 2
3422 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X1]], [[X2]]
3423 ; CHECK-NEXT: ret i1 [[CMP]]
3425 %x1 = shl nuw nsw i8 %x, 1
3426 %x2 = shl nuw nsw i8 %y, 2
3427 %cmp = icmp ult i8 %x1, %x2
3431 define i1 @icmp_ult_vscale_true(i8 %x, i8 %y) {
3432 ; CHECK-LABEL: @icmp_ult_vscale_true(
3433 ; CHECK-NEXT: ret i1 true
3435 %vscale = call i64 @llvm.vscale.i64()
3436 %x1 = shl nuw nsw i64 %vscale, 1
3437 %x2 = shl nuw nsw i64 %vscale, 2
3438 %cmp = icmp ult i64 %x1, %x2
3442 define i1 @icmp_ult_vscale_false(i8 %x, i8 %y) {
3443 ; CHECK-LABEL: @icmp_ult_vscale_false(
3444 ; CHECK-NEXT: ret i1 false
3446 %vscale = call i64 @llvm.vscale.i64()
3447 %x1 = shl nuw nsw i64 %vscale, 1
3448 %x2 = shl nuw nsw i64 %vscale, 2
3449 %cmp = icmp ugt i64 %x1, %x2
3453 declare i64 @llvm.vscale.i64()
3455 ; TODO: Add coverage for global aliases, link once, etc..
3458 attributes #0 = { null_pointer_is_valid }