1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
3 target datalayout = "p:32:32-p1:64:64"
5 define i1 @ptrtoint() {
6 ; CHECK-LABEL: @ptrtoint(
7 ; CHECK-NEXT: ret i1 false
10 %tmp = ptrtoint i8* %a to i32
11 %r = icmp eq i32 %tmp, 0
15 define i1 @bitcast() {
16 ; CHECK-LABEL: @bitcast(
17 ; CHECK-NEXT: ret i1 false
21 %x = bitcast i32* %a to i8*
22 %y = bitcast i64* %b to i8*
23 %cmp = icmp eq i8* %x, %y
29 ; CHECK-NEXT: ret i1 false
31 %a = alloca [3 x i8], align 8
32 %x = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0
33 %cmp = icmp eq i8* %x, null
39 ; CHECK-NEXT: ret i1 true
41 %a = alloca [3 x i8], align 8
42 %x = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0
43 %y = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0
44 %cmp = icmp eq i8* %x, %y
49 %gept = type { i32, i32 }
50 @gepy = global %gept zeroinitializer, align 8
51 @gepz = extern_weak global %gept
55 ; CHECK-NEXT: ret i1 false
57 %x = alloca %gept, align 8
58 %a = getelementptr %gept, %gept* %x, i64 0, i32 0
59 %b = getelementptr %gept, %gept* %x, i64 0, i32 1
60 %equal = icmp eq i32* %a, %b
66 ; CHECK-NEXT: ret i1 false
68 %x = alloca %gept, align 8
69 %a = getelementptr %gept, %gept* @gepy, i64 0, i32 0
70 %b = getelementptr %gept, %gept* @gepy, i64 0, i32 1
71 %equal = icmp eq i32* %a, %b
75 @a = common global [1 x i32] zeroinitializer, align 4
77 define i1 @PR31262() {
78 ; CHECK-LABEL: @PR31262(
79 ; CHECK-NEXT: ret i1 icmp uge (i32* getelementptr ([1 x i32], [1 x i32]* @a, i32 0, i32 undef), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0))
81 %idx = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 undef
82 %cmp = icmp uge i32* %idx, getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0)
88 ; CHECK-NEXT: ret i1 false
90 %x = alloca %gept, align 8
91 %a = getelementptr inbounds %gept, %gept* %x, i64 0, i32 1
92 %b = getelementptr %gept, %gept* @gepy, i64 0, i32 0
93 %equal = icmp eq i32* %a, %b
97 define i1 @gep6(%gept* %x) {
98 ; Same as @gep3 but potentially null.
100 ; CHECK-NEXT: ret i1 false
102 %a = getelementptr %gept, %gept* %x, i64 0, i32 0
103 %b = getelementptr %gept, %gept* %x, i64 0, i32 1
104 %equal = icmp eq i32* %a, %b
108 define i1 @gep7(%gept* %x) {
109 ; CHECK-LABEL: @gep7(
110 ; CHECK-NEXT: [[A:%.*]] = getelementptr [[GEPT:%.*]], %gept* [[X:%.*]], i64 0, i32 0
111 ; CHECK-NEXT: [[EQUAL:%.*]] = icmp eq i32* [[A]], getelementptr (%gept, %gept* @gepz, i32 0, i32 0)
112 ; CHECK-NEXT: ret i1 [[EQUAL]]
114 %a = getelementptr %gept, %gept* %x, i64 0, i32 0
115 %b = getelementptr %gept, %gept* @gepz, i64 0, i32 0
116 %equal = icmp eq i32* %a, %b
120 define i1 @gep8(%gept* %x) {
121 ; CHECK-LABEL: @gep8(
122 ; CHECK-NEXT: [[A:%.*]] = getelementptr [[GEPT:%.*]], %gept* [[X:%.*]], i32 1
123 ; CHECK-NEXT: [[B:%.*]] = getelementptr [[GEPT]], %gept* [[X]], i32 -1
124 ; CHECK-NEXT: [[EQUAL:%.*]] = icmp ugt %gept* [[A]], [[B]]
125 ; CHECK-NEXT: ret i1 [[EQUAL]]
127 %a = getelementptr %gept, %gept* %x, i32 1
128 %b = getelementptr %gept, %gept* %x, i32 -1
129 %equal = icmp ugt %gept* %a, %b
133 define i1 @gep9(i8* %ptr) {
134 ; CHECK-LABEL: @gep9(
136 ; CHECK-NEXT: ret i1 true
139 %first1 = getelementptr inbounds i8, i8* %ptr, i32 0
140 %first2 = getelementptr inbounds i8, i8* %first1, i32 1
141 %first3 = getelementptr inbounds i8, i8* %first2, i32 2
142 %first4 = getelementptr inbounds i8, i8* %first3, i32 4
143 %last1 = getelementptr inbounds i8, i8* %first2, i32 48
144 %last2 = getelementptr inbounds i8, i8* %last1, i32 8
145 %last3 = getelementptr inbounds i8, i8* %last2, i32 -4
146 %last4 = getelementptr inbounds i8, i8* %last3, i32 -4
147 %first.int = ptrtoint i8* %first4 to i32
148 %last.int = ptrtoint i8* %last4 to i32
149 %cmp = icmp ne i32 %last.int, %first.int
153 define i1 @gep10(i8* %ptr) {
154 ; CHECK-LABEL: @gep10(
156 ; CHECK-NEXT: ret i1 true
159 %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2
160 %first2 = getelementptr inbounds i8, i8* %first1, i32 44
161 %last1 = getelementptr inbounds i8, i8* %ptr, i32 48
162 %last2 = getelementptr inbounds i8, i8* %last1, i32 -6
163 %first.int = ptrtoint i8* %first2 to i32
164 %last.int = ptrtoint i8* %last2 to i32
165 %cmp = icmp eq i32 %last.int, %first.int
169 define i1 @gep11(i8* %ptr) {
170 ; CHECK-LABEL: @gep11(
172 ; CHECK-NEXT: ret i1 true
175 %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2
176 %last1 = getelementptr inbounds i8, i8* %ptr, i32 48
177 %last2 = getelementptr inbounds i8, i8* %last1, i32 -6
178 %cmp = icmp ult i8* %first1, %last2
182 define i1 @gep12(i8* %ptr) {
183 ; CHECK-LABEL: @gep12(
185 ; CHECK-NEXT: [[FIRST1:%.*]] = getelementptr inbounds i8, i8* [[PTR:%.*]], i32 -2
186 ; CHECK-NEXT: [[LAST1:%.*]] = getelementptr inbounds i8, i8* [[PTR]], i32 48
187 ; CHECK-NEXT: [[LAST2:%.*]] = getelementptr inbounds i8, i8* [[LAST1]], i32 -6
188 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8* [[FIRST1]], [[LAST2]]
189 ; CHECK-NEXT: ret i1 [[CMP]]
192 %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2
193 %last1 = getelementptr inbounds i8, i8* %ptr, i32 48
194 %last2 = getelementptr inbounds i8, i8* %last1, i32 -6
195 %cmp = icmp slt i8* %first1, %last2
199 define i1 @gep13(i8* %ptr) {
200 ; CHECK-LABEL: @gep13(
201 ; CHECK-NEXT: ret i1 false
203 ; We can prove this GEP is non-null because it is inbounds.
204 %x = getelementptr inbounds i8, i8* %ptr, i32 1
205 %cmp = icmp eq i8* %x, null
209 define i1 @gep13_no_null_opt(i8* %ptr) #0 {
210 ; We can't prove this GEP is non-null.
211 ; CHECK-LABEL: @gep13_no_null_opt(
212 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds i8, i8* [[PTR:%.*]], i32 1
213 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[X]], null
214 ; CHECK-NEXT: ret i1 [[CMP]]
216 %x = getelementptr inbounds i8, i8* %ptr, i32 1
217 %cmp = icmp eq i8* %x, null
221 define i1 @gep14({ {}, i8 }* %ptr) {
222 ; CHECK-LABEL: @gep14(
223 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds { {}, i8 }, { {}, i8 }* [[PTR:%.*]], i32 0, i32 1
224 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[X]], null
225 ; CHECK-NEXT: ret i1 [[CMP]]
227 ; We can't simplify this because the offset of one in the GEP actually doesn't
229 %x = getelementptr inbounds { {}, i8 }, { {}, i8 }* %ptr, i32 0, i32 1
230 %cmp = icmp eq i8* %x, null
234 define i1 @gep15({ {}, [4 x {i8, i8}]}* %ptr, i32 %y) {
235 ; CHECK-LABEL: @gep15(
236 ; CHECK-NEXT: ret i1 false
238 ; We can prove this GEP is non-null even though there is a user value, as we
239 ; would necessarily violate inbounds on one side or the other.
240 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, { {}, [4 x {i8, i8}]}* %ptr, i32 0, i32 1, i32 %y, i32 1
241 %cmp = icmp eq i8* %x, null
245 define i1 @gep15_no_null_opt({ {}, [4 x {i8, i8}]}* %ptr, i32 %y) #0 {
246 ; We can't prove this GEP is non-null.
247 ; CHECK-LABEL: @gep15_no_null_opt(
248 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds { {}, [4 x { i8, i8 }] }, { {}, [4 x { i8, i8 }] }* [[PTR:%.*]], i32 0, i32 1, i32 [[Y:%.*]], i32 1
249 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[X]], null
250 ; CHECK-NEXT: ret i1 [[CMP]]
252 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, { {}, [4 x {i8, i8}]}* %ptr, i32 0, i32 1, i32 %y, i32 1
253 %cmp = icmp eq i8* %x, null
257 define i1 @gep16(i8* %ptr, i32 %a) {
258 ; CHECK-LABEL: @gep16(
259 ; CHECK-NEXT: ret i1 false
261 ; We can prove this GEP is non-null because it is inbounds and because we know
262 ; %b is non-zero even though we don't know its value.
264 %x = getelementptr inbounds i8, i8* %ptr, i32 %b
265 %cmp = icmp eq i8* %x, null
269 define i1 @gep16_no_null_opt(i8* %ptr, i32 %a) #0 {
270 ; We can't prove this GEP is non-null.
271 ; CHECK-LABEL: @gep16_no_null_opt(
272 ; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 1
273 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds i8, i8* [[PTR:%.*]], i32 [[B]]
274 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[X]], null
275 ; CHECK-NEXT: ret i1 [[CMP]]
278 %x = getelementptr inbounds i8, i8* %ptr, i32 %b
279 %cmp = icmp eq i8* %x, null
284 ; CHECK-LABEL: @gep17(
285 ; CHECK-NEXT: ret i1 true
287 %alloca = alloca i32, align 4
288 %bc = bitcast i32* %alloca to [4 x i8]*
289 %gep1 = getelementptr inbounds i32, i32* %alloca, i32 1
290 %pti1 = ptrtoint i32* %gep1 to i32
291 %gep2 = getelementptr inbounds [4 x i8], [4 x i8]* %bc, i32 0, i32 1
292 %pti2 = ptrtoint i8* %gep2 to i32
293 %cmp = icmp ugt i32 %pti1, %pti2
297 define i1 @gep_same_base_constant_indices(i8* %a) {
298 ; CHECK-LABEL: @gep_same_base_constant_indices(
299 ; CHECK-NEXT: ret i1 true
301 %arrayidx1 = getelementptr inbounds i8, i8* %a, i64 1
302 %arrayidx2 = getelementptr inbounds i8, i8* %a, i64 10
303 %cmp = icmp slt i8* %arrayidx1, %arrayidx2
307 define i1 @zext(i32 %x) {
308 ; CHECK-LABEL: @zext(
309 ; CHECK-NEXT: ret i1 true
311 %e1 = zext i32 %x to i64
312 %e2 = zext i32 %x to i64
313 %r = icmp eq i64 %e1, %e2
317 define i1 @zext2(i1 %x) {
318 ; CHECK-LABEL: @zext2(
319 ; CHECK-NEXT: ret i1 [[X:%.*]]
321 %e = zext i1 %x to i32
322 %c = icmp ne i32 %e, 0
327 ; CHECK-LABEL: @zext3(
328 ; CHECK-NEXT: ret i1 true
330 %e = zext i1 1 to i32
331 %c = icmp ne i32 %e, 0
335 define i1 @sext(i32 %x) {
336 ; CHECK-LABEL: @sext(
337 ; CHECK-NEXT: ret i1 true
339 %e1 = sext i32 %x to i64
340 %e2 = sext i32 %x to i64
341 %r = icmp eq i64 %e1, %e2
345 define i1 @sext2(i1 %x) {
346 ; CHECK-LABEL: @sext2(
347 ; CHECK-NEXT: ret i1 [[X:%.*]]
349 %e = sext i1 %x to i32
350 %c = icmp ne i32 %e, 0
355 ; CHECK-LABEL: @sext3(
356 ; CHECK-NEXT: ret i1 true
358 %e = sext i1 1 to i32
359 %c = icmp ne i32 %e, 0
363 define i1 @add(i32 %x, i32 %y) {
365 ; CHECK-NEXT: ret i1 false
371 %c = icmp eq i32 %s, 0
375 define i1 @addv(<2 x i32> %x, <2 x i32> %y) {
376 ; CHECK-LABEL: @addv(
377 ; CHECK-NEXT: ret i1 false
379 %l = lshr <2 x i32> %x, <i32 1, i32 0>
380 %q = lshr <2 x i32> %y, <i32 1, i32 0>
381 %r = or <2 x i32> %q, <i32 1, i32 0>
382 %s = add <2 x i32> %l, %r
383 %e = extractelement <2 x i32> %s, i32 0
384 %c = icmp eq i32 %e, 0
388 define i1 @add2(i8 %x, i8 %y) {
389 ; CHECK-LABEL: @add2(
390 ; CHECK-NEXT: ret i1 false
395 %c = icmp eq i8 %s, 0
399 define i1 @add2v(<2 x i8> %x, <2 x i8> %y) {
400 ; CHECK-LABEL: @add2v(
401 ; CHECK-NEXT: ret i1 false
403 %l = or <2 x i8> %x, <i8 0, i8 128>
404 %r = or <2 x i8> %y, <i8 0, i8 129>
405 %s = add <2 x i8> %l, %r
406 %e = extractelement <2 x i8> %s, i32 1
407 %c = icmp eq i8 %e, 0
411 define i1 @add3(i8 %x, i8 %y) {
412 ; CHECK-LABEL: @add3(
413 ; CHECK-NEXT: [[L:%.*]] = zext i8 [[X:%.*]] to i32
414 ; CHECK-NEXT: [[R:%.*]] = zext i8 [[Y:%.*]] to i32
415 ; CHECK-NEXT: [[S:%.*]] = add i32 [[L]], [[R]]
416 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[S]], 0
417 ; CHECK-NEXT: ret i1 [[C]]
419 %l = zext i8 %x to i32
420 %r = zext i8 %y to i32
422 %c = icmp eq i32 %s, 0
426 define i1 @add4(i32 %x, i32 %y) {
427 ; CHECK-LABEL: @add4(
428 ; CHECK-NEXT: ret i1 true
430 %z = add nsw i32 %y, 1
431 %s1 = add nsw i32 %x, %y
432 %s2 = add nsw i32 %x, %z
433 %c = icmp slt i32 %s1, %s2
437 define i1 @add5(i32 %x, i32 %y) {
438 ; CHECK-LABEL: @add5(
439 ; CHECK-NEXT: ret i1 true
441 %z = add nuw i32 %y, 1
442 %s1 = add nuw i32 %x, %z
443 %s2 = add nuw i32 %x, %y
444 %c = icmp ugt i32 %s1, %s2
448 define i1 @add6(i64 %A, i64 %B) {
449 ; CHECK-LABEL: @add6(
450 ; CHECK-NEXT: ret i1 true
454 %cmp = icmp eq i64 %s1, %s2
458 define i1 @addpowtwo(i32 %x, i32 %y) {
459 ; CHECK-LABEL: @addpowtwo(
460 ; CHECK-NEXT: ret i1 false
465 %c = icmp eq i32 %s, 0
469 define i1 @addpowtwov(<2 x i32> %x, <2 x i32> %y) {
470 ; CHECK-LABEL: @addpowtwov(
471 ; CHECK-NEXT: [[L:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 1, i32 0>
472 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i32> <i32 1, i32 0>, [[Y:%.*]]
473 ; CHECK-NEXT: [[S:%.*]] = add <2 x i32> [[L]], [[R]]
474 ; CHECK-NEXT: [[E:%.*]] = extractelement <2 x i32> [[S]], i32 0
475 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[E]], 0
476 ; CHECK-NEXT: ret i1 [[C]]
478 %l = lshr <2 x i32> %x, <i32 1, i32 0>
479 %r = shl <2 x i32> <i32 1, i32 0>, %y
480 %s = add <2 x i32> %l, %r
481 %e = extractelement <2 x i32> %s, i32 0
482 %c = icmp eq i32 %e, 0
486 define i1 @or(i32 %x) {
488 ; CHECK-NEXT: ret i1 false
491 %c = icmp eq i32 %o, 0
495 ; Do not simplify if we cannot guarantee that the ConstantExpr is a non-zero
497 @GV = common global i32* null
498 define i1 @or_constexp(i32 %x) {
499 ; CHECK-LABEL: @or_constexp(
501 ; CHECK-NEXT: [[O:%.*]] = or i32 [[X:%.*]], and (i32 ptrtoint (i32** @GV to i32), i32 32)
502 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[O]], 0
503 ; CHECK-NEXT: ret i1 [[C]]
506 %0 = and i32 ptrtoint (i32** @GV to i32), 32
508 %c = icmp eq i32 %o, 0
512 define i1 @shl1(i32 %x) {
513 ; CHECK-LABEL: @shl1(
514 ; CHECK-NEXT: ret i1 false
517 %c = icmp eq i32 %s, 0
521 define i1 @lshr1(i32 %x) {
522 ; CHECK-LABEL: @lshr1(
523 ; CHECK-NEXT: ret i1 false
526 %c = icmp eq i32 %s, 0
530 define i1 @lshr3(i32 %x) {
531 ; CHECK-LABEL: @lshr3(
532 ; CHECK-NEXT: ret i1 true
535 %c = icmp eq i32 %s, 0
539 define i1 @lshr4(i32 %X, i32 %Y) {
540 ; CHECK-LABEL: @lshr4(
541 ; CHECK-NEXT: ret i1 true
544 %C = icmp ule i32 %A, %X
548 define i1 @lshr5(i32 %X, i32 %Y) {
549 ; CHECK-LABEL: @lshr5(
550 ; CHECK-NEXT: ret i1 false
553 %C = icmp ugt i32 %A, %X
557 define i1 @lshr6(i32 %X, i32 %Y) {
558 ; CHECK-LABEL: @lshr6(
559 ; CHECK-NEXT: ret i1 false
562 %C = icmp ult i32 %X, %A
566 define i1 @lshr7(i32 %X, i32 %Y) {
567 ; CHECK-LABEL: @lshr7(
568 ; CHECK-NEXT: ret i1 true
571 %C = icmp uge i32 %X, %A
575 define i1 @ashr1(i32 %x) {
576 ; CHECK-LABEL: @ashr1(
577 ; CHECK-NEXT: ret i1 false
580 %c = icmp eq i32 %s, 0
584 define i1 @ashr3(i32 %x) {
585 ; CHECK-LABEL: @ashr3(
586 ; CHECK-NEXT: ret i1 true
589 %c = icmp eq i32 %s, 0
593 define i1 @select1(i1 %cond) {
594 ; CHECK-LABEL: @select1(
595 ; CHECK-NEXT: ret i1 [[COND:%.*]]
597 %s = select i1 %cond, i32 1, i32 0
598 %c = icmp eq i32 %s, 1
602 define i1 @select2(i1 %cond) {
603 ; CHECK-LABEL: @select2(
604 ; CHECK-NEXT: ret i1 [[COND:%.*]]
606 %x = zext i1 %cond to i32
607 %s = select i1 %cond, i32 %x, i32 0
608 %c = icmp ne i32 %s, 0
612 define i1 @select3(i1 %cond) {
613 ; CHECK-LABEL: @select3(
614 ; CHECK-NEXT: ret i1 [[COND:%.*]]
616 %x = zext i1 %cond to i32
617 %s = select i1 %cond, i32 1, i32 %x
618 %c = icmp ne i32 %s, 0
622 define i1 @select4(i1 %cond) {
623 ; CHECK-LABEL: @select4(
624 ; CHECK-NEXT: ret i1 [[COND:%.*]]
626 %invert = xor i1 %cond, 1
627 %s = select i1 %invert, i32 0, i32 1
628 %c = icmp ne i32 %s, 0
632 define i1 @select5(i32 %x) {
633 ; CHECK-LABEL: @select5(
634 ; CHECK-NEXT: ret i1 false
636 %c = icmp eq i32 %x, 0
637 %s = select i1 %c, i32 1, i32 %x
638 %c2 = icmp eq i32 %s, 0
642 define i1 @select6(i32 %x) {
643 ; CHECK-LABEL: @select6(
644 ; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], 0
645 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 [[X]], i32 4
646 ; CHECK-NEXT: [[C2:%.*]] = icmp eq i32 [[S]], 0
647 ; CHECK-NEXT: ret i1 [[C2]]
649 %c = icmp sgt i32 %x, 0
650 %s = select i1 %c, i32 %x, i32 4
651 %c2 = icmp eq i32 %s, 0
655 define i1 @urem1(i32 %X, i32 %Y) {
656 ; CHECK-LABEL: @urem1(
657 ; CHECK-NEXT: ret i1 true
660 %B = icmp ult i32 %A, %Y
664 define i1 @urem2(i32 %X, i32 %Y) {
665 ; CHECK-LABEL: @urem2(
666 ; CHECK-NEXT: ret i1 false
669 %B = icmp eq i32 %A, %Y
673 define i1 @urem4(i32 %X) {
674 ; CHECK-LABEL: @urem4(
675 ; CHECK-NEXT: [[A:%.*]] = urem i32 [[X:%.*]], 15
676 ; CHECK-NEXT: [[B:%.*]] = icmp ult i32 [[A]], 10
677 ; CHECK-NEXT: ret i1 [[B]]
680 %B = icmp ult i32 %A, 10
684 define i1 @urem5(i16 %X, i32 %Y) {
685 ; CHECK-LABEL: @urem5(
686 ; CHECK-NEXT: [[A:%.*]] = zext i16 [[X:%.*]] to i32
687 ; CHECK-NEXT: [[B:%.*]] = urem i32 [[A]], [[Y:%.*]]
688 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[B]], [[Y]]
689 ; CHECK-NEXT: ret i1 [[C]]
691 %A = zext i16 %X to i32
693 %C = icmp slt i32 %B, %Y
697 define i1 @urem6(i32 %X, i32 %Y) {
698 ; CHECK-LABEL: @urem6(
699 ; CHECK-NEXT: ret i1 true
702 %B = icmp ugt i32 %Y, %A
706 define i1 @urem7(i32 %X) {
707 ; CHECK-LABEL: @urem7(
708 ; CHECK-NEXT: [[A:%.*]] = urem i32 1, [[X:%.*]]
709 ; CHECK-NEXT: [[B:%.*]] = icmp sgt i32 [[A]], [[X]]
710 ; CHECK-NEXT: ret i1 [[B]]
713 %B = icmp sgt i32 %A, %X
717 define i1 @urem8(i8 %X, i8 %Y) {
718 ; CHECK-LABEL: @urem8(
719 ; CHECK-NEXT: ret i1 true
722 %B = icmp ule i8 %A, %X
726 define i1 @urem9(i8 %X, i8 %Y) {
727 ; CHECK-LABEL: @urem9(
728 ; CHECK-NEXT: ret i1 false
731 %B = icmp ugt i8 %A, %X
735 define i1 @urem10(i8 %X, i8 %Y) {
736 ; CHECK-LABEL: @urem10(
737 ; CHECK-NEXT: ret i1 true
740 %B = icmp uge i8 %X, %A
744 define i1 @urem11(i8 %X, i8 %Y) {
745 ; CHECK-LABEL: @urem11(
746 ; CHECK-NEXT: ret i1 false
749 %B = icmp ult i8 %X, %A
754 define i1 @srem2(i16 %X, i32 %Y) {
755 ; CHECK-LABEL: @srem2(
756 ; CHECK-NEXT: ret i1 false
758 %A = zext i16 %X to i32
759 %B = add nsw i32 %A, 1
761 %D = icmp slt i32 %C, 0
765 define i1 @srem2v(<2 x i16> %X, <2 x i32> %Y) {
766 ; CHECK-LABEL: @srem2v(
767 ; CHECK-NEXT: ret i1 false
769 %A = zext <2 x i16> %X to <2 x i32>
770 %B = add nsw <2 x i32> %A, <i32 1, i32 0>
771 %C = srem <2 x i32> %B, %Y
772 %D = extractelement <2 x i32> %C, i32 0
773 %E = icmp slt i32 %D, 0
777 define i1 @srem3(i16 %X, i32 %Y) {
778 ; CHECK-LABEL: @srem3(
779 ; CHECK-NEXT: ret i1 false
781 %A = zext i16 %X to i32
782 %B = or i32 2147483648, %A
783 %C = sub nsw i32 1, %B
785 %E = icmp slt i32 %D, 0
789 define i1 @srem3v(<2 x i16> %X, <2 x i32> %Y) {
790 ; CHECK-LABEL: @srem3v(
791 ; CHECK-NEXT: ret i1 false
793 %A = zext <2 x i16> %X to <2 x i32>
794 %B = or <2 x i32> <i32 1, i32 2147483648>, %A
795 %C = sub nsw <2 x i32> <i32 0, i32 1>, %B
796 %D = srem <2 x i32> %C, %Y
797 %E = extractelement <2 x i32> %C, i32 1
798 %F = icmp slt i32 %E, 0
802 define i1 @udiv2(i32 %Z) {
803 ; CHECK-LABEL: @udiv2(
804 ; CHECK-NEXT: ret i1 true
806 %A = udiv exact i32 10, %Z
807 %B = udiv exact i32 20, %Z
808 %C = icmp ult i32 %A, %B
812 ; Exact sdiv and equality preds can simplify.
814 define i1 @sdiv_exact_equality(i32 %Z) {
815 ; CHECK-LABEL: @sdiv_exact_equality(
816 ; CHECK-NEXT: ret i1 false
818 %A = sdiv exact i32 10, %Z
819 %B = sdiv exact i32 20, %Z
820 %C = icmp eq i32 %A, %B
824 ; But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949
826 define i1 @sdiv_exact_not_equality(i32 %Z) {
827 ; CHECK-LABEL: @sdiv_exact_not_equality(
828 ; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 10, [[Z:%.*]]
829 ; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 20, [[Z]]
830 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]]
831 ; CHECK-NEXT: ret i1 [[C]]
833 %A = sdiv exact i32 10, %Z
834 %B = sdiv exact i32 20, %Z
835 %C = icmp ult i32 %A, %B
839 define i1 @udiv3(i32 %X, i32 %Y) {
840 ; CHECK-LABEL: @udiv3(
841 ; CHECK-NEXT: ret i1 false
844 %C = icmp ugt i32 %A, %X
848 define i1 @udiv4(i32 %X, i32 %Y) {
849 ; CHECK-LABEL: @udiv4(
850 ; CHECK-NEXT: ret i1 true
853 %C = icmp ule i32 %A, %X
858 define i1 @udiv6(i32 %X) nounwind {
859 ; CHECK-LABEL: @udiv6(
860 ; CHECK-NEXT: [[A:%.*]] = udiv i32 1, [[X:%.*]]
861 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[A]], 0
862 ; CHECK-NEXT: ret i1 [[C]]
865 %C = icmp eq i32 %A, 0
869 define i1 @udiv7(i32 %X, i32 %Y) {
870 ; CHECK-LABEL: @udiv7(
871 ; CHECK-NEXT: ret i1 false
874 %C = icmp ult i32 %X, %A
878 define i1 @udiv8(i32 %X, i32 %Y) {
879 ; CHECK-LABEL: @udiv8(
880 ; CHECK-NEXT: ret i1 true
883 %C = icmp uge i32 %X, %A
887 ; Square of a non-zero number is non-zero if there is no overflow.
888 define i1 @mul1(i32 %X) {
889 ; CHECK-LABEL: @mul1(
890 ; CHECK-NEXT: ret i1 false
893 %M = mul nuw i32 %Y, %Y
894 %C = icmp eq i32 %M, 0
898 define i1 @mul1v(<2 x i32> %X) {
899 ; CHECK-LABEL: @mul1v(
900 ; CHECK-NEXT: ret i1 false
902 %Y = or <2 x i32> %X, <i32 1, i32 0>
903 %M = mul nuw <2 x i32> %Y, %Y
904 %E = extractelement <2 x i32> %M, i32 0
905 %C = icmp eq i32 %E, 0
909 ; Square of a non-zero number is positive if there is no signed overflow.
910 define i1 @mul2(i32 %X) {
911 ; CHECK-LABEL: @mul2(
912 ; CHECK-NEXT: ret i1 true
915 %M = mul nsw i32 %Y, %Y
916 %C = icmp sgt i32 %M, 0
920 define i1 @mul2v(<2 x i32> %X) {
921 ; CHECK-LABEL: @mul2v(
922 ; CHECK-NEXT: ret i1 true
924 %Y = or <2 x i32> %X, <i32 0, i32 1>
925 %M = mul nsw <2 x i32> %Y, %Y
926 %E = extractelement <2 x i32> %M, i32 1
927 %C = icmp sgt i32 %E, 0
931 ; Product of non-negative numbers is non-negative if there is no signed overflow.
932 define i1 @mul3(i32 %X, i32 %Y) {
933 ; CHECK-LABEL: @mul3(
934 ; CHECK-NEXT: ret i1 true
936 %XX = mul nsw i32 %X, %X
937 %YY = mul nsw i32 %Y, %Y
938 %M = mul nsw i32 %XX, %YY
939 %C = icmp sge i32 %M, 0
943 define <2 x i1> @mul3v(<2 x i32> %X, <2 x i32> %Y) {
944 ; CHECK-LABEL: @mul3v(
945 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
947 %XX = mul nsw <2 x i32> %X, %X
948 %YY = mul nsw <2 x i32> %Y, %Y
949 %M = mul nsw <2 x i32> %XX, %YY
950 %C = icmp sge <2 x i32> %M, zeroinitializer
954 define <2 x i1> @vectorselect1(<2 x i1> %cond) {
955 ; CHECK-LABEL: @vectorselect1(
956 ; CHECK-NEXT: ret <2 x i1> [[COND:%.*]]
958 %invert = xor <2 x i1> %cond, <i1 1, i1 1>
959 %s = select <2 x i1> %invert, <2 x i32> <i32 0, i32 0>, <2 x i32> <i32 1, i32 1>
960 %c = icmp ne <2 x i32> %s, <i32 0, i32 0>
965 define <2 x i1> @vectorselectcrash(i32 %arg1) {
966 ; CHECK-LABEL: @vectorselectcrash(
967 ; CHECK-NEXT: [[TOBOOL40:%.*]] = icmp ne i32 [[ARG1:%.*]], 0
968 ; CHECK-NEXT: [[COND43:%.*]] = select i1 [[TOBOOL40]], <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1>
969 ; CHECK-NEXT: [[CMP45:%.*]] = icmp ugt <2 x i16> [[COND43]], <i16 73, i16 21>
970 ; CHECK-NEXT: ret <2 x i1> [[CMP45]]
972 %tobool40 = icmp ne i32 %arg1, 0
973 %cond43 = select i1 %tobool40, <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1>
974 %cmp45 = icmp ugt <2 x i16> %cond43, <i16 73, i16 21>
979 define i1 @alloca_compare(i64 %idx) {
980 ; CHECK-LABEL: @alloca_compare(
981 ; CHECK-NEXT: ret i1 false
983 %sv = alloca { i32, i32, [124 x i32] }
984 %1 = getelementptr inbounds { i32, i32, [124 x i32] }, { i32, i32, [124 x i32] }* %sv, i32 0, i32 2, i64 %idx
985 %2 = icmp eq i32* %1, null
989 define i1 @alloca_compare_no_null_opt(i64 %idx) #0 {
990 ; CHECK-LABEL: @alloca_compare_no_null_opt(
991 ; CHECK-NEXT: [[SV:%.*]] = alloca { i32, i32, [124 x i32] }, align 8
992 ; CHECK-NEXT: [[CMP:%.*]] = getelementptr inbounds { i32, i32, [124 x i32] }, { i32, i32, [124 x i32] }* [[SV]], i32 0, i32 2, i64 [[IDX:%.*]]
993 ; CHECK-NEXT: [[X:%.*]] = icmp eq i32* [[CMP]], null
994 ; CHECK-NEXT: ret i1 [[X]]
996 %sv = alloca { i32, i32, [124 x i32] }
997 %cmp = getelementptr inbounds { i32, i32, [124 x i32] }, { i32, i32, [124 x i32] }* %sv, i32 0, i32 2, i64 %idx
998 %X = icmp eq i32* %cmp, null
1002 define i1 @infinite_gep() {
1003 ; CHECK-LABEL: @infinite_gep(
1004 ; CHECK-NEXT: ret i1 true
1005 ; CHECK: unreachableblock:
1006 ; CHECK-NEXT: [[X:%.*]] = getelementptr i32, i32* [[X]], i32 1
1007 ; CHECK-NEXT: [[Y:%.*]] = icmp eq i32* [[X]], null
1008 ; CHECK-NEXT: ret i1 [[Y]]
1013 %X = getelementptr i32, i32 *%X, i32 1
1014 %Y = icmp eq i32* %X, null
1018 ; It's not valid to fold a comparison of an argument with an alloca, even though
1019 ; that's tempting. An argument can't *alias* an alloca, however the aliasing rule
1020 ; relies on restrictions against guessing an object's address and dereferencing.
1021 ; There are no restrictions against guessing an object's address and comparing.
1023 define i1 @alloca_argument_compare(i64* %arg) {
1024 ; CHECK-LABEL: @alloca_argument_compare(
1025 ; CHECK-NEXT: [[ALLOC:%.*]] = alloca i64, align 8
1026 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64* [[ARG:%.*]], [[ALLOC]]
1027 ; CHECK-NEXT: ret i1 [[CMP]]
1030 %cmp = icmp eq i64* %arg, %alloc
1034 ; As above, but with the operands reversed.
1036 define i1 @alloca_argument_compare_swapped(i64* %arg) {
1037 ; CHECK-LABEL: @alloca_argument_compare_swapped(
1038 ; CHECK-NEXT: [[ALLOC:%.*]] = alloca i64, align 8
1039 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64* [[ALLOC]], [[ARG:%.*]]
1040 ; CHECK-NEXT: ret i1 [[CMP]]
1043 %cmp = icmp eq i64* %alloc, %arg
1047 ; Don't assume that a noalias argument isn't equal to a global variable's
1048 ; address. This is an example where AliasAnalysis' NoAlias concept is
1049 ; different from actual pointer inequality.
1051 @y = external global i32
1052 define zeroext i1 @external_compare(i32* noalias %x) {
1053 ; CHECK-LABEL: @external_compare(
1054 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[X:%.*]], @y
1055 ; CHECK-NEXT: ret i1 [[CMP]]
1057 %cmp = icmp eq i32* %x, @y
1061 define i1 @alloca_gep(i64 %a, i64 %b) {
1062 ; CHECK-LABEL: @alloca_gep(
1063 ; CHECK-NEXT: ret i1 false
1065 ; We can prove this GEP is non-null because it is inbounds and the pointer
1067 %strs = alloca [1000 x [1001 x i8]], align 16
1068 %x = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %a, i64 %b
1069 %cmp = icmp eq i8* %x, null
1073 define i1 @alloca_gep_no_null_opt(i64 %a, i64 %b) #0 {
1074 ; CHECK-LABEL: @alloca_gep_no_null_opt(
1075 ; CHECK-NEXT: [[STRS:%.*]] = alloca [1000 x [1001 x i8]], align 16
1076 ; CHECK-NEXT: [[X:%.*]] = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* [[STRS]], i64 0, i64 [[A:%.*]], i64 [[B:%.*]]
1077 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[X]], null
1078 ; CHECK-NEXT: ret i1 [[CMP]]
1080 ; We can't prove this GEP is non-null.
1081 %strs = alloca [1000 x [1001 x i8]], align 16
1082 %x = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %a, i64 %b
1083 %cmp = icmp eq i8* %x, null
1087 define i1 @non_inbounds_gep_compare(i64* %a) {
1088 ; CHECK-LABEL: @non_inbounds_gep_compare(
1089 ; CHECK-NEXT: ret i1 true
1091 ; Equality compares with non-inbounds GEPs can be folded.
1092 %x = getelementptr i64, i64* %a, i64 42
1093 %y = getelementptr inbounds i64, i64* %x, i64 -42
1094 %z = getelementptr i64, i64* %a, i64 -42
1095 %w = getelementptr inbounds i64, i64* %z, i64 42
1096 %cmp = icmp eq i64* %y, %w
1100 define i1 @non_inbounds_gep_compare2(i64* %a) {
1101 ; CHECK-LABEL: @non_inbounds_gep_compare2(
1102 ; CHECK-NEXT: ret i1 true
1104 ; Equality compares with non-inbounds GEPs can be folded.
1105 %x = getelementptr i64, i64* %a, i64 4294967297
1106 %y = getelementptr i64, i64* %a, i64 1
1107 %cmp = icmp eq i64* %y, %y
1111 define i1 @compare_always_true_slt(i16 %a) {
1112 ; CHECK-LABEL: @compare_always_true_slt(
1113 ; CHECK-NEXT: ret i1 true
1115 %t1 = zext i16 %a to i32
1116 %t2 = sub i32 0, %t1
1117 %t3 = icmp slt i32 %t2, 1
1121 define <2 x i1> @compare_always_true_slt_splat(<2 x i16> %a) {
1122 ; CHECK-LABEL: @compare_always_true_slt_splat(
1123 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1125 %t1 = zext <2 x i16> %a to <2 x i32>
1126 %t2 = sub <2 x i32> zeroinitializer, %t1
1127 %t3 = icmp slt <2 x i32> %t2, <i32 1, i32 1>
1131 define i1 @compare_always_true_sle(i16 %a) {
1132 ; CHECK-LABEL: @compare_always_true_sle(
1133 ; CHECK-NEXT: ret i1 true
1135 %t1 = zext i16 %a to i32
1136 %t2 = sub i32 0, %t1
1137 %t3 = icmp sle i32 %t2, 0
1141 define <2 x i1> @compare_always_true_sle_splat(<2 x i16> %a) {
1142 ; CHECK-LABEL: @compare_always_true_sle_splat(
1143 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1145 %t1 = zext <2 x i16> %a to <2 x i32>
1146 %t2 = sub <2 x i32> zeroinitializer, %t1
1147 %t3 = icmp sle <2 x i32> %t2, zeroinitializer
1151 define i1 @compare_always_false_sgt(i16 %a) {
1152 ; CHECK-LABEL: @compare_always_false_sgt(
1153 ; CHECK-NEXT: ret i1 false
1155 %t1 = zext i16 %a to i32
1156 %t2 = sub i32 0, %t1
1157 %t3 = icmp sgt i32 %t2, 0
1161 define <2 x i1> @compare_always_false_sgt_splat(<2 x i16> %a) {
1162 ; CHECK-LABEL: @compare_always_false_sgt_splat(
1163 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1165 %t1 = zext <2 x i16> %a to <2 x i32>
1166 %t2 = sub <2 x i32> zeroinitializer, %t1
1167 %t3 = icmp sgt <2 x i32> %t2, zeroinitializer
1171 define i1 @compare_always_false_sge(i16 %a) {
1172 ; CHECK-LABEL: @compare_always_false_sge(
1173 ; CHECK-NEXT: ret i1 false
1175 %t1 = zext i16 %a to i32
1176 %t2 = sub i32 0, %t1
1177 %t3 = icmp sge i32 %t2, 1
1181 define <2 x i1> @compare_always_false_sge_splat(<2 x i16> %a) {
1182 ; CHECK-LABEL: @compare_always_false_sge_splat(
1183 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1185 %t1 = zext <2 x i16> %a to <2 x i32>
1186 %t2 = sub <2 x i32> zeroinitializer, %t1
1187 %t3 = icmp sge <2 x i32> %t2, <i32 1, i32 1>
1191 define i1 @compare_always_false_eq(i16 %a) {
1192 ; CHECK-LABEL: @compare_always_false_eq(
1193 ; CHECK-NEXT: ret i1 false
1195 %t1 = zext i16 %a to i32
1196 %t2 = sub i32 0, %t1
1197 %t3 = icmp eq i32 %t2, 1
1201 define <2 x i1> @compare_always_false_eq_splat(<2 x i16> %a) {
1202 ; CHECK-LABEL: @compare_always_false_eq_splat(
1203 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1205 %t1 = zext <2 x i16> %a to <2 x i32>
1206 %t2 = sub <2 x i32> zeroinitializer, %t1
1207 %t3 = icmp eq <2 x i32> %t2, <i32 1, i32 1>
1211 define i1 @compare_always_true_ne(i16 %a) {
1212 ; CHECK-LABEL: @compare_always_true_ne(
1213 ; CHECK-NEXT: ret i1 true
1215 %t1 = zext i16 %a to i32
1216 %t2 = sub i32 0, %t1
1217 %t3 = icmp ne i32 %t2, 1
1221 define <2 x i1> @compare_always_true_ne_splat(<2 x i16> %a) {
1222 ; CHECK-LABEL: @compare_always_true_ne_splat(
1223 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1225 %t1 = zext <2 x i16> %a to <2 x i32>
1226 %t2 = sub <2 x i32> zeroinitializer, %t1
1227 %t3 = icmp ne <2 x i32> %t2, <i32 1, i32 1>
1231 define i1 @lshr_ugt_false(i32 %a) {
1232 ; CHECK-LABEL: @lshr_ugt_false(
1233 ; CHECK-NEXT: ret i1 false
1235 %shr = lshr i32 1, %a
1236 %cmp = icmp ugt i32 %shr, 1
1240 define i1 @nonnull_arg(i32* nonnull %i) {
1241 ; CHECK-LABEL: @nonnull_arg(
1242 ; CHECK-NEXT: ret i1 false
1244 %cmp = icmp eq i32* %i, null
1248 define i1 @nonnull_arg_no_null_opt(i32* nonnull %i) #0 {
1249 ; CHECK-LABEL: @nonnull_arg_no_null_opt(
1250 ; CHECK-NEXT: ret i1 false
1252 %cmp = icmp eq i32* %i, null
1256 define i1 @nonnull_deref_arg(i32* dereferenceable(4) %i) {
1257 ; CHECK-LABEL: @nonnull_deref_arg(
1258 ; CHECK-NEXT: ret i1 false
1260 %cmp = icmp eq i32* %i, null
1264 define i1 @nonnull_deref_arg_no_null_opt(i32* dereferenceable(4) %i) #0 {
1265 ; CHECK-LABEL: @nonnull_deref_arg_no_null_opt(
1266 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[I:%.*]], null
1267 ; CHECK-NEXT: ret i1 [[CMP]]
1269 %cmp = icmp eq i32* %i, null
1272 define i1 @nonnull_deref_as_arg(i32 addrspace(1)* dereferenceable(4) %i) {
1273 ; CHECK-LABEL: @nonnull_deref_as_arg(
1274 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 addrspace(1)* [[I:%.*]], null
1275 ; CHECK-NEXT: ret i1 [[CMP]]
1277 %cmp = icmp eq i32 addrspace(1)* %i, null
1281 declare nonnull i32* @returns_nonnull_helper()
1282 define i1 @returns_nonnull() {
1283 ; CHECK-LABEL: @returns_nonnull(
1284 ; CHECK-NEXT: [[CALL:%.*]] = call nonnull i32* @returns_nonnull_helper()
1285 ; CHECK-NEXT: ret i1 false
1287 %call = call nonnull i32* @returns_nonnull_helper()
1288 %cmp = icmp eq i32* %call, null
1292 declare dereferenceable(4) i32* @returns_nonnull_deref_helper()
1293 define i1 @returns_nonnull_deref() {
1294 ; CHECK-LABEL: @returns_nonnull_deref(
1295 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) i32* @returns_nonnull_deref_helper()
1296 ; CHECK-NEXT: ret i1 false
1298 %call = call dereferenceable(4) i32* @returns_nonnull_deref_helper()
1299 %cmp = icmp eq i32* %call, null
1303 define i1 @returns_nonnull_deref_no_null_opt () #0 {
1304 ; CHECK-LABEL: @returns_nonnull_deref_no_null_opt(
1305 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) i32* @returns_nonnull_deref_helper()
1306 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[CALL]], null
1307 ; CHECK-NEXT: ret i1 [[CMP]]
1309 %call = call dereferenceable(4) i32* @returns_nonnull_deref_helper()
1310 %cmp = icmp eq i32* %call, null
1314 declare dereferenceable(4) i32 addrspace(1)* @returns_nonnull_deref_as_helper()
1315 define i1 @returns_nonnull_as_deref() {
1316 ; CHECK-LABEL: @returns_nonnull_as_deref(
1317 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable(4) i32 addrspace(1)* @returns_nonnull_deref_as_helper()
1318 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 addrspace(1)* [[CALL]], null
1319 ; CHECK-NEXT: ret i1 [[CMP]]
1321 %call = call dereferenceable(4) i32 addrspace(1)* @returns_nonnull_deref_as_helper()
1322 %cmp = icmp eq i32 addrspace(1)* %call, null
1326 define i1 @nonnull_load(i32** %addr) {
1327 ; CHECK-LABEL: @nonnull_load(
1328 ; CHECK-NEXT: ret i1 false
1330 %ptr = load i32*, i32** %addr, !nonnull !{}
1331 %cmp = icmp eq i32* %ptr, null
1335 define i1 @nonnull_load_as_outer(i32* addrspace(1)* %addr) {
1336 ; CHECK-LABEL: @nonnull_load_as_outer(
1337 ; CHECK-NEXT: ret i1 false
1339 %ptr = load i32*, i32* addrspace(1)* %addr, !nonnull !{}
1340 %cmp = icmp eq i32* %ptr, null
1343 define i1 @nonnull_load_as_inner(i32 addrspace(1)** %addr) {
1344 ; CHECK-LABEL: @nonnull_load_as_inner(
1345 ; CHECK-NEXT: ret i1 false
1347 %ptr = load i32 addrspace(1)*, i32 addrspace(1)** %addr, !nonnull !{}
1348 %cmp = icmp eq i32 addrspace(1)* %ptr, null
1352 ; If a bit is known to be zero for A and known to be one for B,
1353 ; then A and B cannot be equal.
1354 define i1 @icmp_eq_const(i32 %a) {
1355 ; CHECK-LABEL: @icmp_eq_const(
1356 ; CHECK-NEXT: ret i1 false
1358 %b = mul nsw i32 %a, -2
1359 %c = icmp eq i32 %b, 1
1363 define <2 x i1> @icmp_eq_const_vec(<2 x i32> %a) {
1364 ; CHECK-LABEL: @icmp_eq_const_vec(
1365 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1367 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2>
1368 %c = icmp eq <2 x i32> %b, <i32 1, i32 1>
1372 define i1 @icmp_ne_const(i32 %a) {
1373 ; CHECK-LABEL: @icmp_ne_const(
1374 ; CHECK-NEXT: ret i1 true
1376 %b = mul nsw i32 %a, -2
1377 %c = icmp ne i32 %b, 1
1381 define <2 x i1> @icmp_ne_const_vec(<2 x i32> %a) {
1382 ; CHECK-LABEL: @icmp_ne_const_vec(
1383 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1385 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2>
1386 %c = icmp ne <2 x i32> %b, <i32 1, i32 1>
1390 define i1 @icmp_sdiv_int_min(i32 %a) {
1391 ; CHECK-LABEL: @icmp_sdiv_int_min(
1392 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 -2147483648, [[A:%.*]]
1393 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[DIV]], -1073741824
1394 ; CHECK-NEXT: ret i1 [[CMP]]
1396 %div = sdiv i32 -2147483648, %a
1397 %cmp = icmp ne i32 %div, -1073741824
1402 define i1 @icmp_sdiv_pr20288(i64 %a) {
1403 ; CHECK-LABEL: @icmp_sdiv_pr20288(
1404 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 [[A:%.*]], -8589934592
1405 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824
1406 ; CHECK-NEXT: ret i1 [[CMP]]
1408 %div = sdiv i64 %a, -8589934592
1409 %cmp = icmp ne i64 %div, 1073741824
1414 define i1 @icmp_sdiv_neg1(i64 %a) {
1415 ; CHECK-LABEL: @icmp_sdiv_neg1(
1416 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 [[A:%.*]], -1
1417 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824
1418 ; CHECK-NEXT: ret i1 [[CMP]]
1420 %div = sdiv i64 %a, -1
1421 %cmp = icmp ne i64 %div, 1073741824
1426 define i1 @icmp_known_bits(i4 %x, i4 %y) {
1427 ; CHECK-LABEL: @icmp_known_bits(
1428 ; CHECK-NEXT: ret i1 false
1430 %and1 = and i4 %y, -7
1431 %and2 = and i4 %x, -7
1432 %or1 = or i4 %and1, 2
1433 %or2 = or i4 %and2, 2
1434 %add = add i4 %or1, %or2
1435 %cmp = icmp eq i4 %add, 0
1439 define i1 @icmp_known_bits_vec(<2 x i4> %x, <2 x i4> %y) {
1440 ; CHECK-LABEL: @icmp_known_bits_vec(
1441 ; CHECK-NEXT: ret i1 false
1443 %and1 = and <2 x i4> %y, <i4 -7, i4 -1>
1444 %and2 = and <2 x i4> %x, <i4 -7, i4 -1>
1445 %or1 = or <2 x i4> %and1, <i4 2, i4 2>
1446 %or2 = or <2 x i4> %and2, <i4 2, i4 2>
1447 %add = add <2 x i4> %or1, %or2
1448 %ext = extractelement <2 x i4> %add,i32 0
1449 %cmp = icmp eq i4 %ext, 0
1453 define i1 @icmp_shl_nuw_1(i64 %a) {
1454 ; CHECK-LABEL: @icmp_shl_nuw_1(
1455 ; CHECK-NEXT: ret i1 true
1457 %shl = shl nuw i64 1, %a
1458 %cmp = icmp ne i64 %shl, 0
1462 define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) {
1463 ; CHECK-LABEL: @icmp_shl_1_V_ugt_2147483648(
1464 ; CHECK-NEXT: ret i1 false
1466 %shl = shl i32 1, %V
1467 %cmp = icmp ugt i32 %shl, 2147483648
1471 define <2 x i1> @icmp_shl_1_ugt_signmask(<2 x i8> %V) {
1472 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask(
1473 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1475 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1476 %cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 128>
1480 define <2 x i1> @icmp_shl_1_ugt_signmask_undef(<2 x i8> %V) {
1481 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask_undef(
1482 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1484 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1485 %cmp = icmp ugt <2 x i8> %shl, <i8 128, i8 undef>
1489 define <2 x i1> @icmp_shl_1_ugt_signmask_undef2(<2 x i8> %V) {
1490 ; CHECK-LABEL: @icmp_shl_1_ugt_signmask_undef2(
1491 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1493 %shl = shl <2 x i8> <i8 1, i8 undef>, %V
1494 %cmp = icmp ugt <2 x i8> %shl, <i8 undef, i8 128>
1498 define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) {
1499 ; CHECK-LABEL: @icmp_shl_1_V_ule_2147483648(
1500 ; CHECK-NEXT: ret i1 true
1502 %shl = shl i32 1, %V
1503 %cmp = icmp ule i32 %shl, 2147483648
1507 define <2 x i1> @icmp_shl_1_ule_signmask(<2 x i8> %V) {
1508 ; CHECK-LABEL: @icmp_shl_1_ule_signmask(
1509 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1511 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1512 %cmp = icmp ule <2 x i8> %shl, <i8 128, i8 128>
1516 define <2 x i1> @icmp_shl_1_ule_signmask_undef(<2 x i8> %V) {
1517 ; CHECK-LABEL: @icmp_shl_1_ule_signmask_undef(
1518 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1520 %shl = shl <2 x i8> <i8 1, i8 1>, %V
1521 %cmp = icmp ule <2 x i8> %shl, <i8 128, i8 undef>
1525 define <2 x i1> @icmp_shl_1_ule_signmask_undef2(<2 x i8> %V) {
1526 ; CHECK-LABEL: @icmp_shl_1_ule_signmask_undef2(
1527 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1529 %shl = shl <2 x i8> <i8 1, i8 undef>, %V
1530 %cmp = icmp ule <2 x i8> %shl, <i8 undef, i8 128>
1534 define i1 @shl_1_cmp_eq_nonpow2(i32 %x) {
1535 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2(
1536 ; CHECK-NEXT: ret i1 false
1539 %c = icmp eq i32 %s, 31
1543 define <2 x i1> @shl_1_cmp_eq_nonpow2_splat(<2 x i32> %x) {
1544 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2_splat(
1545 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1547 %s = shl <2 x i32> <i32 1, i32 1>, %x
1548 %c = icmp eq <2 x i32> %s, <i32 31, i32 31>
1552 define <2 x i1> @shl_1_cmp_eq_nonpow2_splat_undef(<2 x i32> %x) {
1553 ; CHECK-LABEL: @shl_1_cmp_eq_nonpow2_splat_undef(
1554 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1556 %s = shl <2 x i32> <i32 1, i32 1>, %x
1557 %c = icmp eq <2 x i32> %s, <i32 31, i32 undef>
1561 define i1 @shl_1_cmp_ne_nonpow2(i32 %x) {
1562 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2(
1563 ; CHECK-NEXT: ret i1 true
1566 %c = icmp ne i32 %s, 42
1570 define <2 x i1> @shl_1_cmp_ne_nonpow2_splat(<2 x i32> %x) {
1571 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2_splat(
1572 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1574 %s = shl <2 x i32> <i32 1, i32 1>, %x
1575 %c = icmp ne <2 x i32> %s, <i32 42, i32 42>
1579 define <2 x i1> @shl_1_cmp_ne_nonpow2_splat_undef(<2 x i32> %x) {
1580 ; CHECK-LABEL: @shl_1_cmp_ne_nonpow2_splat_undef(
1581 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1583 %s = shl <2 x i32> <i32 undef, i32 1>, %x
1584 %c = icmp ne <2 x i32> %s, <i32 42, i32 undef>
1588 define i1 @shl_pow2_cmp_eq_nonpow2(i32 %x) {
1589 ; CHECK-LABEL: @shl_pow2_cmp_eq_nonpow2(
1590 ; CHECK-NEXT: ret i1 false
1593 %c = icmp eq i32 %s, 31
1597 define <2 x i1> @shl_pow21_cmp_ne_nonpow2_splat_undef(<2 x i32> %x) {
1598 ; CHECK-LABEL: @shl_pow21_cmp_ne_nonpow2_splat_undef(
1599 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1601 %s = shl <2 x i32> <i32 undef, i32 4>, %x
1602 %c = icmp ne <2 x i32> %s, <i32 31, i32 undef>
1606 ; Negative test - overflowing shift could be zero.
1608 define i1 @shl_pow2_cmp_ne_zero(i32 %x) {
1609 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero(
1610 ; CHECK-NEXT: [[S:%.*]] = shl i32 16, [[X:%.*]]
1611 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[S]], 0
1612 ; CHECK-NEXT: ret i1 [[C]]
1615 %c = icmp ne i32 %s, 0
1619 ; Negative test - overflowing shift could be zero.
1621 define <2 x i1> @shl_pow2_cmp_ne_zero_splat(<2 x i32> %x) {
1622 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_splat(
1623 ; CHECK-NEXT: [[S:%.*]] = shl <2 x i32> <i32 16, i32 16>, [[X:%.*]]
1624 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[S]], zeroinitializer
1625 ; CHECK-NEXT: ret <2 x i1> [[C]]
1627 %s = shl <2 x i32> <i32 16, i32 16>, %x
1628 %c = icmp ne <2 x i32> %s, zeroinitializer
1632 define i1 @shl_pow2_cmp_eq_zero_nuw(i32 %x) {
1633 ; CHECK-LABEL: @shl_pow2_cmp_eq_zero_nuw(
1634 ; CHECK-NEXT: ret i1 false
1636 %s = shl nuw i32 16, %x
1637 %c = icmp eq i32 %s, 0
1641 define <2 x i1> @shl_pow2_cmp_ne_zero_nuw_splat_undef(<2 x i32> %x) {
1642 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_nuw_splat_undef(
1643 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
1645 %s = shl nuw <2 x i32> <i32 16, i32 undef>, %x
1646 %c = icmp ne <2 x i32> %s, <i32 undef, i32 0>
1650 define i1 @shl_pow2_cmp_ne_zero_nsw(i32 %x) {
1651 ; CHECK-LABEL: @shl_pow2_cmp_ne_zero_nsw(
1652 ; CHECK-NEXT: ret i1 true
1654 %s = shl nsw i32 16, %x
1655 %c = icmp ne i32 %s, 0
1659 define <2 x i1> @shl_pow2_cmp_eq_zero_nsw_splat_undef(<2 x i32> %x) {
1660 ; CHECK-LABEL: @shl_pow2_cmp_eq_zero_nsw_splat_undef(
1661 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1663 %s = shl nsw <2 x i32> <i32 undef, i32 16>, %x
1664 %c = icmp eq <2 x i32> %s, <i32 0, i32 undef>
1668 define i1 @tautological1(i32 %A, i32 %B) {
1669 ; CHECK-LABEL: @tautological1(
1670 ; CHECK-NEXT: ret i1 false
1673 %D = icmp ugt i32 %C, %A
1677 define i1 @tautological2(i32 %A, i32 %B) {
1678 ; CHECK-LABEL: @tautological2(
1679 ; CHECK-NEXT: ret i1 true
1682 %D = icmp ule i32 %C, %A
1686 define i1 @tautological3(i32 %A, i32 %B) {
1687 ; CHECK-LABEL: @tautological3(
1688 ; CHECK-NEXT: ret i1 true
1691 %D = icmp ule i32 %A, %C
1695 define i1 @tautological4(i32 %A, i32 %B) {
1696 ; CHECK-LABEL: @tautological4(
1697 ; CHECK-NEXT: ret i1 false
1700 %D = icmp ugt i32 %A, %C
1704 define i1 @tautological5(i32 %A, i32 %B) {
1705 ; CHECK-LABEL: @tautological5(
1706 ; CHECK-NEXT: ret i1 false
1709 %D = icmp ult i32 %C, %A
1713 define i1 @tautological6(i32 %A, i32 %B) {
1714 ; CHECK-LABEL: @tautological6(
1715 ; CHECK-NEXT: ret i1 true
1718 %D = icmp uge i32 %C, %A
1722 define i1 @tautological7(i32 %A, i32 %B) {
1723 ; CHECK-LABEL: @tautological7(
1724 ; CHECK-NEXT: ret i1 true
1727 %D = icmp uge i32 %A, %C
1731 define i1 @tautological8(i32 %A, i32 %B) {
1732 ; CHECK-LABEL: @tautological8(
1733 ; CHECK-NEXT: ret i1 false
1736 %D = icmp ult i32 %A, %C
1740 declare void @helper_i1(i1)
1741 ; Series of tests for icmp s[lt|ge] (or A, B), A and icmp s[gt|le] A, (or A, B)
1742 define void @icmp_slt_sge_or(i32 %Ax, i32 %Bx) {
1743 ; 'p' for positive, 'n' for negative, 'x' for potentially either.
1744 ; %D is 'icmp slt (or A, B), A'
1745 ; %E is 'icmp sge (or A, B), A' making it the not of %D
1746 ; %F is 'icmp sgt A, (or A, B)' making it the same as %D
1747 ; %G is 'icmp sle A, (or A, B)' making it the not of %D
1748 ; CHECK-LABEL: @icmp_slt_sge_or(
1749 ; CHECK-NEXT: [[APOS:%.*]] = and i32 [[AX:%.*]], 2147483647
1750 ; CHECK-NEXT: [[BNEG:%.*]] = or i32 [[BX:%.*]], -2147483648
1751 ; CHECK-NEXT: [[CPX:%.*]] = or i32 [[APOS]], [[BX]]
1752 ; CHECK-NEXT: [[DPX:%.*]] = icmp slt i32 [[CPX]], [[APOS]]
1753 ; CHECK-NEXT: [[EPX:%.*]] = icmp sge i32 [[CPX]], [[APOS]]
1754 ; CHECK-NEXT: [[FPX:%.*]] = icmp sgt i32 [[APOS]], [[CPX]]
1755 ; CHECK-NEXT: [[GPX:%.*]] = icmp sle i32 [[APOS]], [[CPX]]
1756 ; CHECK-NEXT: [[CXX:%.*]] = or i32 [[AX]], [[BX]]
1757 ; CHECK-NEXT: [[DXX:%.*]] = icmp slt i32 [[CXX]], [[AX]]
1758 ; CHECK-NEXT: [[EXX:%.*]] = icmp sge i32 [[CXX]], [[AX]]
1759 ; CHECK-NEXT: [[FXX:%.*]] = icmp sgt i32 [[AX]], [[CXX]]
1760 ; CHECK-NEXT: [[GXX:%.*]] = icmp sle i32 [[AX]], [[CXX]]
1761 ; CHECK-NEXT: [[CXN:%.*]] = or i32 [[AX]], [[BNEG]]
1762 ; CHECK-NEXT: [[DXN:%.*]] = icmp slt i32 [[CXN]], [[AX]]
1763 ; CHECK-NEXT: [[EXN:%.*]] = icmp sge i32 [[CXN]], [[AX]]
1764 ; CHECK-NEXT: [[FXN:%.*]] = icmp sgt i32 [[AX]], [[CXN]]
1765 ; CHECK-NEXT: [[GXN:%.*]] = icmp sle i32 [[AX]], [[CXN]]
1766 ; CHECK-NEXT: call void @helper_i1(i1 false)
1767 ; CHECK-NEXT: call void @helper_i1(i1 true)
1768 ; CHECK-NEXT: call void @helper_i1(i1 false)
1769 ; CHECK-NEXT: call void @helper_i1(i1 true)
1770 ; CHECK-NEXT: call void @helper_i1(i1 [[DPX]])
1771 ; CHECK-NEXT: call void @helper_i1(i1 [[EPX]])
1772 ; CHECK-NEXT: call void @helper_i1(i1 [[FPX]])
1773 ; CHECK-NEXT: call void @helper_i1(i1 [[GPX]])
1774 ; CHECK-NEXT: call void @helper_i1(i1 true)
1775 ; CHECK-NEXT: call void @helper_i1(i1 false)
1776 ; CHECK-NEXT: call void @helper_i1(i1 true)
1777 ; CHECK-NEXT: call void @helper_i1(i1 false)
1778 ; CHECK-NEXT: call void @helper_i1(i1 false)
1779 ; CHECK-NEXT: call void @helper_i1(i1 true)
1780 ; CHECK-NEXT: call void @helper_i1(i1 false)
1781 ; CHECK-NEXT: call void @helper_i1(i1 true)
1782 ; CHECK-NEXT: call void @helper_i1(i1 [[DXX]])
1783 ; CHECK-NEXT: call void @helper_i1(i1 [[EXX]])
1784 ; CHECK-NEXT: call void @helper_i1(i1 [[FXX]])
1785 ; CHECK-NEXT: call void @helper_i1(i1 [[GXX]])
1786 ; CHECK-NEXT: call void @helper_i1(i1 [[DXN]])
1787 ; CHECK-NEXT: call void @helper_i1(i1 [[EXN]])
1788 ; CHECK-NEXT: call void @helper_i1(i1 [[FXN]])
1789 ; CHECK-NEXT: call void @helper_i1(i1 [[GXN]])
1790 ; CHECK-NEXT: call void @helper_i1(i1 false)
1791 ; CHECK-NEXT: call void @helper_i1(i1 true)
1792 ; CHECK-NEXT: call void @helper_i1(i1 false)
1793 ; CHECK-NEXT: call void @helper_i1(i1 true)
1794 ; CHECK-NEXT: call void @helper_i1(i1 false)
1795 ; CHECK-NEXT: call void @helper_i1(i1 true)
1796 ; CHECK-NEXT: call void @helper_i1(i1 false)
1797 ; CHECK-NEXT: call void @helper_i1(i1 true)
1798 ; CHECK-NEXT: call void @helper_i1(i1 false)
1799 ; CHECK-NEXT: call void @helper_i1(i1 true)
1800 ; CHECK-NEXT: call void @helper_i1(i1 false)
1801 ; CHECK-NEXT: call void @helper_i1(i1 true)
1802 ; CHECK-NEXT: ret void
1804 %Aneg = or i32 %Ax, 2147483648
1805 %Apos = and i32 %Ax, 2147483647
1806 %Bneg = or i32 %Bx, 2147483648
1807 %Bpos = and i32 %Bx, 2147483647
1809 %Cpp = or i32 %Apos, %Bpos
1810 %Dpp = icmp slt i32 %Cpp, %Apos
1811 %Epp = icmp sge i32 %Cpp, %Apos
1812 %Fpp = icmp sgt i32 %Apos, %Cpp
1813 %Gpp = icmp sle i32 %Apos, %Cpp
1814 %Cpx = or i32 %Apos, %Bx
1815 %Dpx = icmp slt i32 %Cpx, %Apos
1816 %Epx = icmp sge i32 %Cpx, %Apos
1817 %Fpx = icmp sgt i32 %Apos, %Cpx
1818 %Gpx = icmp sle i32 %Apos, %Cpx
1819 %Cpn = or i32 %Apos, %Bneg
1820 %Dpn = icmp slt i32 %Cpn, %Apos
1821 %Epn = icmp sge i32 %Cpn, %Apos
1822 %Fpn = icmp sgt i32 %Apos, %Cpn
1823 %Gpn = icmp sle i32 %Apos, %Cpn
1825 %Cxp = or i32 %Ax, %Bpos
1826 %Dxp = icmp slt i32 %Cxp, %Ax
1827 %Exp = icmp sge i32 %Cxp, %Ax
1828 %Fxp = icmp sgt i32 %Ax, %Cxp
1829 %Gxp = icmp sle i32 %Ax, %Cxp
1830 %Cxx = or i32 %Ax, %Bx
1831 %Dxx = icmp slt i32 %Cxx, %Ax
1832 %Exx = icmp sge i32 %Cxx, %Ax
1833 %Fxx = icmp sgt i32 %Ax, %Cxx
1834 %Gxx = icmp sle i32 %Ax, %Cxx
1835 %Cxn = or i32 %Ax, %Bneg
1836 %Dxn = icmp slt i32 %Cxn, %Ax
1837 %Exn = icmp sge i32 %Cxn, %Ax
1838 %Fxn = icmp sgt i32 %Ax, %Cxn
1839 %Gxn = icmp sle i32 %Ax, %Cxn
1841 %Cnp = or i32 %Aneg, %Bpos
1842 %Dnp = icmp slt i32 %Cnp, %Aneg
1843 %Enp = icmp sge i32 %Cnp, %Aneg
1844 %Fnp = icmp sgt i32 %Aneg, %Cnp
1845 %Gnp = icmp sle i32 %Aneg, %Cnp
1846 %Cnx = or i32 %Aneg, %Bx
1847 %Dnx = icmp slt i32 %Cnx, %Aneg
1848 %Enx = icmp sge i32 %Cnx, %Aneg
1849 %Fnx = icmp sgt i32 %Aneg, %Cnx
1850 %Gnx = icmp sle i32 %Aneg, %Cnx
1851 %Cnn = or i32 %Aneg, %Bneg
1852 %Dnn = icmp slt i32 %Cnn, %Aneg
1853 %Enn = icmp sge i32 %Cnn, %Aneg
1854 %Fnn = icmp sgt i32 %Aneg, %Cnn
1855 %Gnn = icmp sle i32 %Aneg, %Cnn
1857 call void @helper_i1(i1 %Dpp)
1858 call void @helper_i1(i1 %Epp)
1859 call void @helper_i1(i1 %Fpp)
1860 call void @helper_i1(i1 %Gpp)
1861 call void @helper_i1(i1 %Dpx)
1862 call void @helper_i1(i1 %Epx)
1863 call void @helper_i1(i1 %Fpx)
1864 call void @helper_i1(i1 %Gpx)
1865 call void @helper_i1(i1 %Dpn)
1866 call void @helper_i1(i1 %Epn)
1867 call void @helper_i1(i1 %Fpn)
1868 call void @helper_i1(i1 %Gpn)
1869 call void @helper_i1(i1 %Dxp)
1870 call void @helper_i1(i1 %Exp)
1871 call void @helper_i1(i1 %Fxp)
1872 call void @helper_i1(i1 %Gxp)
1873 call void @helper_i1(i1 %Dxx)
1874 call void @helper_i1(i1 %Exx)
1875 call void @helper_i1(i1 %Fxx)
1876 call void @helper_i1(i1 %Gxx)
1877 call void @helper_i1(i1 %Dxn)
1878 call void @helper_i1(i1 %Exn)
1879 call void @helper_i1(i1 %Fxn)
1880 call void @helper_i1(i1 %Gxn)
1881 call void @helper_i1(i1 %Dnp)
1882 call void @helper_i1(i1 %Enp)
1883 call void @helper_i1(i1 %Fnp)
1884 call void @helper_i1(i1 %Gnp)
1885 call void @helper_i1(i1 %Dnx)
1886 call void @helper_i1(i1 %Enx)
1887 call void @helper_i1(i1 %Fnx)
1888 call void @helper_i1(i1 %Gnx)
1889 call void @helper_i1(i1 %Dnn)
1890 call void @helper_i1(i1 %Enn)
1891 call void @helper_i1(i1 %Fnn)
1892 call void @helper_i1(i1 %Gnn)
1896 define i1 @constant_fold_inttoptr_null() {
1897 ; CHECK-LABEL: @constant_fold_inttoptr_null(
1898 ; CHECK-NEXT: ret i1 false
1900 %x = icmp eq i32* inttoptr (i64 32 to i32*), null
1904 define i1 @constant_fold_null_inttoptr() {
1905 ; CHECK-LABEL: @constant_fold_null_inttoptr(
1906 ; CHECK-NEXT: ret i1 false
1908 %x = icmp eq i32* null, inttoptr (i64 32 to i32*)
1912 define i1 @cmp_through_addrspacecast(i32 addrspace(1)* %p1) {
1913 ; CHECK-LABEL: @cmp_through_addrspacecast(
1914 ; CHECK-NEXT: ret i1 true
1916 %p0 = addrspacecast i32 addrspace(1)* %p1 to i32*
1917 %p0.1 = getelementptr inbounds i32, i32* %p0, i64 1
1918 %cmp = icmp ne i32* %p0, %p0.1
1922 ; Test simplifications for: icmp (X+Y), (X+Z) -> icmp Y,Z
1923 ; Test the overflow check when the RHS has NSW set and constant Z is greater
1924 ; than Y, then we know X+Y also can't overflow.
1926 define i1 @icmp_nsw_1(i32 %V) {
1927 ; CHECK-LABEL: @icmp_nsw_1(
1928 ; CHECK-NEXT: ret i1 true
1930 %add5 = add i32 %V, 5
1931 %add6 = add nsw i32 %V, 6
1932 %s1 = sext i32 %add5 to i64
1933 %s2 = sext i32 %add6 to i64
1934 %cmp = icmp slt i64 %s1, %s2
1938 define i1 @icmp_nsw_2(i32 %V) {
1939 ; CHECK-LABEL: @icmp_nsw_2(
1940 ; CHECK-NEXT: ret i1 true
1942 %add5 = add i32 %V, 5
1943 %add6 = add nsw i32 %V, 6
1944 %cmp = icmp slt i32 %add5, %add6
1948 define i1 @icmp_nsw_commute(i32 %V) {
1949 ; CHECK-LABEL: @icmp_nsw_commute(
1950 ; CHECK-NEXT: ret i1 true
1952 %add5 = add i32 5, %V
1953 %add6 = add nsw i32 %V, 6
1954 %cmp = icmp slt i32 %add5, %add6
1958 define i1 @icmp_nsw_commute2(i32 %V) {
1959 ; CHECK-LABEL: @icmp_nsw_commute2(
1960 ; CHECK-NEXT: ret i1 true
1962 %add5 = add i32 %V, 5
1963 %add6 = add nsw i32 6, %V
1964 %cmp = icmp slt i32 %add5, %add6
1968 define i1 @icmp_nsw_commute3(i32 %V) {
1969 ; CHECK-LABEL: @icmp_nsw_commute3(
1970 ; CHECK-NEXT: ret i1 true
1972 %add5 = add i32 5, %V
1973 %add6 = add nsw i32 6, %V
1974 %cmp = icmp slt i32 %add5, %add6
1978 define i1 @icmp_nsw_22(i32 %V) {
1979 ; CHECK-LABEL: @icmp_nsw_22(
1980 ; CHECK-NEXT: ret i1 true
1982 %add5 = add nsw i32 %V, 5
1983 %add6 = add nsw i32 %V, 6
1984 %cmp = icmp slt i32 %add5, %add6
1988 define i1 @icmp_nsw_23(i32 %V) {
1989 ; CHECK-LABEL: @icmp_nsw_23(
1990 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
1991 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 6
1992 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
1993 ; CHECK-NEXT: ret i1 [[CMP]]
1995 %add5 = add nsw i32 %V, 5
1996 %add6 = add i32 %V, 6
1997 %cmp = icmp slt i32 %add5, %add6
2001 define i1 @icmp_nsw_false(i32 %V) {
2002 ; CHECK-LABEL: @icmp_nsw_false(
2003 ; CHECK-NEXT: ret i1 false
2005 %add5 = add nsw i32 %V, 6
2006 %add6 = add i32 %V, 5
2007 %cmp = icmp slt i32 %add5, %add6
2011 define i1 @icmp_nsw_false_2(i32 %V) {
2012 ; CHECK-LABEL: @icmp_nsw_false_2(
2013 ; CHECK-NEXT: ret i1 false
2015 %add5 = add nsw i32 %V, 6
2016 %add6 = add nsw i32 %V, 5
2017 %cmp = icmp slt i32 %add5, %add6
2021 define i1 @icmp_nsw_false_3(i32 %V) {
2022 ; CHECK-LABEL: @icmp_nsw_false_3(
2023 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2024 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 5
2025 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2026 ; CHECK-NEXT: ret i1 [[CMP]]
2028 %add5 = add nsw i32 %V, 5
2029 %add6 = add i32 %V, 5
2030 %cmp = icmp slt i32 %add5, %add6
2034 define i1 @icmp_nsw_false_4(i32 %V) {
2035 ; CHECK-LABEL: @icmp_nsw_false_4(
2036 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 6
2037 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 5
2038 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2039 ; CHECK-NEXT: ret i1 [[CMP]]
2041 %add5 = add i32 %V, 6
2042 %add6 = add nsw i32 %V, 5
2043 %cmp = icmp slt i32 %add5, %add6
2047 define i1 @icmp_nsw_false_5(i8 %V) {
2048 ; CHECK-LABEL: @icmp_nsw_false_5(
2049 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[V:%.*]], 121
2050 ; CHECK-NEXT: [[ADDNSW:%.*]] = add nsw i8 [[V]], -104
2051 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[ADD]], [[ADDNSW]]
2052 ; CHECK-NEXT: ret i1 [[CMP]]
2054 %add = add i8 %V, 121
2055 %addnsw = add nsw i8 %V, -104
2056 %cmp = icmp slt i8 %add, %addnsw
2060 define i1 @icmp_nsw_i8(i8 %V) {
2061 ; CHECK-LABEL: @icmp_nsw_i8(
2062 ; CHECK-NEXT: ret i1 true
2064 %add5 = add i8 %V, 5
2065 %add6 = add nsw i8 %V, 6
2066 %cmp = icmp slt i8 %add5, %add6
2070 define i1 @icmp_nsw_i16(i16 %V) {
2071 ; CHECK-LABEL: @icmp_nsw_i16(
2072 ; CHECK-NEXT: ret i1 true
2074 %add5 = add i16 %V, 0
2075 %add6 = add nsw i16 %V, 1
2076 %cmp = icmp slt i16 %add5, %add6
2080 define i1 @icmp_nsw_i64(i64 %V) {
2081 ; CHECK-LABEL: @icmp_nsw_i64(
2082 ; CHECK-NEXT: ret i1 true
2084 %add5 = add i64 %V, 5
2085 %add6 = add nsw i64 %V, 6
2086 %cmp = icmp slt i64 %add5, %add6
2090 define <4 x i1> @icmp_nsw_vec(<4 x i32> %V) {
2091 ; CHECK-LABEL: @icmp_nsw_vec(
2092 ; CHECK-NEXT: ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
2094 %add5 = add <4 x i32> %V, <i32 5, i32 5, i32 5, i32 5>
2095 %add6 = add nsw <4 x i32> %V, <i32 6, i32 6, i32 6, i32 6>
2096 %cmp = icmp slt <4 x i32> %add5, %add6
2100 define i1 @icmp_nsw_3(i32 %V) {
2101 ; CHECK-LABEL: @icmp_nsw_3(
2102 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2103 ; CHECK-NEXT: [[ADD5_2:%.*]] = add nsw i32 [[V]], 5
2104 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD5_2]]
2105 ; CHECK-NEXT: ret i1 [[CMP]]
2107 %add5 = add i32 %V, 5
2108 %add5_2 = add nsw i32 %V, 5
2109 %cmp = icmp slt i32 %add5, %add5_2
2113 define i1 @icmp_nsw_4(i32 %V) {
2114 ; CHECK-LABEL: @icmp_nsw_4(
2115 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2116 ; CHECK-NEXT: [[ADD4:%.*]] = add nsw i32 [[V]], 4
2117 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD4]]
2118 ; CHECK-NEXT: ret i1 [[CMP]]
2120 %add5 = add i32 %V, 5
2121 %add4 = add nsw i32 %V, 4
2122 %cmp = icmp slt i32 %add5, %add4
2126 define i1 @icmp_nsw_5(i32 %V) {
2127 ; CHECK-LABEL: @icmp_nsw_5(
2128 ; CHECK-NEXT: [[ADD5:%.*]] = add nsw i32 [[V:%.*]], 5
2129 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[V]], 6
2130 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2131 ; CHECK-NEXT: ret i1 [[CMP]]
2133 %add5 = add nsw i32 %V, 5
2134 %add6 = add i32 %V, 6
2135 %cmp = icmp slt i32 %add5, %add6
2139 define i1 @icmp_nsw_7(i32 %V, i32 %arg) {
2140 ; CHECK-LABEL: @icmp_nsw_7(
2141 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2142 ; CHECK-NEXT: [[ADDARG:%.*]] = add nsw i32 [[V]], [[ARG:%.*]]
2143 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADDARG]]
2144 ; CHECK-NEXT: ret i1 [[CMP]]
2146 %add5 = add i32 %V, 5
2147 %addarg = add nsw i32 %V, %arg
2148 %cmp = icmp slt i32 %add5, %addarg
2152 define i1 @icmp_nsw_8(i32 %V, i32 %arg) {
2153 ; CHECK-LABEL: @icmp_nsw_8(
2154 ; CHECK-NEXT: [[ADDARG:%.*]] = add i32 [[V:%.*]], [[ARG:%.*]]
2155 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 5
2156 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADDARG]], [[ADD6]]
2157 ; CHECK-NEXT: ret i1 [[CMP]]
2159 %addarg = add i32 %V, %arg
2160 %add6 = add nsw i32 %V, 5
2161 %cmp = icmp slt i32 %addarg, %add6
2165 define i1 @icmp_nsw_9(i32 %V1, i32 %V2) {
2166 ; CHECK-LABEL: @icmp_nsw_9(
2167 ; CHECK-NEXT: [[ADD_V1:%.*]] = add i32 [[V1:%.*]], 5
2168 ; CHECK-NEXT: [[ADD_V2:%.*]] = add nsw i32 [[V2:%.*]], 6
2169 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD_V1]], [[ADD_V2]]
2170 ; CHECK-NEXT: ret i1 [[CMP]]
2172 %add_V1 = add i32 %V1, 5
2173 %add_V2 = add nsw i32 %V2, 6
2174 %cmp = icmp slt i32 %add_V1, %add_V2
2178 define i1 @icmp_nsw_10(i32 %V) {
2179 ; CHECK-LABEL: @icmp_nsw_10(
2180 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 5
2181 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], 6
2182 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[ADD6]], [[ADD5]]
2183 ; CHECK-NEXT: ret i1 [[CMP]]
2185 %add5 = add i32 %V, 5
2186 %add6 = add nsw i32 %V, 6
2187 %cmp = icmp sgt i32 %add6, %add5
2191 define i1 @icmp_nsw_11(i32 %V) {
2192 ; CHECK-LABEL: @icmp_nsw_11(
2193 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], -125
2194 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[V]], -99
2195 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[ADD6]]
2196 ; CHECK-NEXT: ret i1 [[CMP]]
2198 %add5 = add i32 %V, -125
2199 %add6 = add nsw i32 %V, -99
2200 %cmp = icmp slt i32 %add5, %add6
2204 define i1 @icmp_nsw_nonpos(i32 %V) {
2205 ; CHECK-LABEL: @icmp_nsw_nonpos(
2206 ; CHECK-NEXT: ret i1 false
2208 %add5 = add i32 %V, 0
2209 %add6 = add nsw i32 %V, -1
2210 %cmp = icmp slt i32 %add5, %add6
2214 define i1 @icmp_nsw_nonpos2(i32 %V) {
2215 ; CHECK-LABEL: @icmp_nsw_nonpos2(
2216 ; CHECK-NEXT: [[ADD5:%.*]] = add i32 [[V:%.*]], 1
2217 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD5]], [[V]]
2218 ; CHECK-NEXT: ret i1 [[CMP]]
2220 %add5 = add i32 %V, 1
2221 %add6 = add nsw i32 %V, 0
2222 %cmp = icmp slt i32 %add5, %add6
2226 declare i11 @llvm.ctpop.i11(i11)
2227 declare i73 @llvm.ctpop.i73(i73)
2228 declare <2 x i13> @llvm.ctpop.v2i13(<2 x i13>)
2230 define i1 @ctpop_sgt_bitwidth(i11 %x) {
2231 ; CHECK-LABEL: @ctpop_sgt_bitwidth(
2232 ; CHECK-NEXT: ret i1 false
2234 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2235 %cmp = icmp sgt i11 %pop, 11
2239 define i1 @ctpop_sle_minus1(i11 %x) {
2240 ; CHECK-LABEL: @ctpop_sle_minus1(
2241 ; CHECK-NEXT: ret i1 false
2243 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2244 %cmp = icmp sle i11 %pop, -1
2248 define i1 @ctpop_ugt_bitwidth(i73 %x) {
2249 ; CHECK-LABEL: @ctpop_ugt_bitwidth(
2250 ; CHECK-NEXT: ret i1 false
2252 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2253 %cmp = icmp ugt i73 %pop, 73
2257 ; Negative test - does not simplify, but instcombine could reduce this.
2259 define i1 @ctpop_ugt_bitwidth_minus1(i73 %x) {
2260 ; CHECK-LABEL: @ctpop_ugt_bitwidth_minus1(
2261 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.ctpop.i73(i73 [[X:%.*]])
2262 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
2263 ; CHECK-NEXT: ret i1 [[CMP]]
2265 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2266 %cmp = icmp ugt i73 %pop, 72
2270 define <2 x i1> @ctpop_sgt_bitwidth_splat(<2 x i13> %x) {
2271 ; CHECK-LABEL: @ctpop_sgt_bitwidth_splat(
2272 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2274 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2275 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
2279 define i1 @ctpop_ult_plus1_bitwidth(i11 %x) {
2280 ; CHECK-LABEL: @ctpop_ult_plus1_bitwidth(
2281 ; CHECK-NEXT: ret i1 true
2283 %pop = call i11 @llvm.ctpop.i11(i11 %x)
2284 %cmp = icmp ult i11 %pop, 12
2288 define i1 @ctpop_ne_big_bitwidth(i73 %x) {
2289 ; CHECK-LABEL: @ctpop_ne_big_bitwidth(
2290 ; CHECK-NEXT: ret i1 true
2292 %pop = call i73 @llvm.ctpop.i73(i73 %x)
2293 %cmp = icmp ne i73 %pop, 75
2297 define <2 x i1> @ctpop_slt_bitwidth_plus1_splat(<2 x i13> %x) {
2298 ; CHECK-LABEL: @ctpop_slt_bitwidth_plus1_splat(
2299 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
2301 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2302 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
2306 ; Negative test - does not simplify, but instcombine could reduce this.
2308 define <2 x i1> @ctpop_slt_bitwidth_splat(<2 x i13> %x) {
2309 ; CHECK-LABEL: @ctpop_slt_bitwidth_splat(
2310 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> [[X:%.*]])
2311 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], <i13 13, i13 13>
2312 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2314 %pop = call <2 x i13> @llvm.ctpop.v2i13(<2 x i13> %x)
2315 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
2319 declare i11 @llvm.ctlz.i11(i11)
2320 declare i73 @llvm.ctlz.i73(i73)
2321 declare <2 x i13> @llvm.ctlz.v2i13(<2 x i13>)
2323 define i1 @ctlz_sgt_bitwidth(i11 %x) {
2324 ; CHECK-LABEL: @ctlz_sgt_bitwidth(
2325 ; CHECK-NEXT: ret i1 false
2327 %pop = call i11 @llvm.ctlz.i11(i11 %x)
2328 %cmp = icmp sgt i11 %pop, 11
2332 define i1 @ctlz_sle_minus1(i11 %x) {
2333 ; CHECK-LABEL: @ctlz_sle_minus1(
2334 ; CHECK-NEXT: ret i1 false
2336 %pop = call i11 @llvm.ctlz.i11(i11 %x)
2337 %cmp = icmp sle i11 %pop, -1
2341 define i1 @ctlz_ugt_bitwidth(i73 %x) {
2342 ; CHECK-LABEL: @ctlz_ugt_bitwidth(
2343 ; CHECK-NEXT: ret i1 false
2345 %pop = call i73 @llvm.ctlz.i73(i73 %x)
2346 %cmp = icmp ugt i73 %pop, 73
2350 ; Negative test - does not simplify, but instcombine could reduce this.
2352 define i1 @ctlz_ugt_bitwidth_minus1(i73 %x) {
2353 ; CHECK-LABEL: @ctlz_ugt_bitwidth_minus1(
2354 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.ctlz.i73(i73 [[X:%.*]], i1 false)
2355 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
2356 ; CHECK-NEXT: ret i1 [[CMP]]
2358 %pop = call i73 @llvm.ctlz.i73(i73 %x)
2359 %cmp = icmp ugt i73 %pop, 72
2363 define <2 x i1> @ctlz_sgt_bitwidth_splat(<2 x i13> %x) {
2364 ; CHECK-LABEL: @ctlz_sgt_bitwidth_splat(
2365 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2367 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
2368 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
2372 define i1 @ctlz_ult_plus1_bitwidth(i11 %x) {
2373 ; CHECK-LABEL: @ctlz_ult_plus1_bitwidth(
2374 ; CHECK-NEXT: ret i1 true
2376 %pop = call i11 @llvm.ctlz.i11(i11 %x)
2377 %cmp = icmp ult i11 %pop, 12
2381 define i1 @ctlz_ne_big_bitwidth(i73 %x) {
2382 ; CHECK-LABEL: @ctlz_ne_big_bitwidth(
2383 ; CHECK-NEXT: ret i1 true
2385 %pop = call i73 @llvm.ctlz.i73(i73 %x)
2386 %cmp = icmp ne i73 %pop, 75
2390 define <2 x i1> @ctlz_slt_bitwidth_plus1_splat(<2 x i13> %x) {
2391 ; CHECK-LABEL: @ctlz_slt_bitwidth_plus1_splat(
2392 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
2394 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
2395 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
2399 ; Negative test - does not simplify, but instcombine could reduce this.
2401 define <2 x i1> @ctlz_slt_bitwidth_splat(<2 x i13> %x) {
2402 ; CHECK-LABEL: @ctlz_slt_bitwidth_splat(
2403 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> [[X:%.*]], i1 false)
2404 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], <i13 13, i13 13>
2405 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2407 %pop = call <2 x i13> @llvm.ctlz.v2i13(<2 x i13> %x)
2408 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
2412 declare i11 @llvm.cttz.i11(i11)
2413 declare i73 @llvm.cttz.i73(i73)
2414 declare <2 x i13> @llvm.cttz.v2i13(<2 x i13>)
2416 define i1 @cttz_sgt_bitwidth(i11 %x) {
2417 ; CHECK-LABEL: @cttz_sgt_bitwidth(
2418 ; CHECK-NEXT: ret i1 false
2420 %pop = call i11 @llvm.cttz.i11(i11 %x)
2421 %cmp = icmp sgt i11 %pop, 11
2425 define i1 @cttz_sle_minus1(i11 %x) {
2426 ; CHECK-LABEL: @cttz_sle_minus1(
2427 ; CHECK-NEXT: ret i1 false
2429 %pop = call i11 @llvm.cttz.i11(i11 %x)
2430 %cmp = icmp sle i11 %pop, -1
2434 define i1 @cttz_ugt_bitwidth(i73 %x) {
2435 ; CHECK-LABEL: @cttz_ugt_bitwidth(
2436 ; CHECK-NEXT: ret i1 false
2438 %pop = call i73 @llvm.cttz.i73(i73 %x)
2439 %cmp = icmp ugt i73 %pop, 73
2443 ; Negative test - does not simplify, but instcombine could reduce this.
2445 define i1 @cttz_ugt_bitwidth_minus1(i73 %x) {
2446 ; CHECK-LABEL: @cttz_ugt_bitwidth_minus1(
2447 ; CHECK-NEXT: [[POP:%.*]] = call i73 @llvm.cttz.i73(i73 [[X:%.*]], i1 false)
2448 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i73 [[POP]], 72
2449 ; CHECK-NEXT: ret i1 [[CMP]]
2451 %pop = call i73 @llvm.cttz.i73(i73 %x)
2452 %cmp = icmp ugt i73 %pop, 72
2456 define <2 x i1> @cttz_sgt_bitwidth_splat(<2 x i13> %x) {
2457 ; CHECK-LABEL: @cttz_sgt_bitwidth_splat(
2458 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
2460 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
2461 %cmp = icmp sgt <2 x i13> %pop, <i13 13, i13 13>
2465 define i1 @cttz_ult_plus1_bitwidth(i11 %x) {
2466 ; CHECK-LABEL: @cttz_ult_plus1_bitwidth(
2467 ; CHECK-NEXT: ret i1 true
2469 %pop = call i11 @llvm.cttz.i11(i11 %x)
2470 %cmp = icmp ult i11 %pop, 12
2474 define i1 @cttz_ne_big_bitwidth(i73 %x) {
2475 ; CHECK-LABEL: @cttz_ne_big_bitwidth(
2476 ; CHECK-NEXT: ret i1 true
2478 %pop = call i73 @llvm.cttz.i73(i73 %x)
2479 %cmp = icmp ne i73 %pop, 75
2483 define <2 x i1> @cttz_slt_bitwidth_plus1_splat(<2 x i13> %x) {
2484 ; CHECK-LABEL: @cttz_slt_bitwidth_plus1_splat(
2485 ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
2487 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
2488 %cmp = icmp slt <2 x i13> %pop, <i13 14, i13 14>
2492 ; Negative test - does not simplify, but instcombine could reduce this.
2494 define <2 x i1> @cttz_slt_bitwidth_splat(<2 x i13> %x) {
2495 ; CHECK-LABEL: @cttz_slt_bitwidth_splat(
2496 ; CHECK-NEXT: [[POP:%.*]] = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> [[X:%.*]], i1 false)
2497 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i13> [[POP]], <i13 13, i13 13>
2498 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
2500 %pop = call <2 x i13> @llvm.cttz.v2i13(<2 x i13> %x)
2501 %cmp = icmp slt <2 x i13> %pop, <i13 13, i13 13>
2505 attributes #0 = { null_pointer_is_valid }