1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6 define i1 @lshr_eq_msb_low_last_zero(i8 %a) {
7 ; CHECK-LABEL: @lshr_eq_msb_low_last_zero(
8 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[A:%.*]], 6
9 ; CHECK-NEXT: ret i1 [[CMP]]
11 %shr = lshr i8 127, %a
12 %cmp = icmp eq i8 %shr, 0
16 define <2 x i1> @lshr_eq_msb_low_last_zero_vec(<2 x i8> %a) {
17 ; CHECK-LABEL: @lshr_eq_msb_low_last_zero_vec(
18 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[A:%.*]], <i8 6, i8 6>
19 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
21 %shr = lshr <2 x i8> <i8 127, i8 127>, %a
22 %cmp = icmp eq <2 x i8> %shr, zeroinitializer
26 define i1 @ashr_eq_msb_low_second_zero(i8 %a) {
27 ; CHECK-LABEL: @ashr_eq_msb_low_second_zero(
28 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[A:%.*]], 6
29 ; CHECK-NEXT: ret i1 [[CMP]]
31 %shr = ashr i8 127, %a
32 %cmp = icmp eq i8 %shr, 0
36 define i1 @lshr_ne_msb_low_last_zero(i8 %a) {
37 ; CHECK-LABEL: @lshr_ne_msb_low_last_zero(
38 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[A:%.*]], 7
39 ; CHECK-NEXT: ret i1 [[CMP]]
41 %shr = lshr i8 127, %a
42 %cmp = icmp ne i8 %shr, 0
46 define i1 @ashr_ne_msb_low_second_zero(i8 %a) {
47 ; CHECK-LABEL: @ashr_ne_msb_low_second_zero(
48 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[A:%.*]], 7
49 ; CHECK-NEXT: ret i1 [[CMP]]
51 %shr = ashr i8 127, %a
52 %cmp = icmp ne i8 %shr, 0
56 define i1 @ashr_eq_both_equal(i8 %a) {
57 ; CHECK-LABEL: @ashr_eq_both_equal(
58 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 0
59 ; CHECK-NEXT: ret i1 [[CMP]]
61 %shr = ashr i8 128, %a
62 %cmp = icmp eq i8 %shr, 128
66 define i1 @ashr_ne_both_equal(i8 %a) {
67 ; CHECK-LABEL: @ashr_ne_both_equal(
68 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 0
69 ; CHECK-NEXT: ret i1 [[CMP]]
71 %shr = ashr i8 128, %a
72 %cmp = icmp ne i8 %shr, 128
76 define i1 @lshr_eq_both_equal(i8 %a) {
77 ; CHECK-LABEL: @lshr_eq_both_equal(
78 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 0
79 ; CHECK-NEXT: ret i1 [[CMP]]
81 %shr = lshr i8 127, %a
82 %cmp = icmp eq i8 %shr, 127
86 define i1 @lshr_ne_both_equal(i8 %a) {
87 ; CHECK-LABEL: @lshr_ne_both_equal(
88 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 0
89 ; CHECK-NEXT: ret i1 [[CMP]]
91 %shr = lshr i8 127, %a
92 %cmp = icmp ne i8 %shr, 127
96 define i1 @exact_ashr_eq_both_equal(i8 %a) {
97 ; CHECK-LABEL: @exact_ashr_eq_both_equal(
98 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 0
99 ; CHECK-NEXT: ret i1 [[CMP]]
101 %shr = ashr exact i8 128, %a
102 %cmp = icmp eq i8 %shr, 128
106 define i1 @exact_ashr_ne_both_equal(i8 %a) {
107 ; CHECK-LABEL: @exact_ashr_ne_both_equal(
108 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 0
109 ; CHECK-NEXT: ret i1 [[CMP]]
111 %shr = ashr exact i8 128, %a
112 %cmp = icmp ne i8 %shr, 128
116 define i1 @exact_lshr_eq_both_equal(i8 %a) {
117 ; CHECK-LABEL: @exact_lshr_eq_both_equal(
118 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 0
119 ; CHECK-NEXT: ret i1 [[CMP]]
121 %shr = lshr exact i8 126, %a
122 %cmp = icmp eq i8 %shr, 126
126 define i1 @exact_lshr_ne_both_equal(i8 %a) {
127 ; CHECK-LABEL: @exact_lshr_ne_both_equal(
128 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 0
129 ; CHECK-NEXT: ret i1 [[CMP]]
131 %shr = lshr exact i8 126, %a
132 %cmp = icmp ne i8 %shr, 126
136 define i1 @exact_lshr_eq_opposite_msb(i8 %a) {
137 ; CHECK-LABEL: @exact_lshr_eq_opposite_msb(
138 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 7
139 ; CHECK-NEXT: ret i1 [[CMP]]
141 %shr = lshr exact i8 -128, %a
142 %cmp = icmp eq i8 %shr, 1
146 define i1 @lshr_eq_opposite_msb(i8 %a) {
147 ; CHECK-LABEL: @lshr_eq_opposite_msb(
148 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 7
149 ; CHECK-NEXT: ret i1 [[CMP]]
151 %shr = lshr i8 -128, %a
152 %cmp = icmp eq i8 %shr, 1
156 define i1 @exact_lshr_ne_opposite_msb(i8 %a) {
157 ; CHECK-LABEL: @exact_lshr_ne_opposite_msb(
158 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 7
159 ; CHECK-NEXT: ret i1 [[CMP]]
161 %shr = lshr exact i8 -128, %a
162 %cmp = icmp ne i8 %shr, 1
166 define i1 @lshr_ne_opposite_msb(i8 %a) {
167 ; CHECK-LABEL: @lshr_ne_opposite_msb(
168 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 7
169 ; CHECK-NEXT: ret i1 [[CMP]]
171 %shr = lshr i8 -128, %a
172 %cmp = icmp ne i8 %shr, 1
176 define i1 @exact_ashr_eq(i8 %a) {
177 ; CHECK-LABEL: @exact_ashr_eq(
178 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 7
179 ; CHECK-NEXT: ret i1 [[CMP]]
181 %shr = ashr exact i8 -128, %a
182 %cmp = icmp eq i8 %shr, -1
186 define i1 @exact_ashr_ne(i8 %a) {
187 ; CHECK-LABEL: @exact_ashr_ne(
188 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 7
189 ; CHECK-NEXT: ret i1 [[CMP]]
191 %shr = ashr exact i8 -128, %a
192 %cmp = icmp ne i8 %shr, -1
196 define i1 @exact_lshr_eq(i8 %a) {
197 ; CHECK-LABEL: @exact_lshr_eq(
198 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 2
199 ; CHECK-NEXT: ret i1 [[CMP]]
201 %shr = lshr exact i8 4, %a
202 %cmp = icmp eq i8 %shr, 1
206 define i1 @exact_lshr_ne(i8 %a) {
207 ; CHECK-LABEL: @exact_lshr_ne(
208 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 2
209 ; CHECK-NEXT: ret i1 [[CMP]]
211 %shr = lshr exact i8 4, %a
212 %cmp = icmp ne i8 %shr, 1
216 define i1 @nonexact_ashr_eq(i8 %a) {
217 ; CHECK-LABEL: @nonexact_ashr_eq(
218 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 7
219 ; CHECK-NEXT: ret i1 [[CMP]]
221 %shr = ashr i8 -128, %a
222 %cmp = icmp eq i8 %shr, -1
226 define i1 @nonexact_ashr_ne(i8 %a) {
227 ; CHECK-LABEL: @nonexact_ashr_ne(
228 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 7
229 ; CHECK-NEXT: ret i1 [[CMP]]
231 %shr = ashr i8 -128, %a
232 %cmp = icmp ne i8 %shr, -1
236 define i1 @nonexact_lshr_eq(i8 %a) {
237 ; CHECK-LABEL: @nonexact_lshr_eq(
238 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 2
239 ; CHECK-NEXT: ret i1 [[CMP]]
242 %cmp = icmp eq i8 %shr, 1
246 define i1 @nonexact_lshr_ne(i8 %a) {
247 ; CHECK-LABEL: @nonexact_lshr_ne(
248 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 2
249 ; CHECK-NEXT: ret i1 [[CMP]]
252 %cmp = icmp ne i8 %shr, 1
256 define i1 @exact_lshr_eq_exactdiv(i8 %a) {
257 ; CHECK-LABEL: @exact_lshr_eq_exactdiv(
258 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 4
259 ; CHECK-NEXT: ret i1 [[CMP]]
261 %shr = lshr exact i8 80, %a
262 %cmp = icmp eq i8 %shr, 5
266 define i1 @exact_lshr_ne_exactdiv(i8 %a) {
267 ; CHECK-LABEL: @exact_lshr_ne_exactdiv(
268 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 4
269 ; CHECK-NEXT: ret i1 [[CMP]]
271 %shr = lshr exact i8 80, %a
272 %cmp = icmp ne i8 %shr, 5
276 define i1 @nonexact_lshr_eq_exactdiv(i8 %a) {
277 ; CHECK-LABEL: @nonexact_lshr_eq_exactdiv(
278 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 4
279 ; CHECK-NEXT: ret i1 [[CMP]]
281 %shr = lshr i8 80, %a
282 %cmp = icmp eq i8 %shr, 5
286 define i1 @nonexact_lshr_ne_exactdiv(i8 %a) {
287 ; CHECK-LABEL: @nonexact_lshr_ne_exactdiv(
288 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 4
289 ; CHECK-NEXT: ret i1 [[CMP]]
291 %shr = lshr i8 80, %a
292 %cmp = icmp ne i8 %shr, 5
296 define i1 @exact_ashr_eq_exactdiv(i8 %a) {
297 ; CHECK-LABEL: @exact_ashr_eq_exactdiv(
298 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 4
299 ; CHECK-NEXT: ret i1 [[CMP]]
301 %shr = ashr exact i8 -80, %a
302 %cmp = icmp eq i8 %shr, -5
306 define i1 @exact_ashr_ne_exactdiv(i8 %a) {
307 ; CHECK-LABEL: @exact_ashr_ne_exactdiv(
308 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 4
309 ; CHECK-NEXT: ret i1 [[CMP]]
311 %shr = ashr exact i8 -80, %a
312 %cmp = icmp ne i8 %shr, -5
316 define i1 @nonexact_ashr_eq_exactdiv(i8 %a) {
317 ; CHECK-LABEL: @nonexact_ashr_eq_exactdiv(
318 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 4
319 ; CHECK-NEXT: ret i1 [[CMP]]
321 %shr = ashr i8 -80, %a
322 %cmp = icmp eq i8 %shr, -5
326 define i1 @nonexact_ashr_ne_exactdiv(i8 %a) {
327 ; CHECK-LABEL: @nonexact_ashr_ne_exactdiv(
328 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[A:%.*]], 4
329 ; CHECK-NEXT: ret i1 [[CMP]]
331 %shr = ashr i8 -80, %a
332 %cmp = icmp ne i8 %shr, -5
336 define i1 @exact_lshr_eq_noexactdiv(i8 %a) {
337 ; CHECK-LABEL: @exact_lshr_eq_noexactdiv(
338 ; CHECK-NEXT: ret i1 false
340 %shr = lshr exact i8 80, %a
341 %cmp = icmp eq i8 %shr, 31
345 define i1 @exact_lshr_ne_noexactdiv(i8 %a) {
346 ; CHECK-LABEL: @exact_lshr_ne_noexactdiv(
347 ; CHECK-NEXT: ret i1 true
349 %shr = lshr exact i8 80, %a
350 %cmp = icmp ne i8 %shr, 31
354 define i1 @nonexact_lshr_eq_noexactdiv(i8 %a) {
355 ; CHECK-LABEL: @nonexact_lshr_eq_noexactdiv(
356 ; CHECK-NEXT: ret i1 false
358 %shr = lshr i8 80, %a
359 %cmp = icmp eq i8 %shr, 31
363 define i1 @nonexact_lshr_ne_noexactdiv(i8 %a) {
364 ; CHECK-LABEL: @nonexact_lshr_ne_noexactdiv(
365 ; CHECK-NEXT: ret i1 true
367 %shr = lshr i8 80, %a
368 %cmp = icmp ne i8 %shr, 31
372 define i1 @exact_ashr_eq_noexactdiv(i8 %a) {
373 ; CHECK-LABEL: @exact_ashr_eq_noexactdiv(
374 ; CHECK-NEXT: ret i1 false
376 %shr = ashr exact i8 -80, %a
377 %cmp = icmp eq i8 %shr, -31
381 define i1 @exact_ashr_ne_noexactdiv(i8 %a) {
382 ; CHECK-LABEL: @exact_ashr_ne_noexactdiv(
383 ; CHECK-NEXT: ret i1 true
385 %shr = ashr exact i8 -80, %a
386 %cmp = icmp ne i8 %shr, -31
390 define i1 @nonexact_ashr_eq_noexactdiv(i8 %a) {
391 ; CHECK-LABEL: @nonexact_ashr_eq_noexactdiv(
392 ; CHECK-NEXT: ret i1 false
394 %shr = ashr i8 -80, %a
395 %cmp = icmp eq i8 %shr, -31
399 define i1 @nonexact_ashr_ne_noexactdiv(i8 %a) {
400 ; CHECK-LABEL: @nonexact_ashr_ne_noexactdiv(
401 ; CHECK-NEXT: ret i1 true
403 %shr = ashr i8 -80, %a
404 %cmp = icmp ne i8 %shr, -31
408 define i1 @nonexact_lshr_eq_noexactlog(i8 %a) {
409 ; CHECK-LABEL: @nonexact_lshr_eq_noexactlog(
410 ; CHECK-NEXT: ret i1 false
412 %shr = lshr i8 90, %a
413 %cmp = icmp eq i8 %shr, 30
417 define i1 @nonexact_lshr_ne_noexactlog(i8 %a) {
418 ; CHECK-LABEL: @nonexact_lshr_ne_noexactlog(
419 ; CHECK-NEXT: ret i1 true
421 %shr = lshr i8 90, %a
422 %cmp = icmp ne i8 %shr, 30
426 define i1 @nonexact_ashr_eq_noexactlog(i8 %a) {
427 ; CHECK-LABEL: @nonexact_ashr_eq_noexactlog(
428 ; CHECK-NEXT: ret i1 false
430 %shr = ashr i8 -90, %a
431 %cmp = icmp eq i8 %shr, -30
435 define i1 @nonexact_ashr_ne_noexactlog(i8 %a) {
436 ; CHECK-LABEL: @nonexact_ashr_ne_noexactlog(
437 ; CHECK-NEXT: ret i1 true
439 %shr = ashr i8 -90, %a
440 %cmp = icmp ne i8 %shr, -30
444 ; Don't try to fold the entire body of function @PR20945 into a
445 ; single `ret i1 true` statement.
446 ; If %B is equal to 1, then this function would return false.
447 ; As a consequence, the instruction combiner is not allowed to fold %cmp
448 ; to 'true'. Instead, it should replace %cmp with a simpler comparison
451 define i1 @PR20945(i32 %B) {
452 ; CHECK-LABEL: @PR20945(
453 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[B:%.*]], 1
454 ; CHECK-NEXT: ret i1 [[CMP]]
456 %shr = ashr i32 -9, %B
457 %cmp = icmp ne i32 %shr, -5
461 define i1 @PR21222(i32 %B) {
462 ; CHECK-LABEL: @PR21222(
463 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[B:%.*]], 6
464 ; CHECK-NEXT: ret i1 [[CMP]]
466 %shr = ashr i32 -93, %B
467 %cmp = icmp eq i32 %shr, -2
471 define i1 @PR24873(i64 %V) {
472 ; CHECK-LABEL: @PR24873(
473 ; CHECK-NEXT: [[ICMP:%.*]] = icmp ugt i64 [[V:%.*]], 61
474 ; CHECK-NEXT: ret i1 [[ICMP]]
476 %ashr = ashr i64 -4611686018427387904, %V
477 %icmp = icmp eq i64 %ashr, -1
481 declare void @foo(i32)
483 define i1 @exact_multiuse(i32 %x) {
484 ; CHECK-LABEL: @exact_multiuse(
485 ; CHECK-NEXT: [[SH:%.*]] = lshr exact i32 [[X:%.*]], 7
486 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], 131072
487 ; CHECK-NEXT: call void @foo(i32 [[SH]])
488 ; CHECK-NEXT: ret i1 [[CMP]]
490 %sh = lshr exact i32 %x, 7
491 %cmp = icmp eq i32 %sh, 1024
492 call void @foo(i32 %sh)
496 declare void @foo2(<2 x i32>)
497 define <2 x i1> @exact_eq0_multiuse(<2 x i32> %x, <2 x i32> %y) {
498 ; CHECK-LABEL: @exact_eq0_multiuse(
499 ; CHECK-NEXT: [[SH:%.*]] = ashr exact <2 x i32> [[X:%.*]], [[Y:%.*]]
500 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SH]], zeroinitializer
501 ; CHECK-NEXT: call void @foo2(<2 x i32> [[SH]])
502 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
504 %sh = ashr exact <2 x i32> %x, %y
505 %cmp = icmp eq <2 x i32> %sh, zeroinitializer
506 call void @foo2(<2 x i32> %sh)
510 ; Verify conversions of ashr+icmp to a sign-bit test.
512 ; negative test, but different transform possible
514 define i1 @ashr_ugt_0(i4 %x) {
515 ; CHECK-LABEL: @ashr_ugt_0(
516 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], 1
517 ; CHECK-NEXT: ret i1 [[R]]
520 %r = icmp ugt i4 %s, 0 ; 0b0000
526 define i1 @ashr_ugt_1(i4 %x) {
527 ; CHECK-LABEL: @ashr_ugt_1(
528 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
529 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 1
530 ; CHECK-NEXT: ret i1 [[R]]
533 %r = icmp ugt i4 %s, 1 ; 0b0001
539 define i1 @ashr_ugt_2(i4 %x) {
540 ; CHECK-LABEL: @ashr_ugt_2(
541 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
542 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 2
543 ; CHECK-NEXT: ret i1 [[R]]
546 %r = icmp ugt i4 %s, 2 ; 0b0010
551 ; TODO: This is a sign-bit test, but we don't recognize the pattern.
553 define i1 @ashr_ugt_3(i4 %x) {
554 ; CHECK-LABEL: @ashr_ugt_3(
555 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
556 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 3
557 ; CHECK-NEXT: ret i1 [[R]]
560 %r = icmp ugt i4 %s, 3 ; 0b0011
564 define i1 @ashr_ugt_4(i4 %x) {
565 ; CHECK-LABEL: @ashr_ugt_4(
566 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
567 ; CHECK-NEXT: ret i1 [[R]]
570 %r = icmp ugt i4 %s, 4 ; 0b0100
574 define i1 @ashr_ugt_5(i4 %x) {
575 ; CHECK-LABEL: @ashr_ugt_5(
576 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
577 ; CHECK-NEXT: ret i1 [[R]]
580 %r = icmp ugt i4 %s, 5 ; 0b0101
584 define i1 @ashr_ugt_6(i4 %x) {
585 ; CHECK-LABEL: @ashr_ugt_6(
586 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
587 ; CHECK-NEXT: ret i1 [[R]]
590 %r = icmp ugt i4 %s, 6 ; 0b0110
594 define i1 @ashr_ugt_7(i4 %x) {
595 ; CHECK-LABEL: @ashr_ugt_7(
596 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
597 ; CHECK-NEXT: ret i1 [[R]]
600 %r = icmp ugt i4 %s, 7 ; 0b0111
604 define i1 @ashr_ugt_8(i4 %x) {
605 ; CHECK-LABEL: @ashr_ugt_8(
606 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
607 ; CHECK-NEXT: ret i1 [[R]]
610 %r = icmp ugt i4 %s, 8 ; 0b1000
614 define i1 @ashr_ugt_9(i4 %x) {
615 ; CHECK-LABEL: @ashr_ugt_9(
616 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
617 ; CHECK-NEXT: ret i1 [[R]]
620 %r = icmp ugt i4 %s, 9 ; 0b1001
624 define i1 @ashr_ugt_10(i4 %x) {
625 ; CHECK-LABEL: @ashr_ugt_10(
626 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
627 ; CHECK-NEXT: ret i1 [[R]]
630 %r = icmp ugt i4 %s, 10 ; 0b1010
634 define i1 @ashr_ugt_11(i4 %x) {
635 ; CHECK-LABEL: @ashr_ugt_11(
636 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
637 ; CHECK-NEXT: ret i1 [[R]]
640 %r = icmp ugt i4 %s, 11 ; 0b1011
646 define i1 @ashr_ugt_12(i4 %x) {
647 ; CHECK-LABEL: @ashr_ugt_12(
648 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
649 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -4
650 ; CHECK-NEXT: ret i1 [[R]]
653 %r = icmp ugt i4 %s, 12 ; 0b1100
659 define i1 @ashr_ugt_13(i4 %x) {
660 ; CHECK-LABEL: @ashr_ugt_13(
661 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
662 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -3
663 ; CHECK-NEXT: ret i1 [[R]]
666 %r = icmp ugt i4 %s, 13 ; 0b1101
670 ; negative test, but different transform possible
672 define i1 @ashr_ugt_14(i4 %x) {
673 ; CHECK-LABEL: @ashr_ugt_14(
674 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], -3
675 ; CHECK-NEXT: ret i1 [[R]]
678 %r = icmp ugt i4 %s, 14 ; 0b1110
682 ; negative test, but simplifies
684 define i1 @ashr_ugt_15(i4 %x) {
685 ; CHECK-LABEL: @ashr_ugt_15(
686 ; CHECK-NEXT: ret i1 false
689 %r = icmp ugt i4 %s, 15 ; 0b1111
693 ; negative test, but simplifies
695 define i1 @ashr_ult_0(i4 %x) {
696 ; CHECK-LABEL: @ashr_ult_0(
697 ; CHECK-NEXT: ret i1 false
700 %r = icmp ult i4 %s, 0 ; 0b0000
704 ; negative test, but different transform possible
706 define i1 @ashr_ult_1(i4 %x) {
707 ; CHECK-LABEL: @ashr_ult_1(
708 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], 2
709 ; CHECK-NEXT: ret i1 [[R]]
712 %r = icmp ult i4 %s, 1 ; 0b0001
718 define i1 @ashr_ult_2(i4 %x) {
719 ; CHECK-LABEL: @ashr_ult_2(
720 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
721 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], 2
722 ; CHECK-NEXT: ret i1 [[R]]
725 %r = icmp ult i4 %s, 2 ; 0b0010
731 define i1 @ashr_ult_3(i4 %x) {
732 ; CHECK-LABEL: @ashr_ult_3(
733 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
734 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], 3
735 ; CHECK-NEXT: ret i1 [[R]]
738 %r = icmp ult i4 %s, 3 ; 0b0011
742 define i1 @ashr_ult_4(i4 %x) {
743 ; CHECK-LABEL: @ashr_ult_4(
744 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
745 ; CHECK-NEXT: ret i1 [[R]]
748 %r = icmp ult i4 %s, 4 ; 0b0100
752 define i1 @ashr_ult_5(i4 %x) {
753 ; CHECK-LABEL: @ashr_ult_5(
754 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
755 ; CHECK-NEXT: ret i1 [[R]]
758 %r = icmp ult i4 %s, 5 ; 0b0101
762 define i1 @ashr_ult_6(i4 %x) {
763 ; CHECK-LABEL: @ashr_ult_6(
764 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
765 ; CHECK-NEXT: ret i1 [[R]]
768 %r = icmp ult i4 %s, 6 ; 0b0110
772 define i1 @ashr_ult_7(i4 %x) {
773 ; CHECK-LABEL: @ashr_ult_7(
774 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
775 ; CHECK-NEXT: ret i1 [[R]]
778 %r = icmp ult i4 %s, 7 ; 0b0111
782 define i1 @ashr_ult_8(i4 %x) {
783 ; CHECK-LABEL: @ashr_ult_8(
784 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
785 ; CHECK-NEXT: ret i1 [[R]]
788 %r = icmp ult i4 %s, 8 ; 0b1000
792 define i1 @ashr_ult_9(i4 %x) {
793 ; CHECK-LABEL: @ashr_ult_9(
794 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
795 ; CHECK-NEXT: ret i1 [[R]]
798 %r = icmp ult i4 %s, 9 ; 0b1001
802 define i1 @ashr_ult_10(i4 %x) {
803 ; CHECK-LABEL: @ashr_ult_10(
804 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
805 ; CHECK-NEXT: ret i1 [[R]]
808 %r = icmp ult i4 %s, 10 ; 0b1010
812 define i1 @ashr_ult_11(i4 %x) {
813 ; CHECK-LABEL: @ashr_ult_11(
814 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
815 ; CHECK-NEXT: ret i1 [[R]]
818 %r = icmp ult i4 %s, 11 ; 0b1011
823 ; TODO: This is a sign-bit test, but we don't recognize the pattern.
825 define i1 @ashr_ult_12(i4 %x) {
826 ; CHECK-LABEL: @ashr_ult_12(
827 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
828 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], -4
829 ; CHECK-NEXT: ret i1 [[R]]
832 %r = icmp ult i4 %s, 12 ; 0b1100
838 define i1 @ashr_ult_13(i4 %x) {
839 ; CHECK-LABEL: @ashr_ult_13(
840 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
841 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], -3
842 ; CHECK-NEXT: ret i1 [[R]]
845 %r = icmp ult i4 %s, 13 ; 0b1101
851 define i1 @ashr_ult_14(i4 %x) {
852 ; CHECK-LABEL: @ashr_ult_14(
853 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
854 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], -2
855 ; CHECK-NEXT: ret i1 [[R]]
858 %r = icmp ult i4 %s, 14 ; 0b1110
862 ; negative test, but different transform possible
864 define i1 @ashr_ult_15(i4 %x) {
865 ; CHECK-LABEL: @ashr_ult_15(
866 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], -2
867 ; CHECK-NEXT: ret i1 [[R]]
870 %r = icmp ult i4 %s, 15 ; 0b1111
874 define i1 @lshr_eq_0_multiuse(i8 %x) {
875 ; CHECK-LABEL: @lshr_eq_0_multiuse(
876 ; CHECK-NEXT: [[S:%.*]] = lshr i8 [[X:%.*]], 2
877 ; CHECK-NEXT: call void @use(i8 [[S]])
878 ; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[X]], 4
879 ; CHECK-NEXT: ret i1 [[C]]
882 call void @use(i8 %s)
883 %c = icmp eq i8 %s, 0
887 define i1 @lshr_ne_0_multiuse(i8 %x) {
888 ; CHECK-LABEL: @lshr_ne_0_multiuse(
889 ; CHECK-NEXT: [[S:%.*]] = lshr i8 [[X:%.*]], 2
890 ; CHECK-NEXT: call void @use(i8 [[S]])
891 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X]], 3
892 ; CHECK-NEXT: ret i1 [[C]]
895 call void @use(i8 %s)
896 %c = icmp ne i8 %s, 0
900 define i1 @ashr_eq_0_multiuse(i8 %x) {
901 ; CHECK-LABEL: @ashr_eq_0_multiuse(
902 ; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 2
903 ; CHECK-NEXT: call void @use(i8 [[S]])
904 ; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[X]], 4
905 ; CHECK-NEXT: ret i1 [[C]]
908 call void @use(i8 %s)
909 %c = icmp eq i8 %s, 0
913 define i1 @ashr_ne_0_multiuse(i8 %x) {
914 ; CHECK-LABEL: @ashr_ne_0_multiuse(
915 ; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 2
916 ; CHECK-NEXT: call void @use(i8 [[S]])
917 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X]], 3
918 ; CHECK-NEXT: ret i1 [[C]]
921 call void @use(i8 %s)
922 %c = icmp ne i8 %s, 0
926 define i1 @lshr_exact_eq_0_multiuse(i8 %x) {
927 ; CHECK-LABEL: @lshr_exact_eq_0_multiuse(
928 ; CHECK-NEXT: [[S:%.*]] = lshr exact i8 [[X:%.*]], 2
929 ; CHECK-NEXT: call void @use(i8 [[S]])
930 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X]], 0
931 ; CHECK-NEXT: ret i1 [[C]]
933 %s = lshr exact i8 %x, 2
934 call void @use(i8 %s)
935 %c = icmp eq i8 %s, 0
939 define i1 @lshr_exact_ne_0_multiuse(i8 %x) {
940 ; CHECK-LABEL: @lshr_exact_ne_0_multiuse(
941 ; CHECK-NEXT: [[S:%.*]] = lshr exact i8 [[X:%.*]], 2
942 ; CHECK-NEXT: call void @use(i8 [[S]])
943 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], 0
944 ; CHECK-NEXT: ret i1 [[C]]
946 %s = lshr exact i8 %x, 2
947 call void @use(i8 %s)
948 %c = icmp ne i8 %s, 0
952 define i1 @ashr_exact_eq_0_multiuse(i8 %x) {
953 ; CHECK-LABEL: @ashr_exact_eq_0_multiuse(
954 ; CHECK-NEXT: [[S:%.*]] = ashr exact i8 [[X:%.*]], 2
955 ; CHECK-NEXT: call void @use(i8 [[S]])
956 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X]], 0
957 ; CHECK-NEXT: ret i1 [[C]]
959 %s = ashr exact i8 %x, 2
960 call void @use(i8 %s)
961 %c = icmp eq i8 %s, 0
965 define i1 @ashr_exact_ne_0_multiuse(i8 %x) {
966 ; CHECK-LABEL: @ashr_exact_ne_0_multiuse(
967 ; CHECK-NEXT: [[S:%.*]] = ashr exact i8 [[X:%.*]], 2
968 ; CHECK-NEXT: call void @use(i8 [[S]])
969 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], 0
970 ; CHECK-NEXT: ret i1 [[C]]
972 %s = ashr exact i8 %x, 2
973 call void @use(i8 %s)
974 %c = icmp ne i8 %s, 0
978 declare void @use(i8)