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)
497 define i1 @ashr_exact_eq_0(i32 %X, i32 %Y) {
498 ; CHECK-LABEL: @ashr_exact_eq_0(
499 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[X:%.*]], 0
500 ; CHECK-NEXT: ret i1 [[B]]
502 %A = ashr exact i32 %X, %Y
503 %B = icmp eq i32 %A, 0
507 define i1 @ashr_exact_ne_0_uses(i32 %X, i32 %Y) {
508 ; CHECK-LABEL: @ashr_exact_ne_0_uses(
509 ; CHECK-NEXT: [[A:%.*]] = ashr exact i32 [[X:%.*]], [[Y:%.*]]
510 ; CHECK-NEXT: call void @foo(i32 [[A]])
511 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[X]], 0
512 ; CHECK-NEXT: ret i1 [[B]]
514 %A = ashr exact i32 %X, %Y
515 call void @foo(i32 %A)
516 %B = icmp ne i32 %A, 0
520 define <2 x i1> @ashr_exact_eq_0_vec(<2 x i32> %X, <2 x i32> %Y) {
521 ; CHECK-LABEL: @ashr_exact_eq_0_vec(
522 ; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i32> [[X:%.*]], zeroinitializer
523 ; CHECK-NEXT: ret <2 x i1> [[B]]
525 %A = ashr exact <2 x i32> %X, %Y
526 %B = icmp eq <2 x i32> %A, zeroinitializer
530 define i1 @lshr_exact_ne_0(i32 %X, i32 %Y) {
531 ; CHECK-LABEL: @lshr_exact_ne_0(
532 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[X:%.*]], 0
533 ; CHECK-NEXT: ret i1 [[B]]
535 %A = lshr exact i32 %X, %Y
536 %B = icmp ne i32 %A, 0
540 define i1 @lshr_exact_eq_0_uses(i32 %X, i32 %Y) {
541 ; CHECK-LABEL: @lshr_exact_eq_0_uses(
542 ; CHECK-NEXT: [[A:%.*]] = lshr exact i32 [[X:%.*]], [[Y:%.*]]
543 ; CHECK-NEXT: call void @foo(i32 [[A]])
544 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[X]], 0
545 ; CHECK-NEXT: ret i1 [[B]]
547 %A = lshr exact i32 %X, %Y
548 call void @foo(i32 %A)
549 %B = icmp eq i32 %A, 0
553 define <2 x i1> @lshr_exact_ne_0_vec(<2 x i32> %X, <2 x i32> %Y) {
554 ; CHECK-LABEL: @lshr_exact_ne_0_vec(
555 ; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i32> [[X:%.*]], zeroinitializer
556 ; CHECK-NEXT: ret <2 x i1> [[B]]
558 %A = lshr exact <2 x i32> %X, %Y
559 %B = icmp ne <2 x i32> %A, zeroinitializer
563 ; Verify conversions of ashr+icmp to a sign-bit test.
565 ; negative test, but different transform possible
567 define i1 @ashr_ugt_0(i4 %x) {
568 ; CHECK-LABEL: @ashr_ugt_0(
569 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], 1
570 ; CHECK-NEXT: ret i1 [[R]]
573 %r = icmp ugt i4 %s, 0 ; 0b0000
579 define i1 @ashr_ugt_1(i4 %x) {
580 ; CHECK-LABEL: @ashr_ugt_1(
581 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
582 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 1
583 ; CHECK-NEXT: ret i1 [[R]]
586 %r = icmp ugt i4 %s, 1 ; 0b0001
592 define i1 @ashr_ugt_2(i4 %x) {
593 ; CHECK-LABEL: @ashr_ugt_2(
594 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
595 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 2
596 ; CHECK-NEXT: ret i1 [[R]]
599 %r = icmp ugt i4 %s, 2 ; 0b0010
604 ; TODO: This is a sign-bit test, but we don't recognize the pattern.
606 define i1 @ashr_ugt_3(i4 %x) {
607 ; CHECK-LABEL: @ashr_ugt_3(
608 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
609 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 3
610 ; CHECK-NEXT: ret i1 [[R]]
613 %r = icmp ugt i4 %s, 3 ; 0b0011
617 define i1 @ashr_ugt_4(i4 %x) {
618 ; CHECK-LABEL: @ashr_ugt_4(
619 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
620 ; CHECK-NEXT: ret i1 [[R]]
623 %r = icmp ugt i4 %s, 4 ; 0b0100
627 define i1 @ashr_ugt_5(i4 %x) {
628 ; CHECK-LABEL: @ashr_ugt_5(
629 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
630 ; CHECK-NEXT: ret i1 [[R]]
633 %r = icmp ugt i4 %s, 5 ; 0b0101
637 define i1 @ashr_ugt_6(i4 %x) {
638 ; CHECK-LABEL: @ashr_ugt_6(
639 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
640 ; CHECK-NEXT: ret i1 [[R]]
643 %r = icmp ugt i4 %s, 6 ; 0b0110
647 define i1 @ashr_ugt_7(i4 %x) {
648 ; CHECK-LABEL: @ashr_ugt_7(
649 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
650 ; CHECK-NEXT: ret i1 [[R]]
653 %r = icmp ugt i4 %s, 7 ; 0b0111
657 define i1 @ashr_ugt_8(i4 %x) {
658 ; CHECK-LABEL: @ashr_ugt_8(
659 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
660 ; CHECK-NEXT: ret i1 [[R]]
663 %r = icmp ugt i4 %s, 8 ; 0b1000
667 define i1 @ashr_ugt_9(i4 %x) {
668 ; CHECK-LABEL: @ashr_ugt_9(
669 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
670 ; CHECK-NEXT: ret i1 [[R]]
673 %r = icmp ugt i4 %s, 9 ; 0b1001
677 define i1 @ashr_ugt_10(i4 %x) {
678 ; CHECK-LABEL: @ashr_ugt_10(
679 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
680 ; CHECK-NEXT: ret i1 [[R]]
683 %r = icmp ugt i4 %s, 10 ; 0b1010
687 define i1 @ashr_ugt_11(i4 %x) {
688 ; CHECK-LABEL: @ashr_ugt_11(
689 ; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
690 ; CHECK-NEXT: ret i1 [[R]]
693 %r = icmp ugt i4 %s, 11 ; 0b1011
699 define i1 @ashr_ugt_12(i4 %x) {
700 ; CHECK-LABEL: @ashr_ugt_12(
701 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
702 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -4
703 ; CHECK-NEXT: ret i1 [[R]]
706 %r = icmp ugt i4 %s, 12 ; 0b1100
712 define i1 @ashr_ugt_13(i4 %x) {
713 ; CHECK-LABEL: @ashr_ugt_13(
714 ; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
715 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -3
716 ; CHECK-NEXT: ret i1 [[R]]
719 %r = icmp ugt i4 %s, 13 ; 0b1101
723 ; negative test, but different transform possible
725 define i1 @ashr_ugt_14(i4 %x) {
726 ; CHECK-LABEL: @ashr_ugt_14(
727 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], -3
728 ; CHECK-NEXT: ret i1 [[R]]
731 %r = icmp ugt i4 %s, 14 ; 0b1110
735 ; negative test, but simplifies
737 define i1 @ashr_ugt_15(i4 %x) {
738 ; CHECK-LABEL: @ashr_ugt_15(
739 ; CHECK-NEXT: ret i1 false
742 %r = icmp ugt i4 %s, 15 ; 0b1111
746 ; negative test, but simplifies
748 define i1 @ashr_ult_0(i4 %x) {
749 ; CHECK-LABEL: @ashr_ult_0(
750 ; CHECK-NEXT: ret i1 false
753 %r = icmp ult i4 %s, 0 ; 0b0000
757 ; negative test, but different transform possible
759 define i1 @ashr_ult_1(i4 %x) {
760 ; CHECK-LABEL: @ashr_ult_1(
761 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], 2
762 ; CHECK-NEXT: ret i1 [[R]]
765 %r = icmp ult i4 %s, 1 ; 0b0001
771 define i1 @ashr_ult_2(i4 %x) {
772 ; CHECK-LABEL: @ashr_ult_2(
773 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], 4
774 ; CHECK-NEXT: ret i1 [[R]]
777 %r = icmp ult i4 %s, 2 ; 0b0010
783 define i1 @ashr_ult_3(i4 %x) {
784 ; CHECK-LABEL: @ashr_ult_3(
785 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], 6
786 ; CHECK-NEXT: ret i1 [[R]]
789 %r = icmp ult i4 %s, 3 ; 0b0011
793 define i1 @ashr_ult_4(i4 %x) {
794 ; CHECK-LABEL: @ashr_ult_4(
795 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
796 ; CHECK-NEXT: ret i1 [[R]]
799 %r = icmp ult i4 %s, 4 ; 0b0100
803 define i1 @ashr_ult_5(i4 %x) {
804 ; CHECK-LABEL: @ashr_ult_5(
805 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
806 ; CHECK-NEXT: ret i1 [[R]]
809 %r = icmp ult i4 %s, 5 ; 0b0101
813 define i1 @ashr_ult_6(i4 %x) {
814 ; CHECK-LABEL: @ashr_ult_6(
815 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
816 ; CHECK-NEXT: ret i1 [[R]]
819 %r = icmp ult i4 %s, 6 ; 0b0110
823 define i1 @ashr_ult_7(i4 %x) {
824 ; CHECK-LABEL: @ashr_ult_7(
825 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
826 ; CHECK-NEXT: ret i1 [[R]]
829 %r = icmp ult i4 %s, 7 ; 0b0111
833 define i1 @ashr_ult_8(i4 %x) {
834 ; CHECK-LABEL: @ashr_ult_8(
835 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
836 ; CHECK-NEXT: ret i1 [[R]]
839 %r = icmp ult i4 %s, 8 ; 0b1000
843 define i1 @ashr_ult_9(i4 %x) {
844 ; CHECK-LABEL: @ashr_ult_9(
845 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
846 ; CHECK-NEXT: ret i1 [[R]]
849 %r = icmp ult i4 %s, 9 ; 0b1001
853 define i1 @ashr_ult_10(i4 %x) {
854 ; CHECK-LABEL: @ashr_ult_10(
855 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
856 ; CHECK-NEXT: ret i1 [[R]]
859 %r = icmp ult i4 %s, 10 ; 0b1010
863 define i1 @ashr_ult_11(i4 %x) {
864 ; CHECK-LABEL: @ashr_ult_11(
865 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
866 ; CHECK-NEXT: ret i1 [[R]]
869 %r = icmp ult i4 %s, 11 ; 0b1011
874 ; TODO: This is a sign-bit test, but we don't recognize the pattern.
876 define i1 @ashr_ult_12(i4 %x) {
877 ; CHECK-LABEL: @ashr_ult_12(
878 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1
879 ; CHECK-NEXT: ret i1 [[R]]
882 %r = icmp ult i4 %s, 12 ; 0b1100
888 define i1 @ashr_ult_13(i4 %x) {
889 ; CHECK-LABEL: @ashr_ult_13(
890 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], -6
891 ; CHECK-NEXT: ret i1 [[R]]
894 %r = icmp ult i4 %s, 13 ; 0b1101
900 define i1 @ashr_ult_14(i4 %x) {
901 ; CHECK-LABEL: @ashr_ult_14(
902 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], -4
903 ; CHECK-NEXT: ret i1 [[R]]
906 %r = icmp ult i4 %s, 14 ; 0b1110
910 ; negative test, but different transform possible
912 define i1 @ashr_ult_15(i4 %x) {
913 ; CHECK-LABEL: @ashr_ult_15(
914 ; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], -2
915 ; CHECK-NEXT: ret i1 [[R]]
918 %r = icmp ult i4 %s, 15 ; 0b1111
922 define i1 @lshr_eq_0_multiuse(i8 %x) {
923 ; CHECK-LABEL: @lshr_eq_0_multiuse(
924 ; CHECK-NEXT: [[S:%.*]] = lshr i8 [[X:%.*]], 2
925 ; CHECK-NEXT: call void @use(i8 [[S]])
926 ; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[X]], 4
927 ; CHECK-NEXT: ret i1 [[C]]
930 call void @use(i8 %s)
931 %c = icmp eq i8 %s, 0
935 define i1 @lshr_ne_0_multiuse(i8 %x) {
936 ; CHECK-LABEL: @lshr_ne_0_multiuse(
937 ; CHECK-NEXT: [[S:%.*]] = lshr i8 [[X:%.*]], 2
938 ; CHECK-NEXT: call void @use(i8 [[S]])
939 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X]], 3
940 ; CHECK-NEXT: ret i1 [[C]]
943 call void @use(i8 %s)
944 %c = icmp ne i8 %s, 0
948 define i1 @ashr_eq_0_multiuse(i8 %x) {
949 ; CHECK-LABEL: @ashr_eq_0_multiuse(
950 ; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 2
951 ; CHECK-NEXT: call void @use(i8 [[S]])
952 ; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[X]], 4
953 ; CHECK-NEXT: ret i1 [[C]]
956 call void @use(i8 %s)
957 %c = icmp eq i8 %s, 0
961 define i1 @ashr_ne_0_multiuse(i8 %x) {
962 ; CHECK-LABEL: @ashr_ne_0_multiuse(
963 ; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 2
964 ; CHECK-NEXT: call void @use(i8 [[S]])
965 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X]], 3
966 ; CHECK-NEXT: ret i1 [[C]]
969 call void @use(i8 %s)
970 %c = icmp ne i8 %s, 0
974 define i1 @lshr_exact_eq_0_multiuse(i8 %x) {
975 ; CHECK-LABEL: @lshr_exact_eq_0_multiuse(
976 ; CHECK-NEXT: [[S:%.*]] = lshr exact i8 [[X:%.*]], 2
977 ; CHECK-NEXT: call void @use(i8 [[S]])
978 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X]], 0
979 ; CHECK-NEXT: ret i1 [[C]]
981 %s = lshr exact i8 %x, 2
982 call void @use(i8 %s)
983 %c = icmp eq i8 %s, 0
987 define i1 @lshr_exact_ne_0_multiuse(i8 %x) {
988 ; CHECK-LABEL: @lshr_exact_ne_0_multiuse(
989 ; CHECK-NEXT: [[S:%.*]] = lshr exact i8 [[X:%.*]], 2
990 ; CHECK-NEXT: call void @use(i8 [[S]])
991 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], 0
992 ; CHECK-NEXT: ret i1 [[C]]
994 %s = lshr exact i8 %x, 2
995 call void @use(i8 %s)
996 %c = icmp ne i8 %s, 0
1000 define i1 @ashr_exact_eq_0_multiuse(i8 %x) {
1001 ; CHECK-LABEL: @ashr_exact_eq_0_multiuse(
1002 ; CHECK-NEXT: [[S:%.*]] = ashr exact i8 [[X:%.*]], 2
1003 ; CHECK-NEXT: call void @use(i8 [[S]])
1004 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X]], 0
1005 ; CHECK-NEXT: ret i1 [[C]]
1007 %s = ashr exact i8 %x, 2
1008 call void @use(i8 %s)
1009 %c = icmp eq i8 %s, 0
1013 define i1 @ashr_exact_ne_0_multiuse(i8 %x) {
1014 ; CHECK-LABEL: @ashr_exact_ne_0_multiuse(
1015 ; CHECK-NEXT: [[S:%.*]] = ashr exact i8 [[X:%.*]], 2
1016 ; CHECK-NEXT: call void @use(i8 [[S]])
1017 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X]], 0
1018 ; CHECK-NEXT: ret i1 [[C]]
1020 %s = ashr exact i8 %x, 2
1021 call void @use(i8 %s)
1022 %c = icmp ne i8 %s, 0
1026 declare void @use(i8)