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)