1 ; RUN: opt -S -instcombine < %s | FileCheck %s
3 define <4 x i32> @test_FoldShiftByConstant_CreateSHL(<4 x i32> %in) {
4 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL(
5 ; CHECK-NEXT: [[VSHL_N:%.*]] = mul <4 x i32> %in, <i32 0, i32 -32, i32 0, i32 -32>
6 ; CHECK-NEXT: ret <4 x i32> [[VSHL_N]]
8 %mul.i = mul <4 x i32> %in, <i32 0, i32 -1, i32 0, i32 -1>
9 %vshl_n = shl <4 x i32> %mul.i, <i32 5, i32 5, i32 5, i32 5>
13 define <8 x i16> @test_FoldShiftByConstant_CreateSHL2(<8 x i16> %in) {
14 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL2(
15 ; CHECK-NEXT: [[VSHL_N:%.*]] = mul <8 x i16> %in, <i16 0, i16 -32, i16 0, i16 -32, i16 0, i16 -32, i16 0, i16 -32>
16 ; CHECK-NEXT: ret <8 x i16> [[VSHL_N]]
18 %mul.i = mul <8 x i16> %in, <i16 0, i16 -1, i16 0, i16 -1, i16 0, i16 -1, i16 0, i16 -1>
19 %vshl_n = shl <8 x i16> %mul.i, <i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5>
23 define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) {
24 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateAnd(
25 ; CHECK-NEXT: [[VSRA_N2:%.*]] = mul <16 x i8> %in0, <i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33>
26 ; CHECK-NEXT: [[VSHL_N:%.*]] = and <16 x i8> [[VSRA_N2]], <i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32>
27 ; CHECK-NEXT: ret <16 x i8> [[VSHL_N]]
29 %vsra_n = ashr <16 x i8> %in0, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5>
30 %tmp = add <16 x i8> %in0, %vsra_n
31 %vshl_n = shl <16 x i8> %tmp, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5>
35 define i32 @bar(i32 %x, i32 %y) {
37 ; CHECK-NEXT: [[B1:%.*]] = shl i32 %y, 4
38 ; CHECK-NEXT: [[A2:%.*]] = add i32 [[B1]], %x
39 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A2]], -16
40 ; CHECK-NEXT: ret i32 [[C]]
48 define <2 x i32> @bar_v2i32(<2 x i32> %x, <2 x i32> %y) {
49 ; CHECK-LABEL: @bar_v2i32(
50 ; CHECK-NEXT: [[B1:%.*]] = shl <2 x i32> %y, <i32 5, i32 5>
51 ; CHECK-NEXT: [[A2:%.*]] = add <2 x i32> [[B1]], %x
52 ; CHECK-NEXT: [[C:%.*]] = and <2 x i32> [[A2]], <i32 -32, i32 -32>
53 ; CHECK-NEXT: ret <2 x i32> [[C]]
55 %a = lshr <2 x i32> %x, <i32 5, i32 5>
56 %b = add <2 x i32> %a, %y
57 %c = shl <2 x i32> %b, <i32 5, i32 5>
61 define i32 @foo(i32 %x, i32 %y) {
63 ; CHECK-NEXT: [[C1:%.*]] = shl i32 %y, 4
64 ; CHECK-NEXT: [[X_MASK:%.*]] = and i32 %x, 128
65 ; CHECK-NEXT: [[D:%.*]] = add i32 [[X_MASK]], [[C1]]
66 ; CHECK-NEXT: ret i32 [[D]]
75 define <2 x i32> @foo_v2i32(<2 x i32> %x, <2 x i32> %y) {
76 ; CHECK-LABEL: @foo_v2i32(
77 ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> %x, <i32 4, i32 4>
78 ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], <i32 8, i32 8>
79 ; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], %y
80 ; CHECK-NEXT: [[D:%.*]] = shl <2 x i32> [[C]], <i32 4, i32 4>
81 ; CHECK-NEXT: ret <2 x i32> [[D]]
83 %a = lshr <2 x i32> %x, <i32 4, i32 4>
84 %b = and <2 x i32> %a, <i32 8, i32 8>
85 %c = add <2 x i32> %b, %y
86 %d = shl <2 x i32> %c, <i32 4, i32 4>