1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes='instcombine<no-verify-fixpoint>' -S | FileCheck %s
4 ; The fuzzer-generated @ashr_out_of_range test case does not reach a fixpoint,
5 ; because a logical and it not relaxed to a bitwise and in one iteration.
8 declare void @use_i32(i32)
10 declare i32 @llvm.cttz.i32(i32, i1 immarg)
11 declare <2 x i8> @llvm.cttz.v2i8(<2 x i8>, i1 immarg)
13 define <4 x i32> @lshr_non_splat_vector(<4 x i32> %A) {
14 ; CHECK-LABEL: @lshr_non_splat_vector(
15 ; CHECK-NEXT: [[B:%.*]] = lshr <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
16 ; CHECK-NEXT: ret <4 x i32> [[B]]
18 %B = lshr <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
22 define <4 x i32> @shl_non_splat_vector(<4 x i32> %A) {
23 ; CHECK-LABEL: @shl_non_splat_vector(
24 ; CHECK-NEXT: [[B:%.*]] = shl <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
25 ; CHECK-NEXT: ret <4 x i32> [[B]]
27 %B = shl <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
31 define i32 @test6(i32 %A) {
32 ; CHECK-LABEL: @test6(
33 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
34 ; CHECK-NEXT: ret i32 [[C]]
36 %B = shl i32 %A, 1 ;; convert to an mul instruction
41 define i32 @test6a(i32 %A) {
42 ; CHECK-LABEL: @test6a(
43 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
44 ; CHECK-NEXT: ret i32 [[C]]
47 %C = shl i32 %B, 1 ;; convert to an mul instruction
51 ;; (A << 5) << 3 === A << 8 == 0
52 define i8 @test8(i8 %A) {
53 ; CHECK-LABEL: @test8(
54 ; CHECK-NEXT: ret i8 0
61 ;; (A << 7) >> 7 === A & 1
62 define i8 @test9(i8 %A) {
63 ; CHECK-LABEL: @test9(
64 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], 1
65 ; CHECK-NEXT: ret i8 [[B]]
72 ;; (A >> 7) << 7 === A & 128
74 define i8 @test10(i8 %A) {
75 ; CHECK-LABEL: @test10(
76 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], -128
77 ; CHECK-NEXT: ret i8 [[B]]
84 ;; Allow the simplification when the lshr shift is exact.
85 define i8 @test10a(i8 %A) {
86 ; CHECK-LABEL: @test10a(
87 ; CHECK-NEXT: ret i8 [[A:%.*]]
89 %B = lshr exact i8 %A, 7
94 ;; (A >> 3) << 4 === (A & 0x1F) << 1
95 define i8 @test11(i8 %x) {
96 ; CHECK-LABEL: @test11(
97 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
98 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
99 ; CHECK-NEXT: ret i8 [[C]]
107 ;; Allow the simplification in InstCombine when the lshr shift is exact.
108 define i8 @test11a(i8 %A) {
109 ; CHECK-LABEL: @test11a(
110 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
111 ; CHECK-NEXT: ret i8 [[C]]
114 %B = lshr exact i8 %a, 3
119 ;; (A >> 8) << 8 === A & -256
120 define i32 @test12(i32 %A) {
121 ; CHECK-LABEL: @test12(
122 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], -256
123 ; CHECK-NEXT: ret i32 [[C]]
130 ;; ((A >>s 6) << 6 === (A & FFFFFFC0)
131 define i8 @shishi(i8 %x) {
132 ; CHECK-LABEL: @shishi(
133 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 6
134 ; CHECK-NEXT: [[B:%.*]] = and i8 [[X]], -64
135 ; CHECK-NEXT: [[EXTRA_USE_OF_A:%.*]] = mul nsw i8 [[A]], 5
136 ; CHECK-NEXT: [[R:%.*]] = sdiv i8 [[EXTRA_USE_OF_A]], [[B]]
137 ; CHECK-NEXT: ret i8 [[R]]
141 %extra_use_of_a = mul i8 %a, 5
142 %r = sdiv i8 %extra_use_of_a, %b
146 ;; (A >> 3) << 4 === (A & -8) * 2
147 define i8 @test13(i8 %x) {
148 ; CHECK-LABEL: @test13(
149 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
150 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
151 ; CHECK-NEXT: ret i8 [[C]]
159 define i8 @test13a(i8 %A) {
160 ; CHECK-LABEL: @test13a(
161 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
162 ; CHECK-NEXT: ret i8 [[C]]
165 %B = ashr exact i8 %a, 3
170 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
171 define i32 @test14(i32 %A) {
172 ; CHECK-LABEL: @test14(
173 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -19760
174 ; CHECK-NEXT: [[C:%.*]] = or disjoint i32 [[B]], 19744
175 ; CHECK-NEXT: ret i32 [[C]]
183 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
184 define i32 @test14a(i32 %A) {
185 ; CHECK-LABEL: @test14a(
186 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], 77
187 ; CHECK-NEXT: ret i32 [[C]]
190 %C = and i32 %B, 1234
195 define i32 @test15(i1 %C) {
196 ; CHECK-LABEL: @test15(
197 ; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], i32 12, i32 4
198 ; CHECK-NEXT: ret i32 [[A]]
200 %A = select i1 %C, i32 3, i32 1
205 define i32 @test15a(i1 %C) {
206 ; CHECK-LABEL: @test15a(
207 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], i32 512, i32 128
208 ; CHECK-NEXT: ret i32 [[V]]
210 %A = select i1 %C, i8 3, i8 1
211 %shift.upgrd.4 = zext i8 %A to i32
212 %V = shl i32 64, %shift.upgrd.4
216 define i1 @test16(i32 %X) {
217 ; CHECK-LABEL: @test16(
218 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 16
219 ; CHECK-NEXT: [[I_7:%.*]] = icmp ne i32 [[TMP1]], 0
220 ; CHECK-NEXT: ret i1 [[I_7]]
222 %i.3 = ashr i32 %X, 4
223 %i.6 = and i32 %i.3, 1
224 %i.7 = icmp ne i32 %i.6, 0
228 define i1 @test17(i32 %A) {
229 ; CHECK-LABEL: @test17(
230 ; CHECK-NEXT: [[B_MASK:%.*]] = and i32 [[A:%.*]], -8
231 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[B_MASK]], 9872
232 ; CHECK-NEXT: ret i1 [[C]]
235 %C = icmp eq i32 %B, 1234
239 define <2 x i1> @test17vec(<2 x i32> %A) {
240 ; CHECK-LABEL: @test17vec(
241 ; CHECK-NEXT: [[B_MASK:%.*]] = and <2 x i32> [[A:%.*]], <i32 -8, i32 -8>
242 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[B_MASK]], <i32 9872, i32 9872>
243 ; CHECK-NEXT: ret <2 x i1> [[C]]
245 %B = lshr <2 x i32> %A, <i32 3, i32 3>
246 %C = icmp eq <2 x i32> %B, <i32 1234, i32 1234>
250 define i1 @test18(i8 %A) {
251 ; CHECK-LABEL: @test18(
252 ; CHECK-NEXT: ret i1 false
256 %C = icmp eq i8 %B, 123
260 define i1 @test19(i32 %A) {
261 ; CHECK-LABEL: @test19(
262 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A:%.*]], 4
263 ; CHECK-NEXT: ret i1 [[C]]
267 %C = icmp eq i32 %B, 0
271 define <2 x i1> @test19vec(<2 x i32> %A) {
272 ; CHECK-LABEL: @test19vec(
273 ; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i32> [[A:%.*]], <i32 4, i32 4>
274 ; CHECK-NEXT: ret <2 x i1> [[C]]
276 %B = ashr <2 x i32> %A, <i32 2, i32 2>
277 %C = icmp eq <2 x i32> %B, zeroinitializer
282 define i1 @test19a(i32 %A) {
283 ; CHECK-LABEL: @test19a(
284 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[A:%.*]], -5
285 ; CHECK-NEXT: ret i1 [[C]]
288 %C = icmp eq i32 %B, -1
292 define <2 x i1> @test19a_vec(<2 x i32> %A) {
293 ; CHECK-LABEL: @test19a_vec(
294 ; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[A:%.*]], <i32 -5, i32 -5>
295 ; CHECK-NEXT: ret <2 x i1> [[C]]
297 %B = ashr <2 x i32> %A, <i32 2, i32 2>
298 %C = icmp eq <2 x i32> %B, <i32 -1, i32 -1>
302 define i1 @test20(i8 %A) {
303 ; CHECK-LABEL: @test20(
304 ; CHECK-NEXT: ret i1 false
308 %C = icmp eq i8 %B, 123
312 define i1 @test21(i8 %A) {
313 ; CHECK-LABEL: @test21(
314 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
315 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 8
316 ; CHECK-NEXT: ret i1 [[C]]
319 %C = icmp eq i8 %B, -128
323 define i1 @test22(i8 %A) {
324 ; CHECK-LABEL: @test22(
325 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
326 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 0
327 ; CHECK-NEXT: ret i1 [[C]]
330 %C = icmp eq i8 %B, 0
334 define i8 @test23(i32 %A) {
335 ; CHECK-LABEL: @test23(
336 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[A:%.*]] to i8
337 ; CHECK-NEXT: ret i8 [[D]]
342 %D = trunc i32 %C to i8
346 define i8 @test24(i8 %X) {
347 ; CHECK-LABEL: @test24(
348 ; CHECK-NEXT: [[Z:%.*]] = and i8 [[X:%.*]], 3
349 ; CHECK-NEXT: ret i8 [[Z]]
357 ;; handle casts between shifts.
358 define i32 @test26(i32 %A) {
359 ; CHECK-LABEL: @test26(
360 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -2
361 ; CHECK-NEXT: ret i32 [[B]]
364 %C = bitcast i32 %B to i32
369 define i1 @test27(i32 %x) nounwind {
370 ; CHECK-LABEL: @test27(
371 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 8
372 ; CHECK-NEXT: [[Z:%.*]] = icmp ne i32 [[TMP1]], 0
373 ; CHECK-NEXT: ret i1 [[Z]]
376 %z = trunc i32 %y to i1
380 define i1 @test28(i8 %x) {
381 ; CHECK-LABEL: @test28(
382 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
383 ; CHECK-NEXT: ret i1 [[CMP]]
386 %cmp = icmp ne i8 %shr, 0
390 define <2 x i1> @test28vec(<2 x i8> %x) {
391 ; CHECK-LABEL: @test28vec(
392 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
393 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
395 %shr = lshr <2 x i8> %x, <i8 7, i8 7>
396 %cmp = icmp ne <2 x i8> %shr, zeroinitializer
400 define i8 @test28a(i8 %x, i8 %y) {
401 ; CHECK-LABEL: @test28a(
403 ; CHECK-NEXT: [[COND1_NOT:%.*]] = icmp sgt i8 [[X:%.*]], -1
404 ; CHECK-NEXT: br i1 [[COND1_NOT]], label [[BB2:%.*]], label [[BB1:%.*]]
406 ; CHECK-NEXT: ret i8 1
408 ; CHECK-NEXT: ret i8 [[Y:%.*]]
411 ; This shouldn't be transformed.
413 %cond1 = icmp ne i8 %i1, 0
414 br i1 %cond1, label %bb1, label %bb2
422 define i32 @test29(i64 %d18) {
423 ; CHECK-LABEL: @test29(
425 ; CHECK-NEXT: [[SUM_SHIFT:%.*]] = lshr i64 [[D18:%.*]], 63
426 ; CHECK-NEXT: [[I101:%.*]] = trunc i64 [[SUM_SHIFT]] to i32
427 ; CHECK-NEXT: ret i32 [[I101]]
430 %i916 = lshr i64 %d18, 32
431 %i917 = trunc i64 %i916 to i32
432 %i10 = lshr i32 %i917, 31
436 define <2 x i32> @test29_uniform(<2 x i64> %d18) {
437 ; CHECK-LABEL: @test29_uniform(
439 ; CHECK-NEXT: [[SUM_SHIFT:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 63, i64 63>
440 ; CHECK-NEXT: [[I101:%.*]] = trunc <2 x i64> [[SUM_SHIFT]] to <2 x i32>
441 ; CHECK-NEXT: ret <2 x i32> [[I101]]
444 %i916 = lshr <2 x i64> %d18, <i64 32, i64 32>
445 %i917 = trunc <2 x i64> %i916 to <2 x i32>
446 %i10 = lshr <2 x i32> %i917, <i32 31, i32 31>
450 define <2 x i32> @test29_nonuniform(<2 x i64> %d18) {
451 ; CHECK-LABEL: @test29_nonuniform(
453 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 15>
454 ; CHECK-NEXT: [[I917:%.*]] = trunc <2 x i64> [[I916]] to <2 x i32>
455 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 22>
456 ; CHECK-NEXT: ret <2 x i32> [[I10]]
459 %i916 = lshr <2 x i64> %d18, <i64 32, i64 15>
460 %i917 = trunc <2 x i64> %i916 to <2 x i32>
461 %i10 = lshr <2 x i32> %i917, <i32 31, i32 22>
465 define <2 x i32> @test29_poison(<2 x i64> %d18) {
466 ; CHECK-LABEL: @test29_poison(
468 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 poison>
469 ; CHECK-NEXT: [[I917:%.*]] = trunc <2 x i64> [[I916]] to <2 x i32>
470 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 poison>
471 ; CHECK-NEXT: ret <2 x i32> [[I10]]
474 %i916 = lshr <2 x i64> %d18, <i64 32, i64 poison>
475 %i917 = trunc <2 x i64> %i916 to <2 x i32>
476 %i10 = lshr <2 x i32> %i917, <i32 31, i32 poison>
480 define i32 @test30(i32 %A, i32 %B, i32 %C) {
481 ; CHECK-LABEL: @test30(
482 ; CHECK-NEXT: [[X1:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
483 ; CHECK-NEXT: [[Z:%.*]] = shl i32 [[X1]], [[C:%.*]]
484 ; CHECK-NEXT: ret i32 [[Z]]
492 define i32 @test31(i32 %A, i32 %B, i32 %C) {
493 ; CHECK-LABEL: @test31(
494 ; CHECK-NEXT: [[X1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
495 ; CHECK-NEXT: [[Z:%.*]] = lshr i32 [[X1]], [[C:%.*]]
496 ; CHECK-NEXT: ret i32 [[Z]]
504 define i32 @test32(i32 %A, i32 %B, i32 %C) {
505 ; CHECK-LABEL: @test32(
506 ; CHECK-NEXT: [[X1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
507 ; CHECK-NEXT: [[Z:%.*]] = ashr i32 [[X1]], [[C:%.*]]
508 ; CHECK-NEXT: ret i32 [[Z]]
516 define i1 @test33(i32 %X) {
517 ; CHECK-LABEL: @test33(
518 ; CHECK-NEXT: [[I1_MASK:%.*]] = and i32 [[X:%.*]], 16777216
519 ; CHECK-NEXT: [[I2:%.*]] = icmp ne i32 [[I1_MASK]], 0
520 ; CHECK-NEXT: ret i1 [[I2]]
523 %i2 = icmp slt i32 %i1, 0
527 define <2 x i1> @test33vec(<2 x i32> %X) {
528 ; CHECK-LABEL: @test33vec(
529 ; CHECK-NEXT: [[I1_MASK:%.*]] = and <2 x i32> [[X:%.*]], <i32 16777216, i32 16777216>
530 ; CHECK-NEXT: [[I2:%.*]] = icmp ne <2 x i32> [[I1_MASK]], zeroinitializer
531 ; CHECK-NEXT: ret <2 x i1> [[I2]]
533 %i1 = shl <2 x i32> %X, <i32 7, i32 7>
534 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
538 define i1 @test34(i32 %X) {
539 ; CHECK-LABEL: @test34(
540 ; CHECK-NEXT: ret i1 false
543 %i2 = icmp slt i32 %i1, 0
547 define i1 @test35(i32 %X) {
548 ; CHECK-LABEL: @test35(
549 ; CHECK-NEXT: [[I2:%.*]] = icmp slt i32 [[X:%.*]], 0
550 ; CHECK-NEXT: ret i1 [[I2]]
553 %i2 = icmp slt i32 %i1, 0
557 define <2 x i1> @test35vec(<2 x i32> %X) {
558 ; CHECK-LABEL: @test35vec(
559 ; CHECK-NEXT: [[I2:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
560 ; CHECK-NEXT: ret <2 x i1> [[I2]]
562 %i1 = ashr <2 x i32> %X, <i32 7, i32 7>
563 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
567 define i128 @test36(i128 %A, i128 %B) {
568 ; CHECK-LABEL: @test36(
569 ; CHECK-NEXT: [[I231:%.*]] = or i128 [[B:%.*]], [[A:%.*]]
570 ; CHECK-NEXT: [[INS:%.*]] = and i128 [[I231]], 18446744073709551615
571 ; CHECK-NEXT: ret i128 [[INS]]
573 %i27 = shl i128 %A, 64
574 %i23 = shl i128 %B, 64
575 %ins = or i128 %i23, %i27
576 %i45 = lshr i128 %ins, 64
580 define i64 @test37(i128 %A, i32 %B) {
581 ; CHECK-LABEL: @test37(
582 ; CHECK-NEXT: [[I22:%.*]] = zext i32 [[B:%.*]] to i128
583 ; CHECK-NEXT: [[I23:%.*]] = shl nuw nsw i128 [[I22]], 32
584 ; CHECK-NEXT: [[INS:%.*]] = or i128 [[I23]], [[A:%.*]]
585 ; CHECK-NEXT: [[I46:%.*]] = trunc i128 [[INS]] to i64
586 ; CHECK-NEXT: ret i64 [[I46]]
588 %i27 = shl i128 %A, 64
589 %i22 = zext i32 %B to i128
590 %i23 = shl i128 %i22, 96
591 %ins = or i128 %i23, %i27
592 %i45 = lshr i128 %ins, 64
593 %i46 = trunc i128 %i45 to i64
597 define <2 x i32> @shl_nuw_nsw_splat_vec(<2 x i8> %x) {
598 ; CHECK-LABEL: @shl_nuw_nsw_splat_vec(
599 ; CHECK-NEXT: [[T2:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i32>
600 ; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw <2 x i32> [[T2]], <i32 17, i32 17>
601 ; CHECK-NEXT: ret <2 x i32> [[T3]]
603 %t2 = zext <2 x i8> %x to <2 x i32>
604 %t3 = shl <2 x i32> %t2, <i32 17, i32 17>
608 define i32 @test38(i32 %x) nounwind readnone {
609 ; CHECK-LABEL: @test38(
610 ; CHECK-NEXT: [[REM1:%.*]] = and i32 [[X:%.*]], 31
611 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[REM1]]
612 ; CHECK-NEXT: ret i32 [[SHL]]
614 %rem = srem i32 %x, 32
615 %shl = shl i32 1, %rem
619 define <2 x i32> @test38_uniform(<2 x i32> %x) nounwind readnone {
620 ; CHECK-LABEL: @test38_uniform(
621 ; CHECK-NEXT: [[REM1:%.*]] = and <2 x i32> [[X:%.*]], <i32 31, i32 31>
622 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <2 x i32> <i32 1, i32 1>, [[REM1]]
623 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
625 %rem = srem <2 x i32> %x, <i32 32, i32 32>
626 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
630 define <3 x i32> @test38_nonuniform(<3 x i32> %x) nounwind readnone {
631 ; CHECK-LABEL: @test38_nonuniform(
632 ; CHECK-NEXT: [[REM1:%.*]] = and <3 x i32> [[X:%.*]], <i32 31, i32 15, i32 0>
633 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <3 x i32> <i32 1, i32 1, i32 1>, [[REM1]]
634 ; CHECK-NEXT: ret <3 x i32> [[SHL]]
636 %rem = srem <3 x i32> %x, <i32 32, i32 16, i32 1>
637 %shl = shl <3 x i32> <i32 1, i32 1, i32 1>, %rem
641 define <2 x i32> @test38_poison(<2 x i32> %x) nounwind readnone {
642 ; CHECK-LABEL: @test38_poison(
643 ; CHECK-NEXT: ret <2 x i32> poison
645 %rem = srem <2 x i32> %x, <i32 32, i32 poison>
646 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
650 ; <rdar://problem/8756731>
651 define i8 @test39(i32 %a0) {
652 ; CHECK-LABEL: @test39(
654 ; CHECK-NEXT: [[I4:%.*]] = trunc i32 [[A0:%.*]] to i8
655 ; CHECK-NEXT: [[I5:%.*]] = shl i8 [[I4]], 5
656 ; CHECK-NEXT: [[I49:%.*]] = shl i8 [[I4]], 6
657 ; CHECK-NEXT: [[I50:%.*]] = and i8 [[I49]], 64
658 ; CHECK-NEXT: [[I51:%.*]] = xor i8 [[I50]], [[I5]]
659 ; CHECK-NEXT: [[TMP0:%.*]] = lshr exact i8 [[I5]], 3
660 ; CHECK-NEXT: [[I54:%.*]] = and i8 [[TMP0]], 16
661 ; CHECK-NEXT: [[I551:%.*]] = or disjoint i8 [[I54]], [[I51]]
662 ; CHECK-NEXT: ret i8 [[I551]]
665 %i4 = trunc i32 %a0 to i8
667 %i48 = and i8 %i5, 32
668 %i49 = lshr i8 %i48, 5
669 %i50 = mul i8 %i49, 64
670 %i51 = xor i8 %i50, %i5
671 %i52 = and i8 %i51, -128
672 %i53 = lshr i8 %i52, 7
673 %i54 = mul i8 %i53, 16
674 %i55 = xor i8 %i54, %i51
678 define i32 @test42(i32 %a, i32 %b) nounwind {
679 ; CHECK-LABEL: @test42(
680 ; CHECK-NEXT: [[DIV:%.*]] = lshr exact i32 4096, [[B:%.*]]
681 ; CHECK-NEXT: [[DIV2:%.*]] = udiv i32 [[A:%.*]], [[DIV]]
682 ; CHECK-NEXT: ret i32 [[DIV2]]
684 %div = lshr i32 4096, %b ; must be exact otherwise we'd divide by zero
685 %div2 = udiv i32 %a, %div
689 define <2 x i32> @test42vec(<2 x i32> %a, <2 x i32> %b) {
690 ; CHECK-LABEL: @test42vec(
691 ; CHECK-NEXT: [[DIV:%.*]] = lshr exact <2 x i32> <i32 4096, i32 4096>, [[B:%.*]]
692 ; CHECK-NEXT: [[DIV2:%.*]] = udiv <2 x i32> [[A:%.*]], [[DIV]]
693 ; CHECK-NEXT: ret <2 x i32> [[DIV2]]
695 %div = lshr <2 x i32> <i32 4096, i32 4096>, %b ; must be exact otherwise we'd divide by zero
696 %div2 = udiv <2 x i32> %a, %div
700 define i32 @test43(i32 %a, i32 %b) nounwind {
701 ; CHECK-LABEL: @test43(
702 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], 12
703 ; CHECK-NEXT: [[DIV21:%.*]] = lshr i32 [[A:%.*]], [[TMP1]]
704 ; CHECK-NEXT: ret i32 [[DIV21]]
706 %div = shl i32 4096, %b ; must be exact otherwise we'd divide by zero
707 %div2 = udiv i32 %a, %div
711 define i32 @test44(i32 %a) nounwind {
712 ; CHECK-LABEL: @test44(
713 ; CHECK-NEXT: [[Y:%.*]] = shl i32 [[A:%.*]], 5
714 ; CHECK-NEXT: ret i32 [[Y]]
716 %y = shl nuw i32 %a, 1
721 define i32 @test45(i32 %a) nounwind {
722 ; CHECK-LABEL: @test45(
723 ; CHECK-NEXT: [[Y:%.*]] = lshr i32 [[A:%.*]], 5
724 ; CHECK-NEXT: ret i32 [[Y]]
726 %y = lshr exact i32 %a, 1
731 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
733 define i32 @test46(i32 %a) {
734 ; CHECK-LABEL: @test46(
735 ; CHECK-NEXT: [[Z:%.*]] = ashr exact i32 [[A:%.*]], 2
736 ; CHECK-NEXT: ret i32 [[Z]]
738 %y = ashr exact i32 %a, 3
743 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
745 define <2 x i32> @test46_splat_vec(<2 x i32> %a) {
746 ; CHECK-LABEL: @test46_splat_vec(
747 ; CHECK-NEXT: [[Z:%.*]] = ashr exact <2 x i32> [[A:%.*]], <i32 2, i32 2>
748 ; CHECK-NEXT: ret <2 x i32> [[Z]]
750 %y = ashr exact <2 x i32> %a, <i32 3, i32 3>
751 %z = shl <2 x i32> %y, <i32 1, i32 1>
755 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
757 define i8 @test47(i8 %a) {
758 ; CHECK-LABEL: @test47(
759 ; CHECK-NEXT: [[Z:%.*]] = lshr exact i8 [[A:%.*]], 2
760 ; CHECK-NEXT: ret i8 [[Z]]
762 %y = lshr exact i8 %a, 3
767 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
769 define <2 x i8> @test47_splat_vec(<2 x i8> %a) {
770 ; CHECK-LABEL: @test47_splat_vec(
771 ; CHECK-NEXT: [[Z:%.*]] = lshr exact <2 x i8> [[A:%.*]], <i8 2, i8 2>
772 ; CHECK-NEXT: ret <2 x i8> [[Z]]
774 %y = lshr exact <2 x i8> %a, <i8 3, i8 3>
775 %z = shl <2 x i8> %y, <i8 1, i8 1>
779 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when C2 > C1
781 define i32 @test48(i32 %x) {
782 ; CHECK-LABEL: @test48(
783 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
784 ; CHECK-NEXT: ret i32 [[B]]
786 %A = lshr exact i32 %x, 1
791 ; Verify that wrap flags are preserved from the original 'shl'.
793 define i32 @test48_nuw_nsw(i32 %x) {
794 ; CHECK-LABEL: @test48_nuw_nsw(
795 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
796 ; CHECK-NEXT: ret i32 [[B]]
798 %A = lshr exact i32 %x, 1
799 %B = shl nuw nsw i32 %A, 3
803 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
805 define <2 x i32> @test48_splat_vec(<2 x i32> %x) {
806 ; CHECK-LABEL: @test48_splat_vec(
807 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
808 ; CHECK-NEXT: ret <2 x i32> [[B]]
810 %A = lshr exact <2 x i32> %x, <i32 1, i32 1>
811 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
815 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when C2 > C1
817 define i32 @test49(i32 %x) {
818 ; CHECK-LABEL: @test49(
819 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
820 ; CHECK-NEXT: ret i32 [[B]]
822 %A = ashr exact i32 %x, 1
827 ; Verify that wrap flags are preserved from the original 'shl'.
829 define i32 @test49_nuw_nsw(i32 %x) {
830 ; CHECK-LABEL: @test49_nuw_nsw(
831 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
832 ; CHECK-NEXT: ret i32 [[B]]
834 %A = ashr exact i32 %x, 1
835 %B = shl nuw nsw i32 %A, 3
839 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
841 define <2 x i32> @test49_splat_vec(<2 x i32> %x) {
842 ; CHECK-LABEL: @test49_splat_vec(
843 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
844 ; CHECK-NEXT: ret <2 x i32> [[B]]
846 %A = ashr exact <2 x i32> %x, <i32 1, i32 1>
847 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
851 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
853 define i32 @test50(i32 %x) {
854 ; CHECK-LABEL: @test50(
855 ; CHECK-NEXT: [[B:%.*]] = ashr i32 [[X:%.*]], 2
856 ; CHECK-NEXT: ret i32 [[B]]
858 %A = shl nsw i32 %x, 1
863 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
864 ; Also, check that exact is propagated.
866 define <2 x i32> @test50_splat_vec(<2 x i32> %x) {
867 ; CHECK-LABEL: @test50_splat_vec(
868 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i32> [[X:%.*]], <i32 2, i32 2>
869 ; CHECK-NEXT: ret <2 x i32> [[B]]
871 %A = shl nsw <2 x i32> %x, <i32 1, i32 1>
872 %B = ashr exact <2 x i32> %A, <i32 3, i32 3>
876 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1)
878 define i32 @test51(i32 %x) {
879 ; CHECK-LABEL: @test51(
880 ; CHECK-NEXT: [[B:%.*]] = lshr i32 [[X:%.*]], 2
881 ; CHECK-NEXT: ret i32 [[B]]
883 %A = shl nuw i32 %x, 1
888 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1) with splats
889 ; Also, check that exact is propagated.
891 define <2 x i32> @test51_splat_vec(<2 x i32> %x) {
892 ; CHECK-LABEL: @test51_splat_vec(
893 ; CHECK-NEXT: [[B:%.*]] = lshr exact <2 x i32> [[X:%.*]], <i32 2, i32 2>
894 ; CHECK-NEXT: ret <2 x i32> [[B]]
896 %A = shl nuw <2 x i32> %x, <i32 1, i32 1>
897 %B = lshr exact <2 x i32> %A, <i32 3, i32 3>
901 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
902 ; Also, check that exact is propagated.
904 define i32 @test51_no_nuw(i32 %x) {
905 ; CHECK-LABEL: @test51_no_nuw(
906 ; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i32 [[X:%.*]], 2
907 ; CHECK-NEXT: [[B:%.*]] = and i32 [[TMP1]], 536870911
908 ; CHECK-NEXT: ret i32 [[B]]
911 %B = lshr exact i32 %A, 3
915 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
917 define <2 x i32> @test51_no_nuw_splat_vec(<2 x i32> %x) {
918 ; CHECK-LABEL: @test51_no_nuw_splat_vec(
919 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 2, i32 2>
920 ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[TMP1]], <i32 536870911, i32 536870911>
921 ; CHECK-NEXT: ret <2 x i32> [[B]]
923 %A = shl <2 x i32> %x, <i32 1, i32 1>
924 %B = lshr <2 x i32> %A, <i32 3, i32 3>
928 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
930 define i32 @test52(i32 %x) {
931 ; CHECK-LABEL: @test52(
932 ; CHECK-NEXT: [[B:%.*]] = shl nsw i32 [[X:%.*]], 2
933 ; CHECK-NEXT: ret i32 [[B]]
935 %A = shl nsw i32 %x, 3
940 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
942 define <2 x i32> @test52_splat_vec(<2 x i32> %x) {
943 ; CHECK-LABEL: @test52_splat_vec(
944 ; CHECK-NEXT: [[B:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
945 ; CHECK-NEXT: ret <2 x i32> [[B]]
947 %A = shl nsw <2 x i32> %x, <i32 3, i32 3>
948 %B = ashr <2 x i32> %A, <i32 1, i32 1>
952 ; (X <<nuw C1) >>u C2 --> X <<nuw/nsw (C1 - C2)
954 define i32 @test53(i32 %x) {
955 ; CHECK-LABEL: @test53(
956 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
957 ; CHECK-NEXT: ret i32 [[B]]
959 %A = shl nuw i32 %x, 3
964 ; (X <<nuw C1) >>u C2 --> X <<nuw/nsw (C1 - C2)
966 define <2 x i32> @test53_splat_vec(<2 x i32> %x) {
967 ; CHECK-LABEL: @test53_splat_vec(
968 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
969 ; CHECK-NEXT: ret <2 x i32> [[B]]
971 %A = shl nuw <2 x i32> %x, <i32 3, i32 3>
972 %B = lshr <2 x i32> %A, <i32 1, i32 1>
976 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
978 define i8 @test53_no_nuw(i8 %x) {
979 ; CHECK-LABEL: @test53_no_nuw(
980 ; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[X:%.*]], 2
981 ; CHECK-NEXT: [[B:%.*]] = and i8 [[TMP1]], 124
982 ; CHECK-NEXT: ret i8 [[B]]
989 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
991 define <2 x i8> @test53_no_nuw_splat_vec(<2 x i8> %x) {
992 ; CHECK-LABEL: @test53_no_nuw_splat_vec(
993 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> [[X:%.*]], <i8 2, i8 2>
994 ; CHECK-NEXT: [[B:%.*]] = and <2 x i8> [[TMP1]], <i8 124, i8 124>
995 ; CHECK-NEXT: ret <2 x i8> [[B]]
997 %A = shl <2 x i8> %x, <i8 3, i8 3>
998 %B = lshr <2 x i8> %A, <i8 1, i8 1>
1002 define i32 @test54(i32 %x) {
1003 ; CHECK-LABEL: @test54(
1004 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1005 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[TMP1]], 16
1006 ; CHECK-NEXT: ret i32 [[AND]]
1008 %shr2 = lshr i32 %x, 1
1009 %shl = shl i32 %shr2, 4
1010 %and = and i32 %shl, 16
1014 define <2 x i32> @test54_splat_vec(<2 x i32> %x) {
1015 ; CHECK-LABEL: @test54_splat_vec(
1016 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[X:%.*]], <i32 3, i32 3>
1017 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[TMP1]], <i32 16, i32 16>
1018 ; CHECK-NEXT: ret <2 x i32> [[AND]]
1020 %shr2 = lshr <2 x i32> %x, <i32 1, i32 1>
1021 %shl = shl <2 x i32> %shr2, <i32 4, i32 4>
1022 %and = and <2 x i32> %shl, <i32 16, i32 16>
1026 define i32 @test55(i32 %x) {
1027 ; CHECK-LABEL: @test55(
1028 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1029 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 8
1030 ; CHECK-NEXT: ret i32 [[OR]]
1032 %shr2 = lshr i32 %x, 1
1033 %shl = shl i32 %shr2, 4
1034 %or = or i32 %shl, 8
1038 define i32 @test56(i32 %x) {
1039 ; CHECK-LABEL: @test56(
1040 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1041 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1042 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 7
1043 ; CHECK-NEXT: ret i32 [[OR]]
1045 %shr2 = lshr i32 %x, 1
1046 %shl = shl i32 %shr2, 4
1047 %or = or i32 %shl, 7
1051 define i32 @test57(i32 %x) {
1052 ; CHECK-LABEL: @test57(
1053 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1054 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1055 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 7
1056 ; CHECK-NEXT: ret i32 [[OR]]
1058 %shr = ashr i32 %x, 1
1059 %shl = shl i32 %shr, 4
1060 %or = or i32 %shl, 7
1064 define i32 @test58(i32 %x) {
1065 ; CHECK-LABEL: @test58(
1066 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1067 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 1
1068 ; CHECK-NEXT: ret i32 [[OR]]
1070 %shr = ashr i32 %x, 4
1071 %shl = shl i32 %shr, 1
1072 %or = or i32 %shl, 1
1076 define <2 x i32> @test58_splat_vec(<2 x i32> %x) {
1077 ; CHECK-LABEL: @test58_splat_vec(
1078 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> [[X:%.*]], <i32 3, i32 3>
1079 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[TMP1]], <i32 1, i32 1>
1080 ; CHECK-NEXT: ret <2 x i32> [[OR]]
1082 %shr = ashr <2 x i32> %x, <i32 4, i32 4>
1083 %shl = shl <2 x i32> %shr, <i32 1, i32 1>
1084 %or = or <2 x i32> %shl, <i32 1, i32 1>
1088 define i32 @test59(i32 %x) {
1089 ; CHECK-LABEL: @test59(
1090 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1091 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -4
1092 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 2
1093 ; CHECK-NEXT: ret i32 [[OR]]
1095 %shr = ashr i32 %x, 4
1096 %shl = shl i32 %shr, 1
1097 %or = or i32 %shl, 2
1101 ; propagate "exact" trait
1102 define i32 @test60(i32 %x) {
1103 ; CHECK-LABEL: @test60(
1104 ; CHECK-NEXT: [[SHL:%.*]] = ashr exact i32 [[X:%.*]], 3
1105 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], 1
1106 ; CHECK-NEXT: ret i32 [[OR]]
1108 %shr = ashr exact i32 %x, 4
1109 %shl = shl i32 %shr, 1
1110 %or = or i32 %shl, 1
1115 define void @test61(i128 %arg, i1 %c1, i1 %c2, i1 %c3, i1 %c4) {
1116 ; CHECK-LABEL: @test61(
1118 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[BB1:%.*]], label [[BB12:%.*]]
1120 ; CHECK-NEXT: br label [[BB2:%.*]]
1122 ; CHECK-NEXT: br i1 [[C2:%.*]], label [[BB3:%.*]], label [[BB7:%.*]]
1124 ; CHECK-NEXT: br label [[BB8:%.*]]
1126 ; CHECK-NEXT: br i1 [[C3:%.*]], label [[BB8]], label [[BB2]]
1128 ; CHECK-NEXT: br i1 undef, label [[BB11:%.*]], label [[BB12]]
1130 ; CHECK-NEXT: br i1 [[C4:%.*]], label [[BB1]], label [[BB12]]
1132 ; CHECK-NEXT: ret void
1135 br i1 %c1, label %bb1, label %bb12
1137 bb1: ; preds = %bb11, %bb
1140 bb2: ; preds = %bb7, %bb1
1141 br i1 %c2, label %bb3, label %bb7
1144 %i = lshr i128 %arg, 36893488147419103232
1145 %i4 = shl i128 %i, 0
1146 %i5 = or i128 %i4, 0
1147 %i6 = trunc i128 %i5 to i16
1151 br i1 %c3, label %bb8, label %bb2
1153 bb8: ; preds = %bb7, %bb3
1154 %i9 = phi i16 [ %i6, %bb3 ], [ poison, %bb7 ]
1155 %i10 = icmp eq i16 %i9, 0
1156 br i1 %i10, label %bb11, label %bb12
1158 bb11: ; preds = %bb8
1159 br i1 %c4, label %bb1, label %bb12
1161 bb12: ; preds = %bb11, %bb8, %bb
1165 define i32 @test62(i32 %a) {
1166 ; CHECK-LABEL: @test62(
1167 ; CHECK-NEXT: ret i32 poison
1169 %b = ashr i32 %a, 32 ; shift all bits out
1173 define <4 x i32> @test62_splat_vector(<4 x i32> %a) {
1174 ; CHECK-LABEL: @test62_splat_vector(
1175 ; CHECK-NEXT: ret <4 x i32> poison
1177 %b = ashr <4 x i32> %a, <i32 32, i32 32, i32 32, i32 32> ; shift all bits out
1181 define <4 x i32> @test62_non_splat_vector(<4 x i32> %a) {
1182 ; CHECK-LABEL: @test62_non_splat_vector(
1183 ; CHECK-NEXT: [[B:%.*]] = ashr <4 x i32> [[A:%.*]], <i32 32, i32 0, i32 1, i32 2>
1184 ; CHECK-NEXT: ret <4 x i32> [[B]]
1186 %b = ashr <4 x i32> %a, <i32 32, i32 0, i32 1, i32 2> ; shift all bits out
1190 define <2 x i65> @test_63(<2 x i64> %t) {
1191 ; CHECK-LABEL: @test_63(
1192 ; CHECK-NEXT: [[A:%.*]] = zext <2 x i64> [[T:%.*]] to <2 x i65>
1193 ; CHECK-NEXT: [[SEXT:%.*]] = shl <2 x i65> [[A]], <i65 33, i65 33>
1194 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i65> [[SEXT]], <i65 33, i65 33>
1195 ; CHECK-NEXT: ret <2 x i65> [[B]]
1197 %a = zext <2 x i64> %t to <2 x i65>
1198 %sext = shl <2 x i65> %a, <i65 33, i65 33>
1199 %b = ashr <2 x i65> %sext, <i65 33, i65 33>
1203 define i32 @test_shl_zext_bool(i1 %t) {
1204 ; CHECK-LABEL: @test_shl_zext_bool(
1205 ; CHECK-NEXT: [[SHL:%.*]] = select i1 [[T:%.*]], i32 4, i32 0
1206 ; CHECK-NEXT: ret i32 [[SHL]]
1208 %ext = zext i1 %t to i32
1209 %shl = shl i32 %ext, 2
1213 define <2 x i32> @test_shl_zext_bool_splat(<2 x i1> %t) {
1214 ; CHECK-LABEL: @test_shl_zext_bool_splat(
1215 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 8, i32 8>, <2 x i32> zeroinitializer
1216 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1218 %ext = zext <2 x i1> %t to <2 x i32>
1219 %shl = shl <2 x i32> %ext, <i32 3, i32 3>
1223 define <2 x i32> @test_shl_zext_bool_vec(<2 x i1> %t) {
1224 ; CHECK-LABEL: @test_shl_zext_bool_vec(
1225 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 4, i32 8>, <2 x i32> zeroinitializer
1226 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1228 %ext = zext <2 x i1> %t to <2 x i32>
1229 %shl = shl <2 x i32> %ext, <i32 2, i32 3>
1233 define i32 @test_shl_zext_bool_not_constant(i1 %cmp, i32 %shamt) {
1234 ; CHECK-LABEL: @test_shl_zext_bool_not_constant(
1235 ; CHECK-NEXT: [[CONV3:%.*]] = zext i1 [[CMP:%.*]] to i32
1236 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[CONV3]], [[SHAMT:%.*]]
1237 ; CHECK-NEXT: ret i32 [[SHL]]
1239 %conv3 = zext i1 %cmp to i32
1240 %shl = shl i32 %conv3, %shamt
1244 define i64 @shl_zext(i32 %t) {
1245 ; CHECK-LABEL: @shl_zext(
1246 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[T:%.*]], 8
1247 ; CHECK-NEXT: [[SHL:%.*]] = zext i32 [[TMP1]] to i64
1248 ; CHECK-NEXT: ret i64 [[SHL]]
1250 %and = and i32 %t, 16777215
1251 %ext = zext i32 %and to i64
1252 %shl = shl i64 %ext, 8
1256 define i64 @shl_zext_extra_use(i32 %t) {
1257 ; CHECK-LABEL: @shl_zext_extra_use(
1258 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[T:%.*]], 16777215
1259 ; CHECK-NEXT: [[EXT:%.*]] = zext nneg i32 [[AND]] to i64
1260 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1261 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 8
1262 ; CHECK-NEXT: ret i64 [[SHL]]
1264 %and = and i32 %t, 16777215
1265 %ext = zext i32 %and to i64
1266 call void @use(i64 %ext)
1267 %shl = shl i64 %ext, 8
1271 define <2 x i64> @shl_zext_splat_vec(<2 x i32> %t) {
1272 ; CHECK-LABEL: @shl_zext_splat_vec(
1273 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[T:%.*]], <i32 8, i32 8>
1274 ; CHECK-NEXT: [[SHL:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
1275 ; CHECK-NEXT: ret <2 x i64> [[SHL]]
1277 %and = and <2 x i32> %t, <i32 16777215, i32 16777215>
1278 %ext = zext <2 x i32> %and to <2 x i64>
1279 %shl = shl <2 x i64> %ext, <i64 8, i64 8>
1283 define i64 @shl_zext_mul(i32 %t) {
1284 ; CHECK-LABEL: @shl_zext_mul(
1285 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1286 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1287 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1288 ; CHECK-NEXT: ret i64 [[SHL]]
1290 %mul = mul i32 %t, 16777215
1291 %ext = zext i32 %mul to i64
1292 %shl = shl i64 %ext, 32
1296 define <3 x i17> @shl_zext_mul_splat(<3 x i5> %t) {
1297 ; CHECK-LABEL: @shl_zext_mul_splat(
1298 ; CHECK-NEXT: [[MUL:%.*]] = mul <3 x i5> [[T:%.*]], <i5 13, i5 13, i5 13>
1299 ; CHECK-NEXT: [[EXT:%.*]] = zext <3 x i5> [[MUL]] to <3 x i17>
1300 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <3 x i17> [[EXT]], <i17 12, i17 12, i17 12>
1301 ; CHECK-NEXT: ret <3 x i17> [[SHL]]
1303 %mul = mul <3 x i5> %t, <i5 13, i5 13, i5 13>
1304 %ext = zext <3 x i5> %mul to <3 x i17>
1305 %shl = shl <3 x i17> %ext, <i17 12, i17 12, i17 12>
1309 define i64 @shl_zext_mul_low_shift_amount(i32 %t) {
1310 ; CHECK-LABEL: @shl_zext_mul_low_shift_amount(
1311 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1312 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1313 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 31
1314 ; CHECK-NEXT: ret i64 [[SHL]]
1316 %mul = mul i32 %t, 16777215
1317 %ext = zext i32 %mul to i64
1318 %shl = shl i64 %ext, 31
1322 define i64 @shl_zext_mul_extra_use1(i32 %t) {
1323 ; CHECK-LABEL: @shl_zext_mul_extra_use1(
1324 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1325 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1326 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1327 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1328 ; CHECK-NEXT: ret i64 [[SHL]]
1330 %mul = mul i32 %t, 16777215
1331 %ext = zext i32 %mul to i64
1332 call void @use(i64 %ext)
1333 %shl = shl i64 %ext, 32
1337 define i64 @shl_zext_mul_extra_use2(i32 %t) {
1338 ; CHECK-LABEL: @shl_zext_mul_extra_use2(
1339 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1340 ; CHECK-NEXT: call void @use_i32(i32 [[MUL]])
1341 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1342 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1343 ; CHECK-NEXT: ret i64 [[SHL]]
1345 %mul = mul i32 %t, 16777215
1346 call void @use_i32(i32 %mul)
1347 %ext = zext i32 %mul to i64
1348 %shl = shl i64 %ext, 32
1352 define <2 x i8> @ashr_demanded_bits_splat(<2 x i8> %x) {
1353 ; CHECK-LABEL: @ashr_demanded_bits_splat(
1354 ; CHECK-NEXT: [[SHR:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
1355 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1357 %and = and <2 x i8> %x, <i8 128, i8 128>
1358 %shr = ashr <2 x i8> %and, <i8 7, i8 7>
1362 define <vscale x 8 x i8> @ashr_demanded_bits_splat2(<vscale x 8 x i8> %x) {
1363 ; CHECK-LABEL: @ashr_demanded_bits_splat2(
1364 ; CHECK-NEXT: [[SHR:%.*]] = ashr <vscale x 8 x i8> [[X:%.*]], shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 7, i32 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1365 ; CHECK-NEXT: ret <vscale x 8 x i8> [[SHR]]
1367 %and = and <vscale x 8 x i8> %x, shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 128, i32 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1368 %shr = ashr <vscale x 8 x i8> %and, shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 7, i32 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1369 ret <vscale x 8 x i8> %shr
1372 define <2 x i8> @lshr_demanded_bits_splat(<2 x i8> %x) {
1373 ; CHECK-LABEL: @lshr_demanded_bits_splat(
1374 ; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i8> [[X:%.*]], <i8 7, i8 7>
1375 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1377 %and = and <2 x i8> %x, <i8 128, i8 128>
1378 %shr = lshr <2 x i8> %and, <i8 7, i8 7>
1382 define <vscale x 8 x i8> @lshr_demanded_bits_splat2(<vscale x 8 x i8> %x) {
1383 ; CHECK-LABEL: @lshr_demanded_bits_splat2(
1384 ; CHECK-NEXT: [[SHR:%.*]] = lshr <vscale x 8 x i8> [[X:%.*]], shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 7, i32 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1385 ; CHECK-NEXT: ret <vscale x 8 x i8> [[SHR]]
1387 %and = and <vscale x 8 x i8> %x, shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 128, i32 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1388 %shr = lshr <vscale x 8 x i8> %and, shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 7, i32 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1389 ret <vscale x 8 x i8> %shr
1392 ; Make sure known bits works correctly with non power of 2 bit widths.
1393 define i7 @test65(i7 %a, i7 %b) {
1394 ; CHECK-LABEL: @test65(
1395 ; CHECK-NEXT: ret i7 0
1397 %shiftamt = and i7 %b, 6 ; this ensures the shift amount is even and less than the bit width.
1398 %x = lshr i7 42, %shiftamt ; 42 has a zero in every even numbered bit and a one in every odd bit.
1399 %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.
1403 define i32 @shl_select_add_true(i32 %x, i1 %cond) {
1404 ; CHECK-LABEL: @shl_select_add_true(
1405 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1406 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1407 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1408 ; CHECK-NEXT: ret i32 [[TMP3]]
1411 %2 = select i1 %cond, i32 %1, i32 %x
1416 define i32 @shl_select_add_false(i32 %x, i1 %cond) {
1417 ; CHECK-LABEL: @shl_select_add_false(
1418 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1419 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1420 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1421 ; CHECK-NEXT: ret i32 [[TMP3]]
1424 %2 = select i1 %cond, i32 %x, i32 %1
1429 define i32 @shl_select_and_true(i32 %x, i1 %cond) {
1430 ; CHECK-LABEL: @shl_select_and_true(
1431 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1432 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1433 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1434 ; CHECK-NEXT: ret i32 [[TMP3]]
1437 %2 = select i1 %cond, i32 %1, i32 %x
1442 define i32 @shl_select_and_false(i32 %x, i1 %cond) {
1443 ; CHECK-LABEL: @shl_select_and_false(
1444 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1445 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1446 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1447 ; CHECK-NEXT: ret i32 [[TMP3]]
1450 %2 = select i1 %cond, i32 %x, i32 %1
1455 define i32 @lshr_select_and_true(i32 %x, i1 %cond) {
1456 ; CHECK-LABEL: @lshr_select_and_true(
1457 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1458 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1459 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1460 ; CHECK-NEXT: ret i32 [[TMP3]]
1463 %2 = select i1 %cond, i32 %1, i32 %x
1468 define i32 @lshr_select_and_false(i32 %x, i1 %cond) {
1469 ; CHECK-LABEL: @lshr_select_and_false(
1470 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1471 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1472 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1473 ; CHECK-NEXT: ret i32 [[TMP3]]
1476 %2 = select i1 %cond, i32 %x, i32 %1
1481 define i32 @ashr_select_and_true(i32 %x, i1 %cond) {
1482 ; CHECK-LABEL: @ashr_select_and_true(
1483 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1484 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1485 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1486 ; CHECK-NEXT: ret i32 [[TMP3]]
1488 %1 = and i32 %x, 2147483655
1489 %2 = select i1 %cond, i32 %1, i32 %x
1494 define i32 @ashr_select_and_false(i32 %x, i1 %cond) {
1495 ; CHECK-LABEL: @ashr_select_and_false(
1496 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1497 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1498 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1499 ; CHECK-NEXT: ret i32 [[TMP3]]
1501 %1 = and i32 %x, 2147483655
1502 %2 = select i1 %cond, i32 %x, i32 %1
1507 define i32 @shl_select_or_true(i32 %x, i1 %cond) {
1508 ; CHECK-LABEL: @shl_select_or_true(
1509 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1510 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1511 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1512 ; CHECK-NEXT: ret i32 [[TMP3]]
1515 %2 = select i1 %cond, i32 %1, i32 %x
1520 define i32 @shl_select_or_false(i32 %x, i1 %cond) {
1521 ; CHECK-LABEL: @shl_select_or_false(
1522 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1523 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1524 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1525 ; CHECK-NEXT: ret i32 [[TMP3]]
1528 %2 = select i1 %cond, i32 %x, i32 %1
1533 define i32 @lshr_select_or_true(i32 %x, i1 %cond) {
1534 ; CHECK-LABEL: @lshr_select_or_true(
1535 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1536 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1537 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1538 ; CHECK-NEXT: ret i32 [[TMP3]]
1541 %2 = select i1 %cond, i32 %1, i32 %x
1546 define i32 @lshr_select_or_false(i32 %x, i1 %cond) {
1547 ; CHECK-LABEL: @lshr_select_or_false(
1548 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1549 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1550 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1551 ; CHECK-NEXT: ret i32 [[TMP3]]
1554 %2 = select i1 %cond, i32 %x, i32 %1
1559 define i32 @ashr_select_or_true(i32 %x, i1 %cond) {
1560 ; CHECK-LABEL: @ashr_select_or_true(
1561 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1562 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1563 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1564 ; CHECK-NEXT: ret i32 [[TMP3]]
1567 %2 = select i1 %cond, i32 %1, i32 %x
1572 define i32 @ashr_select_or_false(i32 %x, i1 %cond) {
1573 ; CHECK-LABEL: @ashr_select_or_false(
1574 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1575 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1576 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1577 ; CHECK-NEXT: ret i32 [[TMP3]]
1580 %2 = select i1 %cond, i32 %x, i32 %1
1585 define i32 @shl_select_xor_true(i32 %x, i1 %cond) {
1586 ; CHECK-LABEL: @shl_select_xor_true(
1587 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1588 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1589 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1590 ; CHECK-NEXT: ret i32 [[TMP3]]
1593 %2 = select i1 %cond, i32 %1, i32 %x
1598 define i32 @shl_select_xor_false(i32 %x, i1 %cond) {
1599 ; CHECK-LABEL: @shl_select_xor_false(
1600 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1601 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1602 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1603 ; CHECK-NEXT: ret i32 [[TMP3]]
1606 %2 = select i1 %cond, i32 %x, i32 %1
1611 define i32 @lshr_select_xor_true(i32 %x, i1 %cond) {
1612 ; CHECK-LABEL: @lshr_select_xor_true(
1613 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1614 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1615 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1616 ; CHECK-NEXT: ret i32 [[TMP3]]
1619 %2 = select i1 %cond, i32 %1, i32 %x
1624 define i32 @lshr_select_xor_false(i32 %x, i1 %cond) {
1625 ; CHECK-LABEL: @lshr_select_xor_false(
1626 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1627 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1628 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1629 ; CHECK-NEXT: ret i32 [[TMP3]]
1632 %2 = select i1 %cond, i32 %x, i32 %1
1637 define i32 @ashr_select_xor_true(i32 %x, i1 %cond) {
1638 ; CHECK-LABEL: @ashr_select_xor_true(
1639 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1640 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1641 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1642 ; CHECK-NEXT: ret i32 [[TMP3]]
1645 %2 = select i1 %cond, i32 %1, i32 %x
1650 define i32 @ashr_select_xor_false(i32 %x, i1 %cond) {
1651 ; CHECK-LABEL: @ashr_select_xor_false(
1652 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1653 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1654 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1655 ; CHECK-NEXT: ret i32 [[TMP3]]
1658 %2 = select i1 %cond, i32 %x, i32 %1
1664 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4871
1665 define i177 @lshr_out_of_range(i177 %Y, ptr %A2, ptr %ptr) {
1666 ; CHECK-LABEL: @lshr_out_of_range(
1667 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i177 [[Y:%.*]], -1
1668 ; CHECK-NEXT: [[B4:%.*]] = sext i1 [[TMP1]] to i177
1669 ; CHECK-NEXT: [[C8:%.*]] = icmp ult i177 [[B4]], [[Y]]
1670 ; CHECK-NEXT: [[TMP2:%.*]] = sext i1 [[C8]] to i64
1671 ; CHECK-NEXT: [[G18:%.*]] = getelementptr ptr, ptr [[A2:%.*]], i64 [[TMP2]]
1672 ; CHECK-NEXT: store ptr [[G18]], ptr [[PTR:%.*]], align 8
1673 ; CHECK-NEXT: ret i177 0
1675 %B5 = udiv i177 %Y, -1
1676 %B4 = add i177 %B5, -1
1677 %B2 = add i177 %B4, -1
1678 %B6 = mul i177 %B5, %B2
1679 %B3 = add i177 %B2, %B2
1680 %B10 = sub i177 %B5, %B3
1681 %B12 = lshr i177 %Y, %B6
1682 %C8 = icmp ugt i177 %B12, %B4
1683 %G18 = getelementptr ptr, ptr %A2, i1 %C8
1684 store ptr %G18, ptr %ptr
1685 %B1 = udiv i177 %B10, %B6
1690 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26716
1691 define i177 @lshr_out_of_range2(i177 %Y, ptr %A2, ptr %ptr) {
1692 ; CHECK-LABEL: @lshr_out_of_range2(
1693 ; CHECK-NEXT: [[C8:%.*]] = icmp ne i177 [[Y:%.*]], 0
1694 ; CHECK-NEXT: [[TMP1:%.*]] = sext i1 [[C8]] to i64
1695 ; CHECK-NEXT: [[G18:%.*]] = getelementptr ptr, ptr [[A2:%.*]], i64 [[TMP1]]
1696 ; CHECK-NEXT: store ptr [[G18]], ptr [[PTR:%.*]], align 8
1697 ; CHECK-NEXT: ret i177 0
1699 %B5 = udiv i177 %Y, -1
1700 %B = sdiv i177 %B5, -1
1701 %B4 = add i177 %B5, %B
1702 %B2 = add i177 %B4, -1
1703 %B6 = mul i177 %B5, %B2
1704 %B12 = lshr i177 %Y, %B6
1705 %C8 = icmp ugt i177 %B12, %B4
1706 %G18 = getelementptr ptr, ptr %A2, i1 %C8
1707 store ptr %G18, ptr %ptr, align 8
1708 %B1 = udiv i177 %B5, %B6
1713 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5032
1714 define void @ashr_out_of_range(ptr %A) {
1715 ; CHECK-LABEL: @ashr_out_of_range(
1716 ; CHECK-NEXT: [[L:%.*]] = load i177, ptr [[A:%.*]], align 4
1717 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i177 [[L]], -1
1718 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 -1, i64 -2
1719 ; CHECK-NEXT: [[G11:%.*]] = getelementptr i177, ptr [[A]], i64 [[TMP2]]
1720 ; CHECK-NEXT: [[L7:%.*]] = load i177, ptr [[G11]], align 4
1721 ; CHECK-NEXT: [[L7_FROZEN:%.*]] = freeze i177 [[L7]]
1722 ; CHECK-NEXT: [[C171:%.*]] = icmp slt i177 [[L7_FROZEN]], 0
1723 ; CHECK-NEXT: [[C17:%.*]] = select i1 [[TMP1]], i1 [[C171]], i1 false
1724 ; CHECK-NEXT: [[TMP3:%.*]] = sext i1 [[C17]] to i64
1725 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, ptr [[G11]], i64 [[TMP3]]
1726 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i177 [[L7_FROZEN]], -1
1727 ; CHECK-NEXT: [[B28:%.*]] = select i1 [[TMP4]], i177 0, i177 [[L7_FROZEN]]
1728 ; CHECK-NEXT: store i177 [[B28]], ptr [[G62]], align 4
1729 ; CHECK-NEXT: ret void
1731 %L = load i177, ptr %A
1732 %B5 = udiv i177 %L, -1
1733 %B4 = add i177 %B5, -1
1734 %B2 = add i177 %B4, -1
1735 %G11 = getelementptr i177, ptr %A, i177 %B2
1736 %L7 = load i177, ptr %G11
1737 %B6 = mul i177 %B5, %B2
1738 %B24 = ashr i177 %L7, %B6
1739 %B36 = and i177 %L7, %B4
1740 %C17 = icmp sgt i177 %B36, %B24
1741 %G62 = getelementptr i177, ptr %G11, i1 %C17
1742 %B28 = urem i177 %B24, %B6
1743 store i177 %B28, ptr %G62
1748 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26135
1749 define void @ashr_out_of_range_1(ptr %A) {
1750 ; CHECK-LABEL: @ashr_out_of_range_1(
1751 ; CHECK-NEXT: [[L:%.*]] = load i177, ptr [[A:%.*]], align 4
1752 ; CHECK-NEXT: [[L_FROZEN:%.*]] = freeze i177 [[L]]
1753 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i177 [[L_FROZEN]], -1
1754 ; CHECK-NEXT: [[B:%.*]] = select i1 [[TMP1]], i177 0, i177 [[L_FROZEN]]
1755 ; CHECK-NEXT: [[TMP2:%.*]] = trunc i177 [[B]] to i64
1756 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i177, ptr [[A]], i64 [[TMP2]]
1757 ; CHECK-NEXT: [[G11:%.*]] = getelementptr i177, ptr [[TMP3]], i64 -1
1758 ; CHECK-NEXT: [[C17:%.*]] = icmp sgt i177 [[B]], [[L_FROZEN]]
1759 ; CHECK-NEXT: [[TMP4:%.*]] = sext i1 [[C17]] to i64
1760 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, ptr [[G11]], i64 [[TMP4]]
1761 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i177 [[L_FROZEN]], -1
1762 ; CHECK-NEXT: [[B28:%.*]] = select i1 [[TMP5]], i177 0, i177 [[L_FROZEN]]
1763 ; CHECK-NEXT: store i177 [[B28]], ptr [[G62]], align 4
1764 ; CHECK-NEXT: ret void
1766 %L = load i177, ptr %A, align 4
1767 %B5 = udiv i177 %L, -1
1768 %B4 = add i177 %B5, -1
1769 %B = and i177 %B4, %L
1770 %B2 = add i177 %B, -1
1771 %G11 = getelementptr i177, ptr %A, i177 %B2
1772 %B6 = mul i177 %B5, %B2
1773 %B24 = ashr i177 %L, %B6
1774 %C17 = icmp sgt i177 %B, %B24
1775 %G62 = getelementptr i177, ptr %G11, i1 %C17
1776 %B28 = urem i177 %B24, %B6
1777 store i177 %B28, ptr %G62, align 4
1782 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38078
1783 define void @ossfuzz_38078(i32 %arg, i32 %arg1, ptr %ptr, ptr %ptr2, ptr %ptr3, ptr %ptr4, ptr %ptr5, ptr %ptr6, ptr %ptr7) {
1784 ; CHECK-LABEL: @ossfuzz_38078(
1786 ; CHECK-NEXT: [[G1:%.*]] = getelementptr i32, ptr [[PTR:%.*]], i64 -1
1787 ; CHECK-NEXT: [[I2:%.*]] = sub i32 0, [[ARG1:%.*]]
1788 ; CHECK-NEXT: [[I5:%.*]] = icmp eq i32 [[I2]], [[ARG:%.*]]
1789 ; CHECK-NEXT: call void @llvm.assume(i1 [[I5]])
1790 ; CHECK-NEXT: store volatile i32 2147483647, ptr [[G1]], align 4
1791 ; CHECK-NEXT: br label [[BB:%.*]]
1793 ; CHECK-NEXT: unreachable
1797 %B24 = urem i32 %i, -2147483648
1798 %B21 = or i32 %i, %i
1799 %i2 = add nsw i32 %arg, %arg1
1800 %B7 = or i32 %i, %i2
1801 %B8 = and i32 %i, %i2
1802 %B12 = sdiv i32 %i2, %B7
1803 %B3 = add i32 %i2, %B24
1804 %B5 = and i32 %i, %B3
1805 %B18 = and i32 %i, %B8
1806 %i3 = xor i32 %i2, %B3
1807 %C1 = icmp ne i32 %B8, %B5
1808 %i4 = lshr i32 %B5, %i3
1809 %B29 = shl nuw i32 %B8, %i3
1810 %B2 = lshr i32 %B12, %i2
1811 %B16 = add i32 %B2, %i3
1812 %B = sdiv i32 %B29, %B5
1813 %B15 = sub i32 %i2, %B5
1814 %B22 = or i32 %B21, %B29
1815 %B23 = mul i32 %B15, %B
1816 %C2 = icmp sge i1 %C1, false
1817 %C7 = icmp sle i32 %i3, %B16
1818 %B20 = xor i32 %B21, %B22
1819 %G1 = getelementptr i32, ptr %ptr, i32 %B22
1821 %B26 = ashr i32 %B29, 0
1822 %B4 = add i32 0, %B5
1823 %B27 = srem i32 %B12, %B21
1824 %i5 = icmp eq i32 %B20, %B18
1825 %C11 = icmp ugt i32 %i4, %B4
1826 call void @llvm.assume(i1 %i5)
1827 store volatile i32 %B4, ptr %G1, align 4
1828 %B11 = or i32 0, %B23
1832 store i1 %C7, ptr %ptr2, align 1
1833 store i32 %B11, ptr %ptr3, align 4
1834 store i1 %C11, ptr %ptr4, align 1
1835 store i32 %B1, ptr %ptr5, align 4
1836 store i32 %B27, ptr %ptr6, align 4
1837 %C = icmp ne i32 %B26, 0
1838 %B17 = or i1 %C, %C2
1839 store i1 %B17, ptr %ptr7, align 1
1842 declare void @llvm.assume(i1 noundef)
1844 define i8 @lshr_mask_demand(i8 %x) {
1845 ; CHECK-LABEL: @lshr_mask_demand(
1846 ; CHECK-NEXT: [[S:%.*]] = lshr i8 63, [[X:%.*]]
1847 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 32
1848 ; CHECK-NEXT: ret i8 [[R]]
1850 %s = lshr i8 63, %x ; 0b00111111
1851 %r = and i8 %s, 224 ; 0b11100000
1855 define i8 @shl_mask_demand(i8 %x) {
1856 ; CHECK-LABEL: @shl_mask_demand(
1857 ; CHECK-NEXT: [[S:%.*]] = shl i8 12, [[X:%.*]]
1858 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 4
1859 ; CHECK-NEXT: ret i8 [[R]]
1861 %s = shl i8 12, %x ; 0b00001100
1862 %r = and i8 %s, 7 ; 0b00000111
1866 define i64 @lshr_mul_negpow2(i64 %x) {
1867 ; CHECK-LABEL: @lshr_mul_negpow2(
1868 ; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[X:%.*]]
1869 ; CHECK-NEXT: [[A:%.*]] = and i64 [[TMP1]], 4294967295
1870 ; CHECK-NEXT: ret i64 [[A]]
1872 %a = mul i64 %x, -4294967296
1873 %b = lshr i64 %a, 32
1877 define i64 @lshr_mul_negpow2_2(i64 %x) {
1878 ; CHECK-LABEL: @lshr_mul_negpow2_2(
1879 ; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[X:%.*]]
1880 ; CHECK-NEXT: [[A:%.*]] = and i64 [[TMP1]], 281474976710655
1881 ; CHECK-NEXT: ret i64 [[A]]
1883 %a = mul i64 %x, -65536
1884 %b = lshr i64 %a, 16
1888 define <2 x i32> @lshr_mul_negpow2_3(<2 x i32> %x) {
1889 ; CHECK-LABEL: @lshr_mul_negpow2_3(
1890 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> zeroinitializer, [[X:%.*]]
1891 ; CHECK-NEXT: [[A:%.*]] = and <2 x i32> [[TMP1]], <i32 255, i32 255>
1892 ; CHECK-NEXT: ret <2 x i32> [[A]]
1894 %a = mul <2 x i32> %x, <i32 -16777216, i32 -16777216>
1895 %b = lshr <2 x i32> %a, <i32 24, i32 24>
1899 define i32 @lshr_mul_negpow2_4(i32 %x) {
1900 ; CHECK-LABEL: @lshr_mul_negpow2_4(
1901 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
1902 ; CHECK-NEXT: [[A:%.*]] = and i32 [[TMP1]], 65535
1903 ; CHECK-NEXT: [[B:%.*]] = xor i32 [[A]], 1
1904 ; CHECK-NEXT: ret i32 [[B]]
1906 %a = mul i32 %x, -65536
1907 %b = xor i32 %a, 65536
1908 %c = lshr i32 %b, 16
1912 define <2 x i32> @lshr_mul_negpow2_5(<2 x i32> %x) {
1913 ; CHECK-LABEL: @lshr_mul_negpow2_5(
1914 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> zeroinitializer, [[X:%.*]]
1915 ; CHECK-NEXT: [[A:%.*]] = and <2 x i32> [[TMP1]], <i32 65527, i32 65527>
1916 ; CHECK-NEXT: [[B:%.*]] = or disjoint <2 x i32> [[A]], <i32 8, i32 8>
1917 ; CHECK-NEXT: ret <2 x i32> [[B]]
1919 %a = mul <2 x i32> %x, <i32 -65536, i32 -65536>
1920 %b = or <2 x i32> %a, <i32 524288, i32 524288>
1921 %c = lshr <2 x i32> %b, <i32 16, i32 16>
1925 define i64 @lshr_mul_negpow2_extra_use(i64 %x) {
1926 ; CHECK-LABEL: @lshr_mul_negpow2_extra_use(
1927 ; CHECK-NEXT: [[A:%.*]] = mul i64 [[X:%.*]], -4294967296
1928 ; CHECK-NEXT: [[B:%.*]] = lshr exact i64 [[A]], 32
1929 ; CHECK-NEXT: call void @use(i64 [[A]])
1930 ; CHECK-NEXT: ret i64 [[B]]
1932 %a = mul i64 %x, -4294967296
1933 %b = lshr i64 %a, 32
1934 call void @use(i64 %a)
1938 define i8 @ashr_sdiv_pos(i8 %x) {
1939 ; CHECK-LABEL: @ashr_sdiv_pos(
1940 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[X:%.*]], -41
1941 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[TMP1]] to i8
1942 ; CHECK-NEXT: ret i8 [[R]]
1949 define <2 x i8> @ashr_sdiv_neg_splat_vec(<2 x i8> %x) {
1950 ; CHECK-LABEL: @ashr_sdiv_neg_splat_vec(
1951 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 41, i8 41>
1952 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
1953 ; CHECK-NEXT: ret <2 x i8> [[R]]
1955 %d = sdiv <2 x i8> %x, <i8 -42, i8 -42>
1956 %r = ashr <2 x i8> %d, <i8 7, i8 7>
1960 define <2 x i8> @ashr_sdiv_neg_splat_vec_poison(<2 x i8> %x) {
1961 ; CHECK-LABEL: @ashr_sdiv_neg_splat_vec_poison(
1962 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 127, i8 127>
1963 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
1964 ; CHECK-NEXT: ret <2 x i8> [[R]]
1966 %d = sdiv <2 x i8> %x, <i8 -127, i8 -127>
1967 %r = ashr <2 x i8> %d, <i8 7, i8 poison>
1971 define i8 @lshr_sdiv_pos(i8 %x) {
1972 ; CHECK-LABEL: @lshr_sdiv_pos(
1973 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[X:%.*]], -11
1974 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[TMP1]] to i8
1975 ; CHECK-NEXT: ret i8 [[R]]
1982 define i18 @lshr_sdiv_neg(i18 %x) {
1983 ; CHECK-LABEL: @lshr_sdiv_neg(
1984 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i18 [[X:%.*]], 11
1985 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[TMP1]] to i18
1986 ; CHECK-NEXT: ret i18 [[R]]
1988 %d = sdiv i18 %x, -12
1989 %r = lshr i18 %d, 17
1995 define i8 @ashr_sdiv_not_full_shift(i8 %x) {
1996 ; CHECK-LABEL: @ashr_sdiv_not_full_shift(
1997 ; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[X:%.*]], 42
1998 ; CHECK-NEXT: [[R:%.*]] = ashr i8 [[D]], 6
1999 ; CHECK-NEXT: ret i8 [[R]]
2008 define i32 @ashr_sdiv_extra_use(i32 %x) {
2009 ; CHECK-LABEL: @ashr_sdiv_extra_use(
2010 ; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 42
2011 ; CHECK-NEXT: call void @use_i32(i32 [[D]])
2012 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X]], -41
2013 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[TMP1]] to i32
2014 ; CHECK-NEXT: ret i32 [[R]]
2016 %d = sdiv i32 %x, 42
2017 call void @use_i32(i32 %d)
2018 %r = ashr i32 %d, 31
2022 define i32 @shl1_cttz(i32 %x) {
2023 ; CHECK-LABEL: @shl1_cttz(
2024 ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[X:%.*]]
2025 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[NEG]], [[X]]
2026 ; CHECK-NEXT: ret i32 [[SHL]]
2028 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
2029 %shl = shl i32 1, %tz
2033 define <2 x i8> @shl1_cttz_vec(<2 x i8> %x) {
2034 ; CHECK-LABEL: @shl1_cttz_vec(
2035 ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
2036 ; CHECK-NEXT: [[SHL:%.*]] = and <2 x i8> [[NEG]], [[X]]
2037 ; CHECK-NEXT: ret <2 x i8> [[SHL]]
2039 %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
2040 %shl = shl <2 x i8> <i8 1, i8 1>, %tz
2044 define <2 x i8> @shl1_cttz_vec_poison(<2 x i8> %x) {
2045 ; CHECK-LABEL: @shl1_cttz_vec_poison(
2046 ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
2047 ; CHECK-NEXT: [[SHL:%.*]] = and <2 x i8> [[NEG]], [[X]]
2048 ; CHECK-NEXT: ret <2 x i8> [[SHL]]
2050 %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
2051 %shl = shl <2 x i8> <i8 1, i8 poison>, %tz
2055 ; negative test - extra use
2057 define i32 @shl1_cttz_extra_use(i32 %x) {
2058 ; CHECK-LABEL: @shl1_cttz_extra_use(
2059 ; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false), !range [[RNG0:![0-9]+]]
2060 ; CHECK-NEXT: call void @use_i32(i32 [[TZ]])
2061 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[TZ]]
2062 ; CHECK-NEXT: ret i32 [[SHL]]
2064 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 false)
2065 call void @use_i32(i32 %tz)
2066 %shl = shl i32 1, %tz
2070 ; negative test - must be shift-left of 1
2072 define i32 @shl2_cttz(i32 %x) {
2073 ; CHECK-LABEL: @shl2_cttz(
2074 ; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true), !range [[RNG0]]
2075 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 2, [[TZ]]
2076 ; CHECK-NEXT: ret i32 [[SHL]]
2078 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
2079 %shl = shl i32 2, %tz
2083 ; shift (X, amt | bitwidth - 1) -> shift (X, bitwidth - 1)
2084 define i6 @shl_or7_eq_shl7(i6 %x, i6 %c) {
2085 ; CHECK-LABEL: @shl_or7_eq_shl7(
2086 ; CHECK-NEXT: [[Y:%.*]] = shl nsw i6 [[X:%.*]], 5
2087 ; CHECK-NEXT: ret i6 [[Y]]
2090 ;; nsw not needed for transform, just check that we propagate.
2091 %y = shl nsw i6 %x, %amt
2095 define <2 x i8> @lshr_vec_or7_eq_shl7(<2 x i8> %x, <2 x i8> %c) {
2096 ; CHECK-LABEL: @lshr_vec_or7_eq_shl7(
2097 ; CHECK-NEXT: [[Y:%.*]] = lshr exact <2 x i8> [[X:%.*]], <i8 7, i8 7>
2098 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2100 %amt = or <2 x i8> %c, <i8 7, i8 7>
2101 ;; exact not needed for transform, just check that we propagate.
2102 %y = lshr exact <2 x i8> %x, %amt
2106 define <2 x i8> @ashr_vec_or7_eq_ashr7(<2 x i8> %x, <2 x i8> %c) {
2107 ; CHECK-LABEL: @ashr_vec_or7_eq_ashr7(
2108 ; CHECK-NEXT: [[Y:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
2109 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2111 %amt = or <2 x i8> %c, <i8 7, i8 7>
2112 %y = ashr <2 x i8> %x, %amt
2116 ; Negative test not bitwidth - 1
2117 define <2 x i8> @ashr_vec_or6_fail(<2 x i8> %x, <2 x i8> %c) {
2118 ; CHECK-LABEL: @ashr_vec_or6_fail(
2119 ; CHECK-NEXT: [[AMT:%.*]] = or <2 x i8> [[C:%.*]], <i8 6, i8 6>
2120 ; CHECK-NEXT: [[Y:%.*]] = ashr <2 x i8> [[X:%.*]], [[AMT]]
2121 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2123 %amt = or <2 x i8> %c, <i8 6, i8 6>
2124 %y = ashr <2 x i8> %x, %amt
2128 define i16 @lshr_and_not_demanded(i8 %x) {
2129 ; CHECK-LABEL: @lshr_and_not_demanded(
2130 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[X:%.*]] to i16
2131 ; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[Y_EXT]], 1
2132 ; CHECK-NEXT: ret i16 [[SHR]]
2135 %y.ext = sext i8 %y to i16
2136 %shr = lshr i16 %y.ext, 1
2140 define i16 @lshr_exact_and_not_demanded(i8 %x) {
2141 ; CHECK-LABEL: @lshr_exact_and_not_demanded(
2142 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[X:%.*]] to i16
2143 ; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[Y_EXT]], 1
2144 ; CHECK-NEXT: ret i16 [[SHR]]
2147 %y.ext = sext i8 %y to i16
2148 %shr = lshr exact i16 %y.ext, 1
2152 define i16 @lshr_and_demanded(i8 %x) {
2153 ; CHECK-LABEL: @lshr_and_demanded(
2154 ; CHECK-NEXT: [[Y:%.*]] = and i8 [[X:%.*]], -4
2155 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[Y]] to i16
2156 ; CHECK-NEXT: [[SHR:%.*]] = lshr exact i16 [[Y_EXT]], 1
2157 ; CHECK-NEXT: ret i16 [[SHR]]
2160 %y.ext = sext i8 %y to i16
2161 %shr = lshr i16 %y.ext, 1
2165 define i16 @ashr_umax_not_demanded(i16 %x) {
2166 ; CHECK-LABEL: @ashr_umax_not_demanded(
2167 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[X:%.*]], 1
2168 ; CHECK-NEXT: ret i16 [[SHR]]
2170 %y = call i16 @llvm.umax.i16(i16 %x, i16 1)
2171 %shr = ashr i16 %y, 1
2175 define i16 @ashr_exact_umax_not_demanded(i16 %x) {
2176 ; CHECK-LABEL: @ashr_exact_umax_not_demanded(
2177 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[X:%.*]], 1
2178 ; CHECK-NEXT: ret i16 [[SHR]]
2180 %y = call i16 @llvm.umax.i16(i16 %x, i16 1)
2181 %shr = ashr exact i16 %y, 1
2185 define i16 @ashr_umax_demanded(i16 %x) {
2186 ; CHECK-LABEL: @ashr_umax_demanded(
2187 ; CHECK-NEXT: [[Y:%.*]] = call i16 @llvm.umax.i16(i16 [[X:%.*]], i16 2)
2188 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[Y]], 1
2189 ; CHECK-NEXT: ret i16 [[SHR]]
2191 %y = call i16 @llvm.umax.i16(i16 %x, i16 2)
2192 %shr = ashr i16 %y, 1
2196 define i128 @shift_zext_nneg(i8 %arg) {
2197 ; CHECK-LABEL: @shift_zext_nneg(
2198 ; CHECK-NEXT: [[EXT:%.*]] = zext nneg i8 [[ARG:%.*]] to i128
2199 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i128 1, [[EXT]]
2200 ; CHECK-NEXT: ret i128 [[SHL]]
2202 %ext = zext i8 %arg to i128
2203 %shl = shl i128 1, %ext
2207 define i129 @shift_zext_not_nneg(i8 %arg) {
2208 ; CHECK-LABEL: @shift_zext_not_nneg(
2209 ; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[ARG:%.*]] to i129
2210 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i129 1, [[EXT]]
2211 ; CHECK-NEXT: ret i129 [[SHL]]
2213 %ext = zext i8 %arg to i129
2214 %shl = shl i129 1, %ext
2218 declare i16 @llvm.umax.i16(i16, i16)