1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3 ; RUN: opt < %s -passes=instcombine -use-constant-int-for-fixed-length-splat -S | FileCheck %s
6 declare void @use_i32(i32)
8 declare i32 @llvm.cttz.i32(i32, i1 immarg)
9 declare <2 x i8> @llvm.cttz.v2i8(<2 x i8>, i1 immarg)
11 define <4 x i32> @lshr_non_splat_vector(<4 x i32> %A) {
12 ; CHECK-LABEL: @lshr_non_splat_vector(
13 ; CHECK-NEXT: [[B:%.*]] = lshr <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
14 ; CHECK-NEXT: ret <4 x i32> [[B]]
16 %B = lshr <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
20 define <4 x i32> @shl_non_splat_vector(<4 x i32> %A) {
21 ; CHECK-LABEL: @shl_non_splat_vector(
22 ; CHECK-NEXT: [[B:%.*]] = shl <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
23 ; CHECK-NEXT: ret <4 x i32> [[B]]
25 %B = shl <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
29 define i32 @test6(i32 %A) {
30 ; CHECK-LABEL: @test6(
31 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
32 ; CHECK-NEXT: ret i32 [[C]]
34 %B = shl i32 %A, 1 ;; convert to an mul instruction
39 define i32 @test6a(i32 %A) {
40 ; CHECK-LABEL: @test6a(
41 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
42 ; CHECK-NEXT: ret i32 [[C]]
45 %C = shl i32 %B, 1 ;; convert to an mul instruction
49 ;; (A << 5) << 3 === A << 8 == 0
50 define i8 @test8(i8 %A) {
51 ; CHECK-LABEL: @test8(
52 ; CHECK-NEXT: ret i8 0
59 ;; (A << 7) >> 7 === A & 1
60 define i8 @test9(i8 %A) {
61 ; CHECK-LABEL: @test9(
62 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], 1
63 ; CHECK-NEXT: ret i8 [[B]]
70 ;; (A >> 7) << 7 === A & 128
72 define i8 @test10(i8 %A) {
73 ; CHECK-LABEL: @test10(
74 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], -128
75 ; CHECK-NEXT: ret i8 [[B]]
82 ;; Allow the simplification when the lshr shift is exact.
83 define i8 @test10a(i8 %A) {
84 ; CHECK-LABEL: @test10a(
85 ; CHECK-NEXT: ret i8 [[A:%.*]]
87 %B = lshr exact i8 %A, 7
92 ;; (A >> 3) << 4 === (A & 0x1F) << 1
93 define i8 @test11(i8 %x) {
94 ; CHECK-LABEL: @test11(
95 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
96 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
97 ; CHECK-NEXT: ret i8 [[C]]
105 ;; Allow the simplification in InstCombine when the lshr shift is exact.
106 define i8 @test11a(i8 %A) {
107 ; CHECK-LABEL: @test11a(
108 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
109 ; CHECK-NEXT: ret i8 [[C]]
112 %B = lshr exact i8 %a, 3
117 ;; (A >> 8) << 8 === A & -256
118 define i32 @test12(i32 %A) {
119 ; CHECK-LABEL: @test12(
120 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -256
121 ; CHECK-NEXT: ret i32 [[B]]
128 ;; ((A >>s 6) << 6 === (A & FFFFFFC0)
129 define i8 @shishi(i8 %x) {
130 ; CHECK-LABEL: @shishi(
131 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 6
132 ; CHECK-NEXT: [[B:%.*]] = and i8 [[X]], -64
133 ; CHECK-NEXT: [[EXTRA_USE_OF_A:%.*]] = mul nsw i8 [[A]], 5
134 ; CHECK-NEXT: [[R:%.*]] = sdiv i8 [[EXTRA_USE_OF_A]], [[B]]
135 ; CHECK-NEXT: ret i8 [[R]]
139 %extra_use_of_a = mul i8 %a, 5
140 %r = sdiv i8 %extra_use_of_a, %b
144 ;; (A >> 3) << 4 === (A & -8) * 2
145 define i8 @test13(i8 %x) {
146 ; CHECK-LABEL: @test13(
147 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
148 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
149 ; CHECK-NEXT: ret i8 [[C]]
157 define i8 @test13a(i8 %A) {
158 ; CHECK-LABEL: @test13a(
159 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
160 ; CHECK-NEXT: ret i8 [[C]]
163 %B = ashr exact i8 %a, 3
168 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
169 define i32 @test14(i32 %A) {
170 ; CHECK-LABEL: @test14(
171 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -19760
172 ; CHECK-NEXT: [[C:%.*]] = or disjoint i32 [[B]], 19744
173 ; CHECK-NEXT: ret i32 [[C]]
181 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
182 define i32 @test14a(i32 %A) {
183 ; CHECK-LABEL: @test14a(
184 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], 77
185 ; CHECK-NEXT: ret i32 [[C]]
188 %C = and i32 %B, 1234
193 define i32 @test15(i1 %C) {
194 ; CHECK-LABEL: @test15(
195 ; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], i32 12, i32 4
196 ; CHECK-NEXT: ret i32 [[A]]
198 %A = select i1 %C, i32 3, i32 1
203 define i32 @test15a(i1 %C) {
204 ; CHECK-LABEL: @test15a(
205 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], i32 512, i32 128
206 ; CHECK-NEXT: ret i32 [[V]]
208 %A = select i1 %C, i8 3, i8 1
209 %shift.upgrd.4 = zext i8 %A to i32
210 %V = shl i32 64, %shift.upgrd.4
214 define i1 @test16(i32 %X) {
215 ; CHECK-LABEL: @test16(
216 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 16
217 ; CHECK-NEXT: [[I_7:%.*]] = icmp ne i32 [[TMP1]], 0
218 ; CHECK-NEXT: ret i1 [[I_7]]
220 %i.3 = ashr i32 %X, 4
221 %i.6 = and i32 %i.3, 1
222 %i.7 = icmp ne i32 %i.6, 0
226 define i1 @test17(i32 %A) {
227 ; CHECK-LABEL: @test17(
228 ; CHECK-NEXT: [[B_MASK:%.*]] = and i32 [[A:%.*]], -8
229 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[B_MASK]], 9872
230 ; CHECK-NEXT: ret i1 [[C]]
233 %C = icmp eq i32 %B, 1234
237 define <2 x i1> @test17vec(<2 x i32> %A) {
238 ; CHECK-LABEL: @test17vec(
239 ; CHECK-NEXT: [[B_MASK:%.*]] = and <2 x i32> [[A:%.*]], splat (i32 -8)
240 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[B_MASK]], splat (i32 9872)
241 ; CHECK-NEXT: ret <2 x i1> [[C]]
243 %B = lshr <2 x i32> %A, <i32 3, i32 3>
244 %C = icmp eq <2 x i32> %B, <i32 1234, i32 1234>
248 define i1 @test18(i8 %A) {
249 ; CHECK-LABEL: @test18(
250 ; CHECK-NEXT: ret i1 false
254 %C = icmp eq i8 %B, 123
258 define i1 @test19(i32 %A) {
259 ; CHECK-LABEL: @test19(
260 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A:%.*]], 4
261 ; CHECK-NEXT: ret i1 [[C]]
265 %C = icmp eq i32 %B, 0
269 define <2 x i1> @test19vec(<2 x i32> %A) {
270 ; CHECK-LABEL: @test19vec(
271 ; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i32> [[A:%.*]], splat (i32 4)
272 ; CHECK-NEXT: ret <2 x i1> [[C]]
274 %B = ashr <2 x i32> %A, <i32 2, i32 2>
275 %C = icmp eq <2 x i32> %B, zeroinitializer
280 define i1 @test19a(i32 %A) {
281 ; CHECK-LABEL: @test19a(
282 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[A:%.*]], -5
283 ; CHECK-NEXT: ret i1 [[C]]
286 %C = icmp eq i32 %B, -1
290 define <2 x i1> @test19a_vec(<2 x i32> %A) {
291 ; CHECK-LABEL: @test19a_vec(
292 ; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[A:%.*]], splat (i32 -5)
293 ; CHECK-NEXT: ret <2 x i1> [[C]]
295 %B = ashr <2 x i32> %A, <i32 2, i32 2>
296 %C = icmp eq <2 x i32> %B, <i32 -1, i32 -1>
300 define i1 @test20(i8 %A) {
301 ; CHECK-LABEL: @test20(
302 ; CHECK-NEXT: ret i1 false
306 %C = icmp eq i8 %B, 123
310 define i1 @test21(i8 %A) {
311 ; CHECK-LABEL: @test21(
312 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
313 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 8
314 ; CHECK-NEXT: ret i1 [[C]]
317 %C = icmp eq i8 %B, -128
321 define i1 @test22(i8 %A) {
322 ; CHECK-LABEL: @test22(
323 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
324 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 0
325 ; CHECK-NEXT: ret i1 [[C]]
328 %C = icmp eq i8 %B, 0
332 define i8 @test23(i32 %A) {
333 ; CHECK-LABEL: @test23(
334 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[A:%.*]] to i8
335 ; CHECK-NEXT: ret i8 [[D]]
340 %D = trunc i32 %C to i8
344 define i8 @test24(i8 %X) {
345 ; CHECK-LABEL: @test24(
346 ; CHECK-NEXT: [[Z:%.*]] = and i8 [[X:%.*]], 3
347 ; CHECK-NEXT: ret i8 [[Z]]
355 ;; handle casts between shifts.
356 define i32 @test26(i32 %A) {
357 ; CHECK-LABEL: @test26(
358 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -2
359 ; CHECK-NEXT: ret i32 [[B]]
362 %C = bitcast i32 %B to i32
367 define i1 @test27(i32 %x) {
368 ; CHECK-LABEL: @test27(
369 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 8
370 ; CHECK-NEXT: [[Z:%.*]] = icmp ne i32 [[TMP1]], 0
371 ; CHECK-NEXT: ret i1 [[Z]]
374 %z = trunc i32 %y to i1
378 define i1 @test28(i8 %x) {
379 ; CHECK-LABEL: @test28(
380 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
381 ; CHECK-NEXT: ret i1 [[CMP]]
384 %cmp = icmp ne i8 %shr, 0
388 define <2 x i1> @test28vec(<2 x i8> %x) {
389 ; CHECK-LABEL: @test28vec(
390 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
391 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
393 %shr = lshr <2 x i8> %x, <i8 7, i8 7>
394 %cmp = icmp ne <2 x i8> %shr, zeroinitializer
398 define i8 @test28a(i8 %x, i8 %y) {
399 ; CHECK-LABEL: @test28a(
401 ; CHECK-NEXT: [[COND1_NOT:%.*]] = icmp sgt i8 [[X:%.*]], -1
402 ; CHECK-NEXT: br i1 [[COND1_NOT]], label [[BB2:%.*]], label [[BB1:%.*]]
404 ; CHECK-NEXT: ret i8 1
406 ; CHECK-NEXT: ret i8 [[Y:%.*]]
409 ; This shouldn't be transformed.
411 %cond1 = icmp ne i8 %i1, 0
412 br i1 %cond1, label %bb1, label %bb2
420 define i32 @test29(i64 %d18) {
421 ; CHECK-LABEL: @test29(
423 ; CHECK-NEXT: [[SUM_SHIFT:%.*]] = lshr i64 [[D18:%.*]], 63
424 ; CHECK-NEXT: [[I101:%.*]] = trunc nuw nsw i64 [[SUM_SHIFT]] to i32
425 ; CHECK-NEXT: ret i32 [[I101]]
428 %i916 = lshr i64 %d18, 32
429 %i917 = trunc i64 %i916 to i32
430 %i10 = lshr i32 %i917, 31
434 define <2 x i32> @test29_uniform(<2 x i64> %d18) {
435 ; CHECK-LABEL: @test29_uniform(
437 ; CHECK-NEXT: [[SUM_SHIFT:%.*]] = lshr <2 x i64> [[D18:%.*]], splat (i64 63)
438 ; CHECK-NEXT: [[I101:%.*]] = trunc nuw nsw <2 x i64> [[SUM_SHIFT]] to <2 x i32>
439 ; CHECK-NEXT: ret <2 x i32> [[I101]]
442 %i916 = lshr <2 x i64> %d18, <i64 32, i64 32>
443 %i917 = trunc <2 x i64> %i916 to <2 x i32>
444 %i10 = lshr <2 x i32> %i917, <i32 31, i32 31>
448 define <2 x i32> @test29_nonuniform(<2 x i64> %d18) {
449 ; CHECK-LABEL: @test29_nonuniform(
451 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 15>
452 ; CHECK-NEXT: [[I917:%.*]] = trunc <2 x i64> [[I916]] to <2 x i32>
453 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 22>
454 ; CHECK-NEXT: ret <2 x i32> [[I10]]
457 %i916 = lshr <2 x i64> %d18, <i64 32, i64 15>
458 %i917 = trunc <2 x i64> %i916 to <2 x i32>
459 %i10 = lshr <2 x i32> %i917, <i32 31, i32 22>
463 define <2 x i32> @test29_poison(<2 x i64> %d18) {
464 ; CHECK-LABEL: @test29_poison(
466 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 poison>
467 ; CHECK-NEXT: [[I917:%.*]] = trunc nuw <2 x i64> [[I916]] to <2 x i32>
468 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 poison>
469 ; CHECK-NEXT: ret <2 x i32> [[I10]]
472 %i916 = lshr <2 x i64> %d18, <i64 32, i64 poison>
473 %i917 = trunc <2 x i64> %i916 to <2 x i32>
474 %i10 = lshr <2 x i32> %i917, <i32 31, i32 poison>
478 define i32 @test30(i32 %A, i32 %B, i32 %C) {
479 ; CHECK-LABEL: @test30(
480 ; CHECK-NEXT: [[X1:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
481 ; CHECK-NEXT: [[Z:%.*]] = shl i32 [[X1]], [[C:%.*]]
482 ; CHECK-NEXT: ret i32 [[Z]]
490 define i32 @test31(i32 %A, i32 %B, i32 %C) {
491 ; CHECK-LABEL: @test31(
492 ; CHECK-NEXT: [[X1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
493 ; CHECK-NEXT: [[Z:%.*]] = lshr i32 [[X1]], [[C:%.*]]
494 ; CHECK-NEXT: ret i32 [[Z]]
502 define i32 @test32(i32 %A, i32 %B, i32 %C) {
503 ; CHECK-LABEL: @test32(
504 ; CHECK-NEXT: [[X1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
505 ; CHECK-NEXT: [[Z:%.*]] = ashr i32 [[X1]], [[C:%.*]]
506 ; CHECK-NEXT: ret i32 [[Z]]
514 define i1 @test33(i32 %X) {
515 ; CHECK-LABEL: @test33(
516 ; CHECK-NEXT: [[I1_MASK:%.*]] = and i32 [[X:%.*]], 16777216
517 ; CHECK-NEXT: [[I2:%.*]] = icmp ne i32 [[I1_MASK]], 0
518 ; CHECK-NEXT: ret i1 [[I2]]
521 %i2 = icmp slt i32 %i1, 0
525 define <2 x i1> @test33vec(<2 x i32> %X) {
526 ; CHECK-LABEL: @test33vec(
527 ; CHECK-NEXT: [[I1_MASK:%.*]] = and <2 x i32> [[X:%.*]], splat (i32 16777216)
528 ; CHECK-NEXT: [[I2:%.*]] = icmp ne <2 x i32> [[I1_MASK]], zeroinitializer
529 ; CHECK-NEXT: ret <2 x i1> [[I2]]
531 %i1 = shl <2 x i32> %X, <i32 7, i32 7>
532 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
536 define i1 @test34(i32 %X) {
537 ; CHECK-LABEL: @test34(
538 ; CHECK-NEXT: ret i1 false
541 %i2 = icmp slt i32 %i1, 0
545 define i1 @test35(i32 %X) {
546 ; CHECK-LABEL: @test35(
547 ; CHECK-NEXT: [[I2:%.*]] = icmp slt i32 [[X:%.*]], 0
548 ; CHECK-NEXT: ret i1 [[I2]]
551 %i2 = icmp slt i32 %i1, 0
555 define <2 x i1> @test35vec(<2 x i32> %X) {
556 ; CHECK-LABEL: @test35vec(
557 ; CHECK-NEXT: [[I2:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
558 ; CHECK-NEXT: ret <2 x i1> [[I2]]
560 %i1 = ashr <2 x i32> %X, <i32 7, i32 7>
561 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
565 define i128 @test36(i128 %A, i128 %B) {
566 ; CHECK-LABEL: @test36(
567 ; CHECK-NEXT: [[I231:%.*]] = or i128 [[B:%.*]], [[A:%.*]]
568 ; CHECK-NEXT: [[INS:%.*]] = and i128 [[I231]], 18446744073709551615
569 ; CHECK-NEXT: ret i128 [[INS]]
571 %i27 = shl i128 %A, 64
572 %i23 = shl i128 %B, 64
573 %ins = or i128 %i23, %i27
574 %i45 = lshr i128 %ins, 64
578 define i64 @test37(i128 %A, i32 %B) {
579 ; CHECK-LABEL: @test37(
580 ; CHECK-NEXT: [[I22:%.*]] = zext i32 [[B:%.*]] to i128
581 ; CHECK-NEXT: [[I23:%.*]] = shl nuw nsw i128 [[I22]], 32
582 ; CHECK-NEXT: [[INS:%.*]] = or i128 [[I23]], [[A:%.*]]
583 ; CHECK-NEXT: [[I46:%.*]] = trunc i128 [[INS]] to i64
584 ; CHECK-NEXT: ret i64 [[I46]]
586 %i27 = shl i128 %A, 64
587 %i22 = zext i32 %B to i128
588 %i23 = shl i128 %i22, 96
589 %ins = or i128 %i23, %i27
590 %i45 = lshr i128 %ins, 64
591 %i46 = trunc i128 %i45 to i64
595 define <2 x i32> @shl_nuw_nsw_splat_vec(<2 x i8> %x) {
596 ; CHECK-LABEL: @shl_nuw_nsw_splat_vec(
597 ; CHECK-NEXT: [[T2:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i32>
598 ; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw <2 x i32> [[T2]], splat (i32 17)
599 ; CHECK-NEXT: ret <2 x i32> [[T3]]
601 %t2 = zext <2 x i8> %x to <2 x i32>
602 %t3 = shl <2 x i32> %t2, <i32 17, i32 17>
606 define i32 @test38(i32 %x) {
607 ; CHECK-LABEL: @test38(
608 ; CHECK-NEXT: [[REM1:%.*]] = and i32 [[X:%.*]], 31
609 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[REM1]]
610 ; CHECK-NEXT: ret i32 [[SHL]]
612 %rem = srem i32 %x, 32
613 %shl = shl i32 1, %rem
617 define <2 x i32> @test38_uniform(<2 x i32> %x) {
618 ; CHECK-LABEL: @test38_uniform(
619 ; CHECK-NEXT: [[REM1:%.*]] = and <2 x i32> [[X:%.*]], splat (i32 31)
620 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <2 x i32> splat (i32 1), [[REM1]]
621 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
623 %rem = srem <2 x i32> %x, <i32 32, i32 32>
624 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
628 define <3 x i32> @test38_nonuniform(<3 x i32> %x) {
629 ; CHECK-LABEL: @test38_nonuniform(
630 ; CHECK-NEXT: [[REM1:%.*]] = and <3 x i32> [[X:%.*]], <i32 31, i32 15, i32 0>
631 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <3 x i32> splat (i32 1), [[REM1]]
632 ; CHECK-NEXT: ret <3 x i32> [[SHL]]
634 %rem = srem <3 x i32> %x, <i32 32, i32 16, i32 1>
635 %shl = shl <3 x i32> <i32 1, i32 1, i32 1>, %rem
639 define <2 x i32> @test38_poison(<2 x i32> %x) {
640 ; CHECK-LABEL: @test38_poison(
641 ; CHECK-NEXT: ret <2 x i32> poison
643 %rem = srem <2 x i32> %x, <i32 32, i32 poison>
644 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
648 ; <rdar://problem/8756731>
649 define i8 @test39(i32 %a0) {
650 ; CHECK-LABEL: @test39(
652 ; CHECK-NEXT: [[I4:%.*]] = trunc i32 [[A0:%.*]] to i8
653 ; CHECK-NEXT: [[I5:%.*]] = shl i8 [[I4]], 5
654 ; CHECK-NEXT: [[I49:%.*]] = shl i8 [[I4]], 6
655 ; CHECK-NEXT: [[I50:%.*]] = and i8 [[I49]], 64
656 ; CHECK-NEXT: [[I51:%.*]] = xor i8 [[I50]], [[I5]]
657 ; CHECK-NEXT: [[TMP0:%.*]] = lshr exact i8 [[I5]], 3
658 ; CHECK-NEXT: [[I54:%.*]] = and i8 [[TMP0]], 16
659 ; CHECK-NEXT: [[I55:%.*]] = or disjoint i8 [[I54]], [[I51]]
660 ; CHECK-NEXT: ret i8 [[I55]]
663 %i4 = trunc i32 %a0 to i8
665 %i48 = and i8 %i5, 32
666 %i49 = lshr i8 %i48, 5
667 %i50 = mul i8 %i49, 64
668 %i51 = xor i8 %i50, %i5
669 %i52 = and i8 %i51, -128
670 %i53 = lshr i8 %i52, 7
671 %i54 = mul i8 %i53, 16
672 %i55 = xor i8 %i54, %i51
676 define i32 @test42(i32 %a, i32 %b) {
677 ; CHECK-LABEL: @test42(
678 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 12, [[B:%.*]]
679 ; CHECK-NEXT: [[DIV2:%.*]] = lshr i32 [[A:%.*]], [[TMP1]]
680 ; CHECK-NEXT: ret i32 [[DIV2]]
682 %div = lshr i32 4096, %b ; must be exact otherwise we'd divide by zero
683 %div2 = udiv i32 %a, %div
687 define <2 x i32> @test42vec(<2 x i32> %a, <2 x i32> %b) {
688 ; CHECK-LABEL: @test42vec(
689 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> splat (i32 12), [[B:%.*]]
690 ; CHECK-NEXT: [[DIV2:%.*]] = lshr <2 x i32> [[A:%.*]], [[TMP1]]
691 ; CHECK-NEXT: ret <2 x i32> [[DIV2]]
693 %div = lshr <2 x i32> <i32 4096, i32 4096>, %b ; must be exact otherwise we'd divide by zero
694 %div2 = udiv <2 x i32> %a, %div
698 define i32 @test43(i32 %a, i32 %b) {
699 ; CHECK-LABEL: @test43(
700 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], 12
701 ; CHECK-NEXT: [[DIV21:%.*]] = lshr i32 [[A:%.*]], [[TMP1]]
702 ; CHECK-NEXT: ret i32 [[DIV21]]
704 %div = shl i32 4096, %b ; must be exact otherwise we'd divide by zero
705 %div2 = udiv i32 %a, %div
709 define i32 @test44(i32 %a) {
710 ; CHECK-LABEL: @test44(
711 ; CHECK-NEXT: [[Y:%.*]] = shl i32 [[A:%.*]], 5
712 ; CHECK-NEXT: ret i32 [[Y]]
714 %y = shl nuw i32 %a, 1
719 define i32 @test44_multiuse(i32 %a) {
720 ; CHECK-LABEL: @test44_multiuse(
721 ; CHECK-NEXT: [[Y:%.*]] = shl nuw i32 [[A:%.*]], 1
722 ; CHECK-NEXT: call void @use_i32(i32 [[Y]])
723 ; CHECK-NEXT: [[Z:%.*]] = shl i32 [[A]], 5
724 ; CHECK-NEXT: ret i32 [[Z]]
726 %y = shl nuw i32 %a, 1
727 call void @use_i32(i32 %y)
732 define i32 @test45(i32 %a) {
733 ; CHECK-LABEL: @test45(
734 ; CHECK-NEXT: [[Y:%.*]] = lshr i32 [[A:%.*]], 5
735 ; CHECK-NEXT: ret i32 [[Y]]
737 %y = lshr exact i32 %a, 1
742 define i32 @test45_multiuse(i32 %a) {
743 ; CHECK-LABEL: @test45_multiuse(
744 ; CHECK-NEXT: [[Y:%.*]] = lshr exact i32 [[A:%.*]], 1
745 ; CHECK-NEXT: call void @use_i32(i32 [[Y]])
746 ; CHECK-NEXT: [[Z:%.*]] = lshr i32 [[A]], 5
747 ; CHECK-NEXT: ret i32 [[Z]]
749 %y = lshr exact i32 %a, 1
750 call void @use_i32(i32 %y)
755 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
757 define i32 @test46(i32 %a) {
758 ; CHECK-LABEL: @test46(
759 ; CHECK-NEXT: [[Z:%.*]] = ashr exact i32 [[A:%.*]], 2
760 ; CHECK-NEXT: ret i32 [[Z]]
762 %y = ashr exact i32 %a, 3
767 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
769 define <2 x i32> @test46_splat_vec(<2 x i32> %a) {
770 ; CHECK-LABEL: @test46_splat_vec(
771 ; CHECK-NEXT: [[Z:%.*]] = ashr exact <2 x i32> [[A:%.*]], splat (i32 2)
772 ; CHECK-NEXT: ret <2 x i32> [[Z]]
774 %y = ashr exact <2 x i32> %a, <i32 3, i32 3>
775 %z = shl <2 x i32> %y, <i32 1, i32 1>
779 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
781 define i8 @test47(i8 %a) {
782 ; CHECK-LABEL: @test47(
783 ; CHECK-NEXT: [[Z:%.*]] = lshr exact i8 [[A:%.*]], 2
784 ; CHECK-NEXT: ret i8 [[Z]]
786 %y = lshr exact i8 %a, 3
791 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
793 define <2 x i8> @test47_splat_vec(<2 x i8> %a) {
794 ; CHECK-LABEL: @test47_splat_vec(
795 ; CHECK-NEXT: [[Z:%.*]] = lshr exact <2 x i8> [[A:%.*]], splat (i8 2)
796 ; CHECK-NEXT: ret <2 x i8> [[Z]]
798 %y = lshr exact <2 x i8> %a, <i8 3, i8 3>
799 %z = shl <2 x i8> %y, <i8 1, i8 1>
803 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when C2 > C1
805 define i32 @test48(i32 %x) {
806 ; CHECK-LABEL: @test48(
807 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
808 ; CHECK-NEXT: ret i32 [[B]]
810 %A = lshr exact i32 %x, 1
815 ; Verify that wrap flags are preserved from the original 'shl'.
817 define i32 @test48_nuw_nsw(i32 %x) {
818 ; CHECK-LABEL: @test48_nuw_nsw(
819 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
820 ; CHECK-NEXT: ret i32 [[B]]
822 %A = lshr exact i32 %x, 1
823 %B = shl nuw nsw i32 %A, 3
827 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
829 define <2 x i32> @test48_splat_vec(<2 x i32> %x) {
830 ; CHECK-LABEL: @test48_splat_vec(
831 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], splat (i32 2)
832 ; CHECK-NEXT: ret <2 x i32> [[B]]
834 %A = lshr exact <2 x i32> %x, <i32 1, i32 1>
835 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
839 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when C2 > C1
841 define i32 @test49(i32 %x) {
842 ; CHECK-LABEL: @test49(
843 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
844 ; CHECK-NEXT: ret i32 [[B]]
846 %A = ashr exact i32 %x, 1
851 ; Verify that wrap flags are preserved from the original 'shl'.
853 define i32 @test49_nuw_nsw(i32 %x) {
854 ; CHECK-LABEL: @test49_nuw_nsw(
855 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
856 ; CHECK-NEXT: ret i32 [[B]]
858 %A = ashr exact i32 %x, 1
859 %B = shl nuw nsw i32 %A, 3
863 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
865 define <2 x i32> @test49_splat_vec(<2 x i32> %x) {
866 ; CHECK-LABEL: @test49_splat_vec(
867 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], splat (i32 2)
868 ; CHECK-NEXT: ret <2 x i32> [[B]]
870 %A = ashr exact <2 x i32> %x, <i32 1, i32 1>
871 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
875 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
877 define i32 @test50(i32 %x) {
878 ; CHECK-LABEL: @test50(
879 ; CHECK-NEXT: [[B:%.*]] = ashr i32 [[X:%.*]], 2
880 ; CHECK-NEXT: ret i32 [[B]]
882 %A = shl nsw i32 %x, 1
887 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
888 ; Also, check that exact is propagated.
890 define <2 x i32> @test50_splat_vec(<2 x i32> %x) {
891 ; CHECK-LABEL: @test50_splat_vec(
892 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i32> [[X:%.*]], splat (i32 2)
893 ; CHECK-NEXT: ret <2 x i32> [[B]]
895 %A = shl nsw <2 x i32> %x, <i32 1, i32 1>
896 %B = ashr exact <2 x i32> %A, <i32 3, i32 3>
900 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1)
902 define i32 @test51(i32 %x) {
903 ; CHECK-LABEL: @test51(
904 ; CHECK-NEXT: [[B:%.*]] = lshr i32 [[X:%.*]], 2
905 ; CHECK-NEXT: ret i32 [[B]]
907 %A = shl nuw i32 %x, 1
912 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1) with splats
913 ; Also, check that exact is propagated.
915 define <2 x i32> @test51_splat_vec(<2 x i32> %x) {
916 ; CHECK-LABEL: @test51_splat_vec(
917 ; CHECK-NEXT: [[B:%.*]] = lshr exact <2 x i32> [[X:%.*]], splat (i32 2)
918 ; CHECK-NEXT: ret <2 x i32> [[B]]
920 %A = shl nuw <2 x i32> %x, <i32 1, i32 1>
921 %B = lshr exact <2 x i32> %A, <i32 3, i32 3>
925 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
926 ; Also, check that exact is propagated.
928 define i32 @test51_no_nuw(i32 %x) {
929 ; CHECK-LABEL: @test51_no_nuw(
930 ; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i32 [[X:%.*]], 2
931 ; CHECK-NEXT: [[B:%.*]] = and i32 [[TMP1]], 536870911
932 ; CHECK-NEXT: ret i32 [[B]]
935 %B = lshr exact i32 %A, 3
939 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
941 define <2 x i32> @test51_no_nuw_splat_vec(<2 x i32> %x) {
942 ; CHECK-LABEL: @test51_no_nuw_splat_vec(
943 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], splat (i32 2)
944 ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[TMP1]], splat (i32 536870911)
945 ; CHECK-NEXT: ret <2 x i32> [[B]]
947 %A = shl <2 x i32> %x, <i32 1, i32 1>
948 %B = lshr <2 x i32> %A, <i32 3, i32 3>
952 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
954 define i32 @test52(i32 %x) {
955 ; CHECK-LABEL: @test52(
956 ; CHECK-NEXT: [[B:%.*]] = shl nsw i32 [[X:%.*]], 2
957 ; CHECK-NEXT: ret i32 [[B]]
959 %A = shl nsw i32 %x, 3
964 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
966 define <2 x i32> @test52_splat_vec(<2 x i32> %x) {
967 ; CHECK-LABEL: @test52_splat_vec(
968 ; CHECK-NEXT: [[B:%.*]] = shl nsw <2 x i32> [[X:%.*]], splat (i32 2)
969 ; CHECK-NEXT: ret <2 x i32> [[B]]
971 %A = shl nsw <2 x i32> %x, <i32 3, i32 3>
972 %B = ashr <2 x i32> %A, <i32 1, i32 1>
976 ; (X <<nuw C1) >>u C2 --> X <<nuw/nsw (C1 - C2)
978 define i32 @test53(i32 %x) {
979 ; CHECK-LABEL: @test53(
980 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
981 ; CHECK-NEXT: ret i32 [[B]]
983 %A = shl nuw i32 %x, 3
988 ; (X <<nuw C1) >>u C2 --> X <<nuw/nsw (C1 - C2)
990 define <2 x i32> @test53_splat_vec(<2 x i32> %x) {
991 ; CHECK-LABEL: @test53_splat_vec(
992 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], splat (i32 2)
993 ; CHECK-NEXT: ret <2 x i32> [[B]]
995 %A = shl nuw <2 x i32> %x, <i32 3, i32 3>
996 %B = lshr <2 x i32> %A, <i32 1, i32 1>
1000 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
1002 define i8 @test53_no_nuw(i8 %x) {
1003 ; CHECK-LABEL: @test53_no_nuw(
1004 ; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[X:%.*]], 2
1005 ; CHECK-NEXT: [[B:%.*]] = and i8 [[TMP1]], 124
1006 ; CHECK-NEXT: ret i8 [[B]]
1013 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
1015 define <2 x i8> @test53_no_nuw_splat_vec(<2 x i8> %x) {
1016 ; CHECK-LABEL: @test53_no_nuw_splat_vec(
1017 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> [[X:%.*]], splat (i8 2)
1018 ; CHECK-NEXT: [[B:%.*]] = and <2 x i8> [[TMP1]], splat (i8 124)
1019 ; CHECK-NEXT: ret <2 x i8> [[B]]
1021 %A = shl <2 x i8> %x, <i8 3, i8 3>
1022 %B = lshr <2 x i8> %A, <i8 1, i8 1>
1026 define i32 @test54(i32 %x) {
1027 ; CHECK-LABEL: @test54(
1028 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1029 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[TMP1]], 16
1030 ; CHECK-NEXT: ret i32 [[AND]]
1032 %shr2 = lshr i32 %x, 1
1033 %shl = shl i32 %shr2, 4
1034 %and = and i32 %shl, 16
1038 define <2 x i32> @test54_splat_vec(<2 x i32> %x) {
1039 ; CHECK-LABEL: @test54_splat_vec(
1040 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[X:%.*]], splat (i32 3)
1041 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[TMP1]], splat (i32 16)
1042 ; CHECK-NEXT: ret <2 x i32> [[AND]]
1044 %shr2 = lshr <2 x i32> %x, <i32 1, i32 1>
1045 %shl = shl <2 x i32> %shr2, <i32 4, i32 4>
1046 %and = and <2 x i32> %shl, <i32 16, i32 16>
1050 define i32 @test55(i32 %x) {
1051 ; CHECK-LABEL: @test55(
1052 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1053 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 8
1054 ; CHECK-NEXT: ret i32 [[OR]]
1056 %shr2 = lshr i32 %x, 1
1057 %shl = shl i32 %shr2, 4
1058 %or = or i32 %shl, 8
1062 define i32 @test56(i32 %x) {
1063 ; CHECK-LABEL: @test56(
1064 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1065 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1066 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 7
1067 ; CHECK-NEXT: ret i32 [[OR]]
1069 %shr2 = lshr i32 %x, 1
1070 %shl = shl i32 %shr2, 4
1071 %or = or i32 %shl, 7
1075 define i32 @test57(i32 %x) {
1076 ; CHECK-LABEL: @test57(
1077 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1078 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1079 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 7
1080 ; CHECK-NEXT: ret i32 [[OR]]
1082 %shr = ashr i32 %x, 1
1083 %shl = shl i32 %shr, 4
1084 %or = or i32 %shl, 7
1088 define i32 @test58(i32 %x) {
1089 ; CHECK-LABEL: @test58(
1090 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1091 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 1
1092 ; CHECK-NEXT: ret i32 [[OR]]
1094 %shr = ashr i32 %x, 4
1095 %shl = shl i32 %shr, 1
1096 %or = or i32 %shl, 1
1100 define <2 x i32> @test58_splat_vec(<2 x i32> %x) {
1101 ; CHECK-LABEL: @test58_splat_vec(
1102 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> [[X:%.*]], splat (i32 3)
1103 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[TMP1]], splat (i32 1)
1104 ; CHECK-NEXT: ret <2 x i32> [[OR]]
1106 %shr = ashr <2 x i32> %x, <i32 4, i32 4>
1107 %shl = shl <2 x i32> %shr, <i32 1, i32 1>
1108 %or = or <2 x i32> %shl, <i32 1, i32 1>
1112 define i32 @test59(i32 %x) {
1113 ; CHECK-LABEL: @test59(
1114 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1115 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -4
1116 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 2
1117 ; CHECK-NEXT: ret i32 [[OR]]
1119 %shr = ashr i32 %x, 4
1120 %shl = shl i32 %shr, 1
1121 %or = or i32 %shl, 2
1125 ; propagate "exact" trait
1126 define i32 @test60(i32 %x) {
1127 ; CHECK-LABEL: @test60(
1128 ; CHECK-NEXT: [[SHL:%.*]] = ashr exact i32 [[X:%.*]], 3
1129 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], 1
1130 ; CHECK-NEXT: ret i32 [[OR]]
1132 %shr = ashr exact i32 %x, 4
1133 %shl = shl i32 %shr, 1
1134 %or = or i32 %shl, 1
1139 define void @test61(i128 %arg, i1 %c1, i1 %c2, i1 %c3, i1 %c4) {
1140 ; CHECK-LABEL: @test61(
1142 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[BB1:%.*]], label [[BB12:%.*]]
1144 ; CHECK-NEXT: br label [[BB2:%.*]]
1146 ; CHECK-NEXT: br i1 [[C2:%.*]], label [[BB3:%.*]], label [[BB7:%.*]]
1148 ; CHECK-NEXT: br label [[BB8:%.*]]
1150 ; CHECK-NEXT: br i1 [[C3:%.*]], label [[BB8]], label [[BB2]]
1152 ; CHECK-NEXT: br i1 poison, label [[BB11:%.*]], label [[BB12]]
1154 ; CHECK-NEXT: br i1 [[C4:%.*]], label [[BB1]], label [[BB12]]
1156 ; CHECK-NEXT: ret void
1159 br i1 %c1, label %bb1, label %bb12
1161 bb1: ; preds = %bb11, %bb
1164 bb2: ; preds = %bb7, %bb1
1165 br i1 %c2, label %bb3, label %bb7
1168 %i = lshr i128 %arg, 36893488147419103232
1169 %i4 = shl i128 %i, 0
1170 %i5 = or i128 %i4, 0
1171 %i6 = trunc i128 %i5 to i16
1175 br i1 %c3, label %bb8, label %bb2
1177 bb8: ; preds = %bb7, %bb3
1178 %i9 = phi i16 [ %i6, %bb3 ], [ poison, %bb7 ]
1179 %i10 = icmp eq i16 %i9, 0
1180 br i1 %i10, label %bb11, label %bb12
1182 bb11: ; preds = %bb8
1183 br i1 %c4, label %bb1, label %bb12
1185 bb12: ; preds = %bb11, %bb8, %bb
1189 define i32 @test62(i32 %a) {
1190 ; CHECK-LABEL: @test62(
1191 ; CHECK-NEXT: ret i32 poison
1193 %b = ashr i32 %a, 32 ; shift all bits out
1197 define <4 x i32> @test62_splat_vector(<4 x i32> %a) {
1198 ; CHECK-LABEL: @test62_splat_vector(
1199 ; CHECK-NEXT: ret <4 x i32> poison
1201 %b = ashr <4 x i32> %a, <i32 32, i32 32, i32 32, i32 32> ; shift all bits out
1205 define <4 x i32> @test62_non_splat_vector(<4 x i32> %a) {
1206 ; CHECK-LABEL: @test62_non_splat_vector(
1207 ; CHECK-NEXT: [[B:%.*]] = ashr <4 x i32> [[A:%.*]], <i32 32, i32 0, i32 1, i32 2>
1208 ; CHECK-NEXT: ret <4 x i32> [[B]]
1210 %b = ashr <4 x i32> %a, <i32 32, i32 0, i32 1, i32 2> ; shift all bits out
1214 define <2 x i65> @test_63(<2 x i64> %t) {
1215 ; CHECK-LABEL: @test_63(
1216 ; CHECK-NEXT: [[A:%.*]] = zext <2 x i64> [[T:%.*]] to <2 x i65>
1217 ; CHECK-NEXT: [[SEXT:%.*]] = shl <2 x i65> [[A]], splat (i65 33)
1218 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i65> [[SEXT]], splat (i65 33)
1219 ; CHECK-NEXT: ret <2 x i65> [[B]]
1221 %a = zext <2 x i64> %t to <2 x i65>
1222 %sext = shl <2 x i65> %a, <i65 33, i65 33>
1223 %b = ashr <2 x i65> %sext, <i65 33, i65 33>
1227 define i32 @test_shl_zext_bool(i1 %t) {
1228 ; CHECK-LABEL: @test_shl_zext_bool(
1229 ; CHECK-NEXT: [[SHL:%.*]] = select i1 [[T:%.*]], i32 4, i32 0
1230 ; CHECK-NEXT: ret i32 [[SHL]]
1232 %ext = zext i1 %t to i32
1233 %shl = shl i32 %ext, 2
1237 define <2 x i32> @test_shl_zext_bool_splat(<2 x i1> %t) {
1238 ; CHECK-LABEL: @test_shl_zext_bool_splat(
1239 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> splat (i32 8), <2 x i32> zeroinitializer
1240 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1242 %ext = zext <2 x i1> %t to <2 x i32>
1243 %shl = shl <2 x i32> %ext, <i32 3, i32 3>
1247 define <2 x i32> @test_shl_zext_bool_vec(<2 x i1> %t) {
1248 ; CHECK-LABEL: @test_shl_zext_bool_vec(
1249 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 4, i32 8>, <2 x i32> zeroinitializer
1250 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1252 %ext = zext <2 x i1> %t to <2 x i32>
1253 %shl = shl <2 x i32> %ext, <i32 2, i32 3>
1257 define i32 @test_shl_zext_bool_not_constant(i1 %cmp, i32 %shamt) {
1258 ; CHECK-LABEL: @test_shl_zext_bool_not_constant(
1259 ; CHECK-NEXT: [[CONV3:%.*]] = zext i1 [[CMP:%.*]] to i32
1260 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[CONV3]], [[SHAMT:%.*]]
1261 ; CHECK-NEXT: ret i32 [[SHL]]
1263 %conv3 = zext i1 %cmp to i32
1264 %shl = shl i32 %conv3, %shamt
1268 define i64 @shl_zext(i32 %t) {
1269 ; CHECK-LABEL: @shl_zext(
1270 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[T:%.*]], 8
1271 ; CHECK-NEXT: [[SHL:%.*]] = zext i32 [[TMP1]] to i64
1272 ; CHECK-NEXT: ret i64 [[SHL]]
1274 %and = and i32 %t, 16777215
1275 %ext = zext i32 %and to i64
1276 %shl = shl i64 %ext, 8
1280 define i64 @shl_zext_extra_use(i32 %t) {
1281 ; CHECK-LABEL: @shl_zext_extra_use(
1282 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[T:%.*]], 16777215
1283 ; CHECK-NEXT: [[EXT:%.*]] = zext nneg i32 [[AND]] to i64
1284 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1285 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 8
1286 ; CHECK-NEXT: ret i64 [[SHL]]
1288 %and = and i32 %t, 16777215
1289 %ext = zext i32 %and to i64
1290 call void @use(i64 %ext)
1291 %shl = shl i64 %ext, 8
1295 define <2 x i64> @shl_zext_splat_vec(<2 x i32> %t) {
1296 ; CHECK-LABEL: @shl_zext_splat_vec(
1297 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[T:%.*]], splat (i32 8)
1298 ; CHECK-NEXT: [[SHL:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
1299 ; CHECK-NEXT: ret <2 x i64> [[SHL]]
1301 %and = and <2 x i32> %t, <i32 16777215, i32 16777215>
1302 %ext = zext <2 x i32> %and to <2 x i64>
1303 %shl = shl <2 x i64> %ext, <i64 8, i64 8>
1307 define i64 @shl_zext_mul(i32 %t) {
1308 ; CHECK-LABEL: @shl_zext_mul(
1309 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1310 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1311 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1312 ; CHECK-NEXT: ret i64 [[SHL]]
1314 %mul = mul i32 %t, 16777215
1315 %ext = zext i32 %mul to i64
1316 %shl = shl i64 %ext, 32
1320 define <3 x i17> @shl_zext_mul_splat(<3 x i5> %t) {
1321 ; CHECK-LABEL: @shl_zext_mul_splat(
1322 ; CHECK-NEXT: [[MUL:%.*]] = mul <3 x i5> [[T:%.*]], splat (i5 13)
1323 ; CHECK-NEXT: [[EXT:%.*]] = zext <3 x i5> [[MUL]] to <3 x i17>
1324 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <3 x i17> [[EXT]], splat (i17 12)
1325 ; CHECK-NEXT: ret <3 x i17> [[SHL]]
1327 %mul = mul <3 x i5> %t, <i5 13, i5 13, i5 13>
1328 %ext = zext <3 x i5> %mul to <3 x i17>
1329 %shl = shl <3 x i17> %ext, <i17 12, i17 12, i17 12>
1333 define i64 @shl_zext_mul_low_shift_amount(i32 %t) {
1334 ; CHECK-LABEL: @shl_zext_mul_low_shift_amount(
1335 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1336 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1337 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 31
1338 ; CHECK-NEXT: ret i64 [[SHL]]
1340 %mul = mul i32 %t, 16777215
1341 %ext = zext i32 %mul to i64
1342 %shl = shl i64 %ext, 31
1346 define i64 @shl_zext_mul_extra_use1(i32 %t) {
1347 ; CHECK-LABEL: @shl_zext_mul_extra_use1(
1348 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1349 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1350 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1351 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1352 ; CHECK-NEXT: ret i64 [[SHL]]
1354 %mul = mul i32 %t, 16777215
1355 %ext = zext i32 %mul to i64
1356 call void @use(i64 %ext)
1357 %shl = shl i64 %ext, 32
1361 define i64 @shl_zext_mul_extra_use2(i32 %t) {
1362 ; CHECK-LABEL: @shl_zext_mul_extra_use2(
1363 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1364 ; CHECK-NEXT: call void @use_i32(i32 [[MUL]])
1365 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1366 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1367 ; CHECK-NEXT: ret i64 [[SHL]]
1369 %mul = mul i32 %t, 16777215
1370 call void @use_i32(i32 %mul)
1371 %ext = zext i32 %mul to i64
1372 %shl = shl i64 %ext, 32
1376 define <2 x i8> @ashr_demanded_bits_splat(<2 x i8> %x) {
1377 ; CHECK-LABEL: @ashr_demanded_bits_splat(
1378 ; CHECK-NEXT: [[SHR:%.*]] = ashr <2 x i8> [[X:%.*]], splat (i8 7)
1379 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1381 %and = and <2 x i8> %x, <i8 128, i8 128>
1382 %shr = ashr <2 x i8> %and, <i8 7, i8 7>
1386 define <vscale x 8 x i8> @ashr_demanded_bits_splat2(<vscale x 8 x i8> %x) {
1387 ; CHECK-LABEL: @ashr_demanded_bits_splat2(
1388 ; CHECK-NEXT: [[SHR:%.*]] = ashr <vscale x 8 x i8> [[X:%.*]], splat (i8 7)
1389 ; CHECK-NEXT: ret <vscale x 8 x i8> [[SHR]]
1391 %and = and <vscale x 8 x i8> %x, splat (i8 128)
1392 %shr = ashr <vscale x 8 x i8> %and, splat (i8 7)
1393 ret <vscale x 8 x i8> %shr
1396 define <2 x i8> @lshr_demanded_bits_splat(<2 x i8> %x) {
1397 ; CHECK-LABEL: @lshr_demanded_bits_splat(
1398 ; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i8> [[X:%.*]], splat (i8 7)
1399 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1401 %and = and <2 x i8> %x, <i8 128, i8 128>
1402 %shr = lshr <2 x i8> %and, <i8 7, i8 7>
1406 define <vscale x 8 x i8> @lshr_demanded_bits_splat2(<vscale x 8 x i8> %x) {
1407 ; CHECK-LABEL: @lshr_demanded_bits_splat2(
1408 ; CHECK-NEXT: [[SHR:%.*]] = lshr <vscale x 8 x i8> [[X:%.*]], splat (i8 7)
1409 ; CHECK-NEXT: ret <vscale x 8 x i8> [[SHR]]
1411 %and = and <vscale x 8 x i8> %x, splat (i8 128)
1412 %shr = lshr <vscale x 8 x i8> %and, splat (i8 7)
1413 ret <vscale x 8 x i8> %shr
1416 ; Make sure known bits works correctly with non power of 2 bit widths.
1417 define i7 @test65(i7 %a, i7 %b) {
1418 ; CHECK-LABEL: @test65(
1419 ; CHECK-NEXT: ret i7 0
1421 %shiftamt = and i7 %b, 6 ; this ensures the shift amount is even and less than the bit width.
1422 %x = lshr i7 42, %shiftamt ; 42 has a zero in every even numbered bit and a one in every odd bit.
1423 %y = and i7 %x, 1 ; this extracts the lsb which should be 0 because we shifted an even number of bits and all even bits of the shift input are 0.
1427 define i32 @shl_select_add_true(i32 %x, i1 %cond) {
1428 ; CHECK-LABEL: @shl_select_add_true(
1429 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1430 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1431 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1432 ; CHECK-NEXT: ret i32 [[TMP3]]
1435 %2 = select i1 %cond, i32 %1, i32 %x
1440 define i32 @shl_select_add_false(i32 %x, i1 %cond) {
1441 ; CHECK-LABEL: @shl_select_add_false(
1442 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1443 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1444 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1445 ; CHECK-NEXT: ret i32 [[TMP3]]
1448 %2 = select i1 %cond, i32 %x, i32 %1
1453 define i32 @shl_select_and_true(i32 %x, i1 %cond) {
1454 ; CHECK-LABEL: @shl_select_and_true(
1455 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1456 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1457 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1458 ; CHECK-NEXT: ret i32 [[TMP3]]
1461 %2 = select i1 %cond, i32 %1, i32 %x
1466 define i32 @shl_select_and_false(i32 %x, i1 %cond) {
1467 ; CHECK-LABEL: @shl_select_and_false(
1468 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1469 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1470 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1471 ; CHECK-NEXT: ret i32 [[TMP3]]
1474 %2 = select i1 %cond, i32 %x, i32 %1
1479 define i32 @lshr_select_and_true(i32 %x, i1 %cond) {
1480 ; CHECK-LABEL: @lshr_select_and_true(
1481 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1482 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1483 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1484 ; CHECK-NEXT: ret i32 [[TMP3]]
1487 %2 = select i1 %cond, i32 %1, i32 %x
1492 define i32 @lshr_select_and_false(i32 %x, i1 %cond) {
1493 ; CHECK-LABEL: @lshr_select_and_false(
1494 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1495 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1496 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1497 ; CHECK-NEXT: ret i32 [[TMP3]]
1500 %2 = select i1 %cond, i32 %x, i32 %1
1505 define i32 @ashr_select_and_true(i32 %x, i1 %cond) {
1506 ; CHECK-LABEL: @ashr_select_and_true(
1507 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1508 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1509 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1510 ; CHECK-NEXT: ret i32 [[TMP3]]
1512 %1 = and i32 %x, 2147483655
1513 %2 = select i1 %cond, i32 %1, i32 %x
1518 define i32 @ashr_select_and_false(i32 %x, i1 %cond) {
1519 ; CHECK-LABEL: @ashr_select_and_false(
1520 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1521 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1522 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1523 ; CHECK-NEXT: ret i32 [[TMP3]]
1525 %1 = and i32 %x, 2147483655
1526 %2 = select i1 %cond, i32 %x, i32 %1
1531 define i32 @shl_select_or_true(i32 %x, i1 %cond) {
1532 ; CHECK-LABEL: @shl_select_or_true(
1533 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1534 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1535 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1536 ; CHECK-NEXT: ret i32 [[TMP3]]
1539 %2 = select i1 %cond, i32 %1, i32 %x
1544 define i32 @shl_select_or_false(i32 %x, i1 %cond) {
1545 ; CHECK-LABEL: @shl_select_or_false(
1546 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1547 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1548 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1549 ; CHECK-NEXT: ret i32 [[TMP3]]
1552 %2 = select i1 %cond, i32 %x, i32 %1
1557 define i32 @lshr_select_or_true(i32 %x, i1 %cond) {
1558 ; CHECK-LABEL: @lshr_select_or_true(
1559 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1560 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1561 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1562 ; CHECK-NEXT: ret i32 [[TMP3]]
1565 %2 = select i1 %cond, i32 %1, i32 %x
1570 define i32 @lshr_select_or_false(i32 %x, i1 %cond) {
1571 ; CHECK-LABEL: @lshr_select_or_false(
1572 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1573 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1574 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1575 ; CHECK-NEXT: ret i32 [[TMP3]]
1578 %2 = select i1 %cond, i32 %x, i32 %1
1583 define i32 @ashr_select_or_true(i32 %x, i1 %cond) {
1584 ; CHECK-LABEL: @ashr_select_or_true(
1585 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1586 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1587 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1588 ; CHECK-NEXT: ret i32 [[TMP3]]
1591 %2 = select i1 %cond, i32 %1, i32 %x
1596 define i32 @ashr_select_or_false(i32 %x, i1 %cond) {
1597 ; CHECK-LABEL: @ashr_select_or_false(
1598 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1599 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1600 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1601 ; CHECK-NEXT: ret i32 [[TMP3]]
1604 %2 = select i1 %cond, i32 %x, i32 %1
1609 define i32 @shl_select_xor_true(i32 %x, i1 %cond) {
1610 ; CHECK-LABEL: @shl_select_xor_true(
1611 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1612 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1613 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1614 ; CHECK-NEXT: ret i32 [[TMP3]]
1617 %2 = select i1 %cond, i32 %1, i32 %x
1622 define i32 @shl_select_xor_false(i32 %x, i1 %cond) {
1623 ; CHECK-LABEL: @shl_select_xor_false(
1624 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1625 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1626 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1627 ; CHECK-NEXT: ret i32 [[TMP3]]
1630 %2 = select i1 %cond, i32 %x, i32 %1
1635 define i32 @lshr_select_xor_true(i32 %x, i1 %cond) {
1636 ; CHECK-LABEL: @lshr_select_xor_true(
1637 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1638 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1639 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1640 ; CHECK-NEXT: ret i32 [[TMP3]]
1643 %2 = select i1 %cond, i32 %1, i32 %x
1648 define i32 @lshr_select_xor_false(i32 %x, i1 %cond) {
1649 ; CHECK-LABEL: @lshr_select_xor_false(
1650 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1651 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1652 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1653 ; CHECK-NEXT: ret i32 [[TMP3]]
1656 %2 = select i1 %cond, i32 %x, i32 %1
1661 define i32 @ashr_select_xor_true(i32 %x, i1 %cond) {
1662 ; CHECK-LABEL: @ashr_select_xor_true(
1663 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1664 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1665 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1666 ; CHECK-NEXT: ret i32 [[TMP3]]
1669 %2 = select i1 %cond, i32 %1, i32 %x
1674 define i32 @ashr_select_xor_false(i32 %x, i1 %cond) {
1675 ; CHECK-LABEL: @ashr_select_xor_false(
1676 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1677 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1678 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1679 ; CHECK-NEXT: ret i32 [[TMP3]]
1682 %2 = select i1 %cond, i32 %x, i32 %1
1688 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4871
1689 define i177 @lshr_out_of_range(i177 %Y, ptr %A2, ptr %ptr) {
1690 ; CHECK-LABEL: @lshr_out_of_range(
1691 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i177 [[Y:%.*]], -1
1692 ; CHECK-NEXT: [[B4:%.*]] = sext i1 [[TMP1]] to i177
1693 ; CHECK-NEXT: [[C8:%.*]] = icmp ugt i177 [[Y]], [[B4]]
1694 ; CHECK-NEXT: [[TMP2:%.*]] = sext i1 [[C8]] to i64
1695 ; CHECK-NEXT: [[G18:%.*]] = getelementptr ptr, ptr [[A2:%.*]], i64 [[TMP2]]
1696 ; CHECK-NEXT: store ptr [[G18]], ptr [[PTR:%.*]], align 8
1697 ; CHECK-NEXT: ret i177 0
1699 %B5 = udiv i177 %Y, -1
1700 %B4 = add i177 %B5, -1
1701 %B2 = add i177 %B4, -1
1702 %B6 = mul i177 %B5, %B2
1703 %B3 = add i177 %B2, %B2
1704 %B10 = sub i177 %B5, %B3
1705 %B12 = lshr i177 %Y, %B6
1706 %C8 = icmp ugt i177 %B12, %B4
1707 %G18 = getelementptr ptr, ptr %A2, i1 %C8
1708 store ptr %G18, ptr %ptr
1709 %B1 = udiv i177 %B10, %B6
1714 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26716
1715 define i177 @lshr_out_of_range2(i177 %Y, ptr %A2, ptr %ptr) {
1716 ; CHECK-LABEL: @lshr_out_of_range2(
1717 ; CHECK-NEXT: [[C8:%.*]] = icmp ne i177 [[Y:%.*]], 0
1718 ; CHECK-NEXT: [[TMP1:%.*]] = sext i1 [[C8]] to i64
1719 ; CHECK-NEXT: [[G18:%.*]] = getelementptr ptr, ptr [[A2:%.*]], i64 [[TMP1]]
1720 ; CHECK-NEXT: store ptr [[G18]], ptr [[PTR:%.*]], align 8
1721 ; CHECK-NEXT: ret i177 0
1723 %B5 = udiv i177 %Y, -1
1724 %B = sdiv i177 %B5, -1
1725 %B4 = add i177 %B5, %B
1726 %B2 = add i177 %B4, -1
1727 %B6 = mul i177 %B5, %B2
1728 %B12 = lshr i177 %Y, %B6
1729 %C8 = icmp ugt i177 %B12, %B4
1730 %G18 = getelementptr ptr, ptr %A2, i1 %C8
1731 store ptr %G18, ptr %ptr, align 8
1732 %B1 = udiv i177 %B5, %B6
1736 ; The fuzzer-generated @ashr_out_of_range test case does not reach a fixpoint,
1737 ; because a logical and it not relaxed to a bitwise and in one iteration.
1740 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5032
1741 define void @ashr_out_of_range(ptr %A) "instcombine-no-verify-fixpoint" {
1742 ; CHECK-LABEL: @ashr_out_of_range(
1743 ; CHECK-NEXT: [[L:%.*]] = load i177, ptr [[A:%.*]], align 4
1744 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i177 [[L]], -1
1745 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 -1, i64 -2
1746 ; CHECK-NEXT: [[G11:%.*]] = getelementptr i177, ptr [[A]], i64 [[TMP2]]
1747 ; CHECK-NEXT: [[L7:%.*]] = load i177, ptr [[G11]], align 4
1748 ; CHECK-NEXT: [[L7_FROZEN:%.*]] = freeze i177 [[L7]]
1749 ; CHECK-NEXT: [[C171:%.*]] = icmp slt i177 [[L7_FROZEN]], 0
1750 ; CHECK-NEXT: [[C17:%.*]] = select i1 [[TMP1]], i1 [[C171]], i1 false
1751 ; CHECK-NEXT: [[TMP3:%.*]] = sext i1 [[C17]] to i64
1752 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, ptr [[G11]], i64 [[TMP3]]
1753 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i177 [[L7_FROZEN]], -1
1754 ; CHECK-NEXT: [[B28:%.*]] = select i1 [[TMP4]], i177 0, i177 [[L7_FROZEN]]
1755 ; CHECK-NEXT: store i177 [[B28]], ptr [[G62]], align 4
1756 ; CHECK-NEXT: ret void
1758 %L = load i177, ptr %A
1759 %B5 = udiv i177 %L, -1
1760 %B4 = add i177 %B5, -1
1761 %B2 = add i177 %B4, -1
1762 %G11 = getelementptr i177, ptr %A, i177 %B2
1763 %L7 = load i177, ptr %G11
1764 %B6 = mul i177 %B5, %B2
1765 %B24 = ashr i177 %L7, %B6
1766 %B36 = and i177 %L7, %B4
1767 %C17 = icmp sgt i177 %B36, %B24
1768 %G62 = getelementptr i177, ptr %G11, i1 %C17
1769 %B28 = urem i177 %B24, %B6
1770 store i177 %B28, ptr %G62
1775 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26135
1776 define void @ashr_out_of_range_1(ptr %A) {
1777 ; CHECK-LABEL: @ashr_out_of_range_1(
1778 ; CHECK-NEXT: [[L:%.*]] = load i177, ptr [[A:%.*]], align 4
1779 ; CHECK-NEXT: [[L_FROZEN:%.*]] = freeze i177 [[L]]
1780 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i177 [[L_FROZEN]], -1
1781 ; CHECK-NEXT: [[TMP2:%.*]] = trunc i177 [[L_FROZEN]] to i64
1782 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP1]], i64 0, i64 [[TMP2]]
1783 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i177, ptr [[A]], i64 [[TMP3]]
1784 ; CHECK-NEXT: [[G11:%.*]] = getelementptr i8, ptr [[TMP4]], i64 -24
1785 ; CHECK-NEXT: [[TMP5:%.*]] = sext i1 [[TMP1]] to i64
1786 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, ptr [[G11]], i64 [[TMP5]]
1787 ; CHECK-NEXT: [[TMP6:%.*]] = icmp eq i177 [[L_FROZEN]], -1
1788 ; CHECK-NEXT: [[B28:%.*]] = select i1 [[TMP6]], i177 0, i177 [[L_FROZEN]]
1789 ; CHECK-NEXT: store i177 [[B28]], ptr [[G62]], align 4
1790 ; CHECK-NEXT: ret void
1792 %L = load i177, ptr %A, align 4
1793 %B5 = udiv i177 %L, -1
1794 %B4 = add i177 %B5, -1
1795 %B = and i177 %B4, %L
1796 %B2 = add i177 %B, -1
1797 %G11 = getelementptr i177, ptr %A, i177 %B2
1798 %B6 = mul i177 %B5, %B2
1799 %B24 = ashr i177 %L, %B6
1800 %C17 = icmp sgt i177 %B, %B24
1801 %G62 = getelementptr i177, ptr %G11, i1 %C17
1802 %B28 = urem i177 %B24, %B6
1803 store i177 %B28, ptr %G62, align 4
1808 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38078
1809 define void @ossfuzz_38078(i32 %arg, i32 %arg1, ptr %ptr, ptr %ptr2, ptr %ptr3, ptr %ptr4, ptr %ptr5, ptr %ptr6, ptr %ptr7) {
1810 ; CHECK-LABEL: @ossfuzz_38078(
1812 ; CHECK-NEXT: [[G1:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 -4
1813 ; CHECK-NEXT: [[I2:%.*]] = sub i32 0, [[ARG1:%.*]]
1814 ; CHECK-NEXT: [[I5:%.*]] = icmp eq i32 [[ARG:%.*]], [[I2]]
1815 ; CHECK-NEXT: call void @llvm.assume(i1 [[I5]])
1816 ; CHECK-NEXT: store volatile i32 2147483647, ptr [[G1]], align 4
1817 ; CHECK-NEXT: br label [[BB:%.*]]
1819 ; CHECK-NEXT: unreachable
1823 %B24 = urem i32 %i, -2147483648
1824 %B21 = or i32 %i, %i
1825 %i2 = add nsw i32 %arg, %arg1
1826 %B7 = or i32 %i, %i2
1827 %B8 = and i32 %i, %i2
1828 %B12 = sdiv i32 %i2, %B7
1829 %B3 = add i32 %i2, %B24
1830 %B5 = and i32 %i, %B3
1831 %B18 = and i32 %i, %B8
1832 %i3 = xor i32 %i2, %B3
1833 %C1 = icmp ne i32 %B8, %B5
1834 %i4 = lshr i32 %B5, %i3
1835 %B29 = shl nuw i32 %B8, %i3
1836 %B2 = lshr i32 %B12, %i2
1837 %B16 = add i32 %B2, %i3
1838 %B = sdiv i32 %B29, %B5
1839 %B15 = sub i32 %i2, %B5
1840 %B22 = or i32 %B21, %B29
1841 %B23 = mul i32 %B15, %B
1842 %C2 = icmp sge i1 %C1, false
1843 %C7 = icmp sle i32 %i3, %B16
1844 %B20 = xor i32 %B21, %B22
1845 %G1 = getelementptr i32, ptr %ptr, i32 %B22
1847 %B26 = ashr i32 %B29, 0
1848 %B4 = add i32 0, %B5
1849 %B27 = srem i32 %B12, %B21
1850 %i5 = icmp eq i32 %B20, %B18
1851 %C11 = icmp ugt i32 %i4, %B4
1852 call void @llvm.assume(i1 %i5)
1853 store volatile i32 %B4, ptr %G1, align 4
1854 %B11 = or i32 0, %B23
1858 store i1 %C7, ptr %ptr2, align 1
1859 store i32 %B11, ptr %ptr3, align 4
1860 store i1 %C11, ptr %ptr4, align 1
1861 store i32 %B1, ptr %ptr5, align 4
1862 store i32 %B27, ptr %ptr6, align 4
1863 %C = icmp ne i32 %B26, 0
1864 %B17 = or i1 %C, %C2
1865 store i1 %B17, ptr %ptr7, align 1
1868 declare void @llvm.assume(i1 noundef)
1870 define i8 @lshr_mask_demand(i8 %x) {
1871 ; CHECK-LABEL: @lshr_mask_demand(
1872 ; CHECK-NEXT: [[S:%.*]] = lshr i8 63, [[X:%.*]]
1873 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 32
1874 ; CHECK-NEXT: ret i8 [[R]]
1876 %s = lshr i8 63, %x ; 0b00111111
1877 %r = and i8 %s, 224 ; 0b11100000
1881 define i8 @shl_mask_demand(i8 %x) {
1882 ; CHECK-LABEL: @shl_mask_demand(
1883 ; CHECK-NEXT: [[S:%.*]] = shl i8 12, [[X:%.*]]
1884 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 4
1885 ; CHECK-NEXT: ret i8 [[R]]
1887 %s = shl i8 12, %x ; 0b00001100
1888 %r = and i8 %s, 7 ; 0b00000111
1892 define i64 @lshr_mul_negpow2(i64 %x) {
1893 ; CHECK-LABEL: @lshr_mul_negpow2(
1894 ; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[X:%.*]]
1895 ; CHECK-NEXT: [[A:%.*]] = and i64 [[TMP1]], 4294967295
1896 ; CHECK-NEXT: ret i64 [[A]]
1898 %a = mul i64 %x, -4294967296
1899 %b = lshr i64 %a, 32
1903 define i64 @lshr_mul_negpow2_2(i64 %x) {
1904 ; CHECK-LABEL: @lshr_mul_negpow2_2(
1905 ; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[X:%.*]]
1906 ; CHECK-NEXT: [[A:%.*]] = and i64 [[TMP1]], 281474976710655
1907 ; CHECK-NEXT: ret i64 [[A]]
1909 %a = mul i64 %x, -65536
1910 %b = lshr i64 %a, 16
1914 define <2 x i32> @lshr_mul_negpow2_3(<2 x i32> %x) {
1915 ; CHECK-LABEL: @lshr_mul_negpow2_3(
1916 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> zeroinitializer, [[X:%.*]]
1917 ; CHECK-NEXT: [[A:%.*]] = and <2 x i32> [[TMP1]], splat (i32 255)
1918 ; CHECK-NEXT: ret <2 x i32> [[A]]
1920 %a = mul <2 x i32> %x, <i32 -16777216, i32 -16777216>
1921 %b = lshr <2 x i32> %a, <i32 24, i32 24>
1925 define i32 @lshr_mul_negpow2_4(i32 %x) {
1926 ; CHECK-LABEL: @lshr_mul_negpow2_4(
1927 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
1928 ; CHECK-NEXT: [[A:%.*]] = and i32 [[TMP1]], 65535
1929 ; CHECK-NEXT: [[B:%.*]] = xor i32 [[A]], 1
1930 ; CHECK-NEXT: ret i32 [[B]]
1932 %a = mul i32 %x, -65536
1933 %b = xor i32 %a, 65536
1934 %c = lshr i32 %b, 16
1938 define <2 x i32> @lshr_mul_negpow2_5(<2 x i32> %x) {
1939 ; CHECK-LABEL: @lshr_mul_negpow2_5(
1940 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> zeroinitializer, [[X:%.*]]
1941 ; CHECK-NEXT: [[A:%.*]] = and <2 x i32> [[TMP1]], splat (i32 65527)
1942 ; CHECK-NEXT: [[B:%.*]] = or disjoint <2 x i32> [[A]], splat (i32 8)
1943 ; CHECK-NEXT: ret <2 x i32> [[B]]
1945 %a = mul <2 x i32> %x, <i32 -65536, i32 -65536>
1946 %b = or <2 x i32> %a, <i32 524288, i32 524288>
1947 %c = lshr <2 x i32> %b, <i32 16, i32 16>
1951 define i64 @lshr_mul_negpow2_extra_use(i64 %x) {
1952 ; CHECK-LABEL: @lshr_mul_negpow2_extra_use(
1953 ; CHECK-NEXT: [[A:%.*]] = mul i64 [[X:%.*]], -4294967296
1954 ; CHECK-NEXT: [[B:%.*]] = lshr exact i64 [[A]], 32
1955 ; CHECK-NEXT: call void @use(i64 [[A]])
1956 ; CHECK-NEXT: ret i64 [[B]]
1958 %a = mul i64 %x, -4294967296
1959 %b = lshr i64 %a, 32
1960 call void @use(i64 %a)
1964 define i8 @ashr_sdiv_pos(i8 %x) {
1965 ; CHECK-LABEL: @ashr_sdiv_pos(
1966 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[X:%.*]], -41
1967 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[TMP1]] to i8
1968 ; CHECK-NEXT: ret i8 [[R]]
1975 define <2 x i8> @ashr_sdiv_neg_splat_vec(<2 x i8> %x) {
1976 ; CHECK-LABEL: @ashr_sdiv_neg_splat_vec(
1977 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]], splat (i8 41)
1978 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
1979 ; CHECK-NEXT: ret <2 x i8> [[R]]
1981 %d = sdiv <2 x i8> %x, <i8 -42, i8 -42>
1982 %r = ashr <2 x i8> %d, <i8 7, i8 7>
1986 define <2 x i8> @ashr_sdiv_neg_splat_vec_poison(<2 x i8> %x) {
1987 ; CHECK-LABEL: @ashr_sdiv_neg_splat_vec_poison(
1988 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X:%.*]], splat (i8 127)
1989 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
1990 ; CHECK-NEXT: ret <2 x i8> [[R]]
1992 %d = sdiv <2 x i8> %x, <i8 -127, i8 -127>
1993 %r = ashr <2 x i8> %d, <i8 7, i8 poison>
1997 define i8 @lshr_sdiv_pos(i8 %x) {
1998 ; CHECK-LABEL: @lshr_sdiv_pos(
1999 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[X:%.*]], -11
2000 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[TMP1]] to i8
2001 ; CHECK-NEXT: ret i8 [[R]]
2008 define i18 @lshr_sdiv_neg(i18 %x) {
2009 ; CHECK-LABEL: @lshr_sdiv_neg(
2010 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i18 [[X:%.*]], 11
2011 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[TMP1]] to i18
2012 ; CHECK-NEXT: ret i18 [[R]]
2014 %d = sdiv i18 %x, -12
2015 %r = lshr i18 %d, 17
2021 define i8 @ashr_sdiv_not_full_shift(i8 %x) {
2022 ; CHECK-LABEL: @ashr_sdiv_not_full_shift(
2023 ; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[X:%.*]], 42
2024 ; CHECK-NEXT: [[R:%.*]] = ashr i8 [[D]], 6
2025 ; CHECK-NEXT: ret i8 [[R]]
2034 define i32 @ashr_sdiv_extra_use(i32 %x) {
2035 ; CHECK-LABEL: @ashr_sdiv_extra_use(
2036 ; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 42
2037 ; CHECK-NEXT: call void @use_i32(i32 [[D]])
2038 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X]], -41
2039 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[TMP1]] to i32
2040 ; CHECK-NEXT: ret i32 [[R]]
2042 %d = sdiv i32 %x, 42
2043 call void @use_i32(i32 %d)
2044 %r = ashr i32 %d, 31
2048 define i32 @shl1_cttz(i32 %x) {
2049 ; CHECK-LABEL: @shl1_cttz(
2050 ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[X:%.*]]
2051 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[X]], [[NEG]]
2052 ; CHECK-NEXT: ret i32 [[SHL]]
2054 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
2055 %shl = shl i32 1, %tz
2059 define <2 x i8> @shl1_cttz_vec(<2 x i8> %x) {
2060 ; CHECK-LABEL: @shl1_cttz_vec(
2061 ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
2062 ; CHECK-NEXT: [[SHL:%.*]] = and <2 x i8> [[X]], [[NEG]]
2063 ; CHECK-NEXT: ret <2 x i8> [[SHL]]
2065 %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
2066 %shl = shl <2 x i8> <i8 1, i8 1>, %tz
2070 define <2 x i8> @shl1_cttz_vec_poison(<2 x i8> %x) {
2071 ; CHECK-LABEL: @shl1_cttz_vec_poison(
2072 ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
2073 ; CHECK-NEXT: [[SHL:%.*]] = and <2 x i8> [[X]], [[NEG]]
2074 ; CHECK-NEXT: ret <2 x i8> [[SHL]]
2076 %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
2077 %shl = shl <2 x i8> <i8 1, i8 poison>, %tz
2081 ; negative test - extra use
2083 define i32 @shl1_cttz_extra_use(i32 %x) {
2084 ; CHECK-LABEL: @shl1_cttz_extra_use(
2085 ; CHECK-NEXT: [[TZ:%.*]] = call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false)
2086 ; CHECK-NEXT: call void @use_i32(i32 [[TZ]])
2087 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[TZ]]
2088 ; CHECK-NEXT: ret i32 [[SHL]]
2090 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 false)
2091 call void @use_i32(i32 %tz)
2092 %shl = shl i32 1, %tz
2096 ; negative test - must be shift-left of 1
2098 define i32 @shl2_cttz(i32 %x) {
2099 ; CHECK-LABEL: @shl2_cttz(
2100 ; CHECK-NEXT: [[TZ:%.*]] = call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true)
2101 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 2, [[TZ]]
2102 ; CHECK-NEXT: ret i32 [[SHL]]
2104 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
2105 %shl = shl i32 2, %tz
2109 ; shift (X, amt | bitwidth - 1) -> shift (X, bitwidth - 1)
2110 define i6 @shl_or7_eq_shl7(i6 %x, i6 %c) {
2111 ; CHECK-LABEL: @shl_or7_eq_shl7(
2112 ; CHECK-NEXT: [[Y:%.*]] = shl nsw i6 [[X:%.*]], 5
2113 ; CHECK-NEXT: ret i6 [[Y]]
2116 ;; nsw not needed for transform, just check that we propagate.
2117 %y = shl nsw i6 %x, %amt
2121 define <2 x i8> @lshr_vec_or7_eq_shl7(<2 x i8> %x, <2 x i8> %c) {
2122 ; CHECK-LABEL: @lshr_vec_or7_eq_shl7(
2123 ; CHECK-NEXT: [[Y:%.*]] = lshr exact <2 x i8> [[X:%.*]], splat (i8 7)
2124 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2126 %amt = or <2 x i8> %c, <i8 7, i8 7>
2127 ;; exact not needed for transform, just check that we propagate.
2128 %y = lshr exact <2 x i8> %x, %amt
2132 define <2 x i8> @ashr_vec_or7_eq_ashr7(<2 x i8> %x, <2 x i8> %c) {
2133 ; CHECK-LABEL: @ashr_vec_or7_eq_ashr7(
2134 ; CHECK-NEXT: [[Y:%.*]] = ashr <2 x i8> [[X:%.*]], splat (i8 7)
2135 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2137 %amt = or <2 x i8> %c, <i8 7, i8 7>
2138 %y = ashr <2 x i8> %x, %amt
2142 ; Negative test not bitwidth - 1
2143 define <2 x i8> @ashr_vec_or6_fail(<2 x i8> %x, <2 x i8> %c) {
2144 ; CHECK-LABEL: @ashr_vec_or6_fail(
2145 ; CHECK-NEXT: [[AMT:%.*]] = or <2 x i8> [[C:%.*]], splat (i8 6)
2146 ; CHECK-NEXT: [[Y:%.*]] = ashr <2 x i8> [[X:%.*]], [[AMT]]
2147 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2149 %amt = or <2 x i8> %c, <i8 6, i8 6>
2150 %y = ashr <2 x i8> %x, %amt
2154 define i16 @lshr_and_not_demanded(i8 %x) {
2155 ; CHECK-LABEL: @lshr_and_not_demanded(
2156 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[X:%.*]] to i16
2157 ; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[Y_EXT]], 1
2158 ; CHECK-NEXT: ret i16 [[SHR]]
2161 %y.ext = sext i8 %y to i16
2162 %shr = lshr i16 %y.ext, 1
2166 define i16 @lshr_exact_and_not_demanded(i8 %x) {
2167 ; CHECK-LABEL: @lshr_exact_and_not_demanded(
2168 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[X:%.*]] to i16
2169 ; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[Y_EXT]], 1
2170 ; CHECK-NEXT: ret i16 [[SHR]]
2173 %y.ext = sext i8 %y to i16
2174 %shr = lshr exact i16 %y.ext, 1
2178 define i16 @lshr_and_demanded(i8 %x) {
2179 ; CHECK-LABEL: @lshr_and_demanded(
2180 ; CHECK-NEXT: [[Y:%.*]] = and i8 [[X:%.*]], -4
2181 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[Y]] to i16
2182 ; CHECK-NEXT: [[SHR:%.*]] = lshr exact i16 [[Y_EXT]], 1
2183 ; CHECK-NEXT: ret i16 [[SHR]]
2186 %y.ext = sext i8 %y to i16
2187 %shr = lshr i16 %y.ext, 1
2191 define i16 @ashr_umax_not_demanded(i16 %x) {
2192 ; CHECK-LABEL: @ashr_umax_not_demanded(
2193 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[X:%.*]], 1
2194 ; CHECK-NEXT: ret i16 [[SHR]]
2196 %y = call i16 @llvm.umax.i16(i16 %x, i16 1)
2197 %shr = ashr i16 %y, 1
2201 define i16 @ashr_exact_umax_not_demanded(i16 %x) {
2202 ; CHECK-LABEL: @ashr_exact_umax_not_demanded(
2203 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[X:%.*]], 1
2204 ; CHECK-NEXT: ret i16 [[SHR]]
2206 %y = call i16 @llvm.umax.i16(i16 %x, i16 1)
2207 %shr = ashr exact i16 %y, 1
2211 define i16 @ashr_umax_demanded(i16 %x) {
2212 ; CHECK-LABEL: @ashr_umax_demanded(
2213 ; CHECK-NEXT: [[Y:%.*]] = call i16 @llvm.umax.i16(i16 [[X:%.*]], i16 2)
2214 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[Y]], 1
2215 ; CHECK-NEXT: ret i16 [[SHR]]
2217 %y = call i16 @llvm.umax.i16(i16 %x, i16 2)
2218 %shr = ashr i16 %y, 1
2222 define i128 @shift_zext_nneg(i8 %arg) {
2223 ; CHECK-LABEL: @shift_zext_nneg(
2224 ; CHECK-NEXT: [[EXT:%.*]] = zext nneg i8 [[ARG:%.*]] to i128
2225 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i128 1, [[EXT]]
2226 ; CHECK-NEXT: ret i128 [[SHL]]
2228 %ext = zext i8 %arg to i128
2229 %shl = shl i128 1, %ext
2233 define i129 @shift_zext_not_nneg(i8 %arg) {
2234 ; CHECK-LABEL: @shift_zext_not_nneg(
2235 ; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[ARG:%.*]] to i129
2236 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i129 1, [[EXT]]
2237 ; CHECK-NEXT: ret i129 [[SHL]]
2239 %ext = zext i8 %arg to i129
2240 %shl = shl i129 1, %ext
2244 define i8 @src_shl_nsw(i8 %x) {
2245 ; CHECK-LABEL: @src_shl_nsw(
2246 ; CHECK-NEXT: [[R:%.*]] = shl nsw i8 32, [[X:%.*]]
2247 ; CHECK-NEXT: ret i8 [[R]]
2249 %sh = shl nsw i8 1, %x
2250 %r = shl nsw i8 %sh, 5
2254 define i8 @src_shl_nsw_fail(i8 %x) {
2255 ; CHECK-LABEL: @src_shl_nsw_fail(
2256 ; CHECK-NEXT: [[R:%.*]] = shl i8 32, [[X:%.*]]
2257 ; CHECK-NEXT: ret i8 [[R]]
2259 %sh = shl nsw i8 1, %x
2264 define i8 @src_shl_nuw(i8 %x) {
2265 ; CHECK-LABEL: @src_shl_nuw(
2266 ; CHECK-NEXT: [[R:%.*]] = shl nuw i8 12, [[X:%.*]]
2267 ; CHECK-NEXT: ret i8 [[R]]
2269 %sh = shl nuw i8 3, %x
2270 %r = shl nuw i8 %sh, 2
2274 define i8 @src_shl_nuw_fail(i8 %x) {
2275 ; CHECK-LABEL: @src_shl_nuw_fail(
2276 ; CHECK-NEXT: [[R:%.*]] = shl i8 12, [[X:%.*]]
2277 ; CHECK-NEXT: ret i8 [[R]]
2280 %r = shl nuw i8 %sh, 2
2284 define i8 @src_lshr_exact(i8 %x) {
2285 ; CHECK-LABEL: @src_lshr_exact(
2286 ; CHECK-NEXT: [[R:%.*]] = lshr exact i8 48, [[X:%.*]]
2287 ; CHECK-NEXT: ret i8 [[R]]
2289 %sh = lshr exact i8 96, %x
2290 %r = lshr exact i8 %sh, 1
2294 define i8 @src_lshr_exact_fail(i8 %x) {
2295 ; CHECK-LABEL: @src_lshr_exact_fail(
2296 ; CHECK-NEXT: [[R:%.*]] = lshr i8 48, [[X:%.*]]
2297 ; CHECK-NEXT: ret i8 [[R]]
2299 %sh = lshr exact i8 96, %x
2304 define i8 @src_ashr_exact(i8 %x) {
2305 ; CHECK-LABEL: @src_ashr_exact(
2306 ; CHECK-NEXT: [[R:%.*]] = ashr exact i8 -8, [[X:%.*]]
2307 ; CHECK-NEXT: ret i8 [[R]]
2309 %sh = ashr exact i8 -32, %x
2310 %r = ashr exact i8 %sh, 2
2314 define i8 @src_ashr_exact_fail(i8 %x) {
2315 ; CHECK-LABEL: @src_ashr_exact_fail(
2316 ; CHECK-NEXT: [[R:%.*]] = ashr i8 -8, [[X:%.*]]
2317 ; CHECK-NEXT: ret i8 [[R]]
2319 %sh = ashr i8 -32, %x
2320 %r = ashr exact i8 %sh, 2
2324 declare i16 @llvm.umax.i16(i16, i16)