1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 define <4 x i32> @test_FoldShiftByConstant_CreateSHL(<4 x i32> %in) {
5 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL(
6 ; CHECK-NEXT: [[VSHL_N:%.*]] = mul <4 x i32> [[IN:%.*]], <i32 0, i32 -32, i32 0, i32 -32>
7 ; CHECK-NEXT: ret <4 x i32> [[VSHL_N]]
9 %mul.i = mul <4 x i32> %in, <i32 0, i32 -1, i32 0, i32 -1>
10 %vshl_n = shl <4 x i32> %mul.i, <i32 5, i32 5, i32 5, i32 5>
14 define <8 x i16> @test_FoldShiftByConstant_CreateSHL2(<8 x i16> %in) {
15 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL2(
16 ; 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>
17 ; CHECK-NEXT: ret <8 x i16> [[VSHL_N]]
19 %mul.i = mul <8 x i16> %in, <i16 0, i16 -1, i16 0, i16 -1, i16 0, i16 -1, i16 0, i16 -1>
20 %vshl_n = shl <8 x i16> %mul.i, <i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5>
24 define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) {
25 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateAnd(
26 ; CHECK-NEXT: [[TMP1:%.*]] = 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>
27 ; CHECK-NEXT: [[VSHL_N:%.*]] = and <16 x i8> [[TMP1]], <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>
28 ; CHECK-NEXT: ret <16 x i8> [[VSHL_N]]
30 %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>
31 %tmp = add <16 x i8> %in0, %vsra_n
32 %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>
36 define i32 @lshr_add_shl(i32 %x, i32 %y) {
37 ; CHECK-LABEL: @lshr_add_shl(
38 ; CHECK-NEXT: [[B1:%.*]] = shl i32 [[Y:%.*]], 4
39 ; CHECK-NEXT: [[A2:%.*]] = add i32 [[B1]], [[X:%.*]]
40 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A2]], -16
41 ; CHECK-NEXT: ret i32 [[C]]
49 define <2 x i32> @lshr_add_shl_v2i32(<2 x i32> %x, <2 x i32> %y) {
50 ; CHECK-LABEL: @lshr_add_shl_v2i32(
51 ; CHECK-NEXT: [[B1:%.*]] = shl <2 x i32> [[Y:%.*]], <i32 5, i32 5>
52 ; CHECK-NEXT: [[A2:%.*]] = add <2 x i32> [[B1]], [[X:%.*]]
53 ; CHECK-NEXT: [[C:%.*]] = and <2 x i32> [[A2]], <i32 -32, i32 -32>
54 ; CHECK-NEXT: ret <2 x i32> [[C]]
56 %a = lshr <2 x i32> %x, <i32 5, i32 5>
57 %b = add <2 x i32> %a, %y
58 %c = shl <2 x i32> %b, <i32 5, i32 5>
62 define <2 x i32> @lshr_add_shl_v2i32_undef(<2 x i32> %x, <2 x i32> %y) {
63 ; CHECK-LABEL: @lshr_add_shl_v2i32_undef(
64 ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 undef>
65 ; CHECK-NEXT: [[B:%.*]] = add <2 x i32> [[A]], [[Y:%.*]]
66 ; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], <i32 undef, i32 5>
67 ; CHECK-NEXT: ret <2 x i32> [[C]]
69 %a = lshr <2 x i32> %x, <i32 5, i32 undef>
70 %b = add <2 x i32> %a, %y
71 %c = shl <2 x i32> %b, <i32 undef, i32 5>
75 define <2 x i32> @lshr_add_shl_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) {
76 ; CHECK-LABEL: @lshr_add_shl_v2i32_nonuniform(
77 ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 6>
78 ; CHECK-NEXT: [[B:%.*]] = add <2 x i32> [[A]], [[Y:%.*]]
79 ; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], <i32 5, i32 6>
80 ; CHECK-NEXT: ret <2 x i32> [[C]]
82 %a = lshr <2 x i32> %x, <i32 5, i32 6>
83 %b = add <2 x i32> %a, %y
84 %c = shl <2 x i32> %b, <i32 5, i32 6>
88 define i32 @lshr_add_and_shl(i32 %x, i32 %y) {
89 ; CHECK-LABEL: @lshr_add_and_shl(
90 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[Y:%.*]], 5
91 ; CHECK-NEXT: [[X_MASK:%.*]] = and i32 [[X:%.*]], 4064
92 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[X_MASK]], [[TMP1]]
93 ; CHECK-NEXT: ret i32 [[TMP2]]
102 define <2 x i32> @lshr_add_and_shl_v2i32(<2 x i32> %x, <2 x i32> %y) {
103 ; CHECK-LABEL: @lshr_add_and_shl_v2i32(
104 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[Y:%.*]], <i32 5, i32 5>
105 ; CHECK-NEXT: [[X_MASK:%.*]] = and <2 x i32> [[X:%.*]], <i32 4064, i32 4064>
106 ; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i32> [[X_MASK]], [[TMP1]]
107 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
109 %1 = lshr <2 x i32> %x, <i32 5, i32 5>
110 %2 = and <2 x i32> %1, <i32 127, i32 127>
111 %3 = add <2 x i32> %y, %2
112 %4 = shl <2 x i32> %3, <i32 5, i32 5>
116 define <2 x i32> @lshr_add_and_shl_v2i32_undef(<2 x i32> %x, <2 x i32> %y) {
117 ; CHECK-LABEL: @lshr_add_and_shl_v2i32_undef(
118 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 undef, i32 5>
119 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 127, i32 127>
120 ; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> [[TMP2]], [[Y:%.*]]
121 ; CHECK-NEXT: [[TMP4:%.*]] = shl <2 x i32> [[TMP3]], <i32 5, i32 undef>
122 ; CHECK-NEXT: ret <2 x i32> [[TMP4]]
124 %1 = lshr <2 x i32> %x, <i32 undef, i32 5>
125 %2 = and <2 x i32> %1, <i32 127, i32 127>
126 %3 = add <2 x i32> %y, %2
127 %4 = shl <2 x i32> %3, <i32 5, i32 undef>
131 define <2 x i32> @lshr_add_and_shl_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) {
132 ; CHECK-LABEL: @lshr_add_and_shl_v2i32_nonuniform(
133 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 6>
134 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 127, i32 255>
135 ; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> [[TMP2]], [[Y:%.*]]
136 ; CHECK-NEXT: [[TMP4:%.*]] = shl <2 x i32> [[TMP3]], <i32 5, i32 6>
137 ; CHECK-NEXT: ret <2 x i32> [[TMP4]]
139 %1 = lshr <2 x i32> %x, <i32 5, i32 6>
140 %2 = and <2 x i32> %1, <i32 127, i32 255>
141 %3 = add <2 x i32> %y, %2
142 %4 = shl <2 x i32> %3, <i32 5, i32 6>
146 define i32 @shl_add_and_lshr(i32 %x, i32 %y) {
147 ; CHECK-LABEL: @shl_add_and_lshr(
148 ; CHECK-NEXT: [[C1:%.*]] = shl i32 [[Y:%.*]], 4
149 ; CHECK-NEXT: [[X_MASK:%.*]] = and i32 [[X:%.*]], 128
150 ; CHECK-NEXT: [[D:%.*]] = add i32 [[X_MASK]], [[C1]]
151 ; CHECK-NEXT: ret i32 [[D]]
160 define <2 x i32> @shl_add_and_lshr_v2i32(<2 x i32> %x, <2 x i32> %y) {
161 ; CHECK-LABEL: @shl_add_and_lshr_v2i32(
162 ; CHECK-NEXT: [[C1:%.*]] = shl <2 x i32> [[Y:%.*]], <i32 4, i32 4>
163 ; CHECK-NEXT: [[X_MASK:%.*]] = and <2 x i32> [[X:%.*]], <i32 128, i32 128>
164 ; CHECK-NEXT: [[D:%.*]] = add <2 x i32> [[X_MASK]], [[C1]]
165 ; CHECK-NEXT: ret <2 x i32> [[D]]
167 %a = lshr <2 x i32> %x, <i32 4, i32 4>
168 %b = and <2 x i32> %a, <i32 8, i32 8>
169 %c = add <2 x i32> %b, %y
170 %d = shl <2 x i32> %c, <i32 4, i32 4>
174 define <2 x i32> @shl_add_and_lshr_v2i32_undef(<2 x i32> %x, <2 x i32> %y) {
175 ; CHECK-LABEL: @shl_add_and_lshr_v2i32_undef(
176 ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 4, i32 undef>
177 ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], <i32 8, i32 undef>
178 ; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], [[Y:%.*]]
179 ; CHECK-NEXT: [[D:%.*]] = shl <2 x i32> [[C]], <i32 4, i32 undef>
180 ; CHECK-NEXT: ret <2 x i32> [[D]]
182 %a = lshr <2 x i32> %x, <i32 4, i32 undef>
183 %b = and <2 x i32> %a, <i32 8, i32 undef>
184 %c = add <2 x i32> %b, %y
185 %d = shl <2 x i32> %c, <i32 4, i32 undef>
189 define <2 x i32> @shl_add_and_lshr_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) {
190 ; CHECK-LABEL: @shl_add_and_lshr_v2i32_nonuniform(
191 ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 4, i32 5>
192 ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], <i32 8, i32 9>
193 ; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], [[Y:%.*]]
194 ; CHECK-NEXT: [[D:%.*]] = shl <2 x i32> [[C]], <i32 4, i32 5>
195 ; CHECK-NEXT: ret <2 x i32> [[D]]
197 %a = lshr <2 x i32> %x, <i32 4, i32 5>
198 %b = and <2 x i32> %a, <i32 8, i32 9>
199 %c = add <2 x i32> %b, %y
200 %d = shl <2 x i32> %c, <i32 4, i32 5>