1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define <4 x float> @test1(<4 x float> %v1) {
6 ; CHECK-NEXT: ret <4 x float> [[V1:%.*]]
8 %v2 = shufflevector <4 x float> %v1, <4 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
12 define <4 x float> @test2(<4 x float> %v1) {
13 ; CHECK-LABEL: @test2(
14 ; CHECK-NEXT: ret <4 x float> [[V1:%.*]]
16 %v2 = shufflevector <4 x float> %v1, <4 x float> %v1, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
20 define float @test3(<4 x float> %A, <4 x float> %B, float %f) {
21 ; CHECK-LABEL: @test3(
22 ; CHECK-NEXT: ret float [[F:%.*]]
24 %C = insertelement <4 x float> %A, float %f, i32 0
25 %D = shufflevector <4 x float> %C, <4 x float> %B, <4 x i32> <i32 5, i32 0, i32 2, i32 7>
26 %E = extractelement <4 x float> %D, i32 1
30 define i32 @test4(<4 x i32> %X) {
31 ; CHECK-LABEL: @test4(
32 ; CHECK-NEXT: [[R:%.*]] = extractelement <4 x i32> [[X:%.*]], i32 0
33 ; CHECK-NEXT: ret i32 [[R]]
35 %t = shufflevector <4 x i32> %X, <4 x i32> undef, <4 x i32> zeroinitializer
36 %r = extractelement <4 x i32> %t, i32 0
40 define i32 @test5(<4 x i32> %X) {
41 ; CHECK-LABEL: @test5(
42 ; CHECK-NEXT: [[R:%.*]] = extractelement <4 x i32> [[X:%.*]], i32 3
43 ; CHECK-NEXT: ret i32 [[R]]
45 %t = shufflevector <4 x i32> %X, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 undef, i32 undef>
46 %r = extractelement <4 x i32> %t, i32 0
50 define float @test6(<4 x float> %X) {
51 ; CHECK-LABEL: @test6(
52 ; CHECK-NEXT: [[R:%.*]] = extractelement <4 x float> [[X:%.*]], i32 0
53 ; CHECK-NEXT: ret float [[R]]
55 %X1 = bitcast <4 x float> %X to <4 x i32>
56 %t = shufflevector <4 x i32> %X1, <4 x i32> undef, <4 x i32> zeroinitializer
57 %t2 = bitcast <4 x i32> %t to <4 x float>
58 %r = extractelement <4 x float> %t2, i32 0
62 define <4 x float> @test7(<4 x float> %x) {
63 ; CHECK-LABEL: @test7(
64 ; CHECK-NEXT: ret <4 x float> [[X:%.*]]
66 %r = shufflevector <4 x float> %x, <4 x float> undef, <4 x i32> < i32 0, i32 1, i32 6, i32 7 >
70 ; This should turn into a single shuffle.
71 define <4 x float> @test8(<4 x float> %x, <4 x float> %y) {
72 ; CHECK-LABEL: @test8(
73 ; CHECK-NEXT: [[T134:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> <i32 1, i32 undef, i32 3, i32 4>
74 ; CHECK-NEXT: ret <4 x float> [[T134]]
76 %t4 = extractelement <4 x float> %x, i32 1
77 %t2 = extractelement <4 x float> %x, i32 3
78 %t1 = extractelement <4 x float> %y, i32 0
79 %t128 = insertelement <4 x float> undef, float %t4, i32 0
80 %t130 = insertelement <4 x float> %t128, float undef, i32 1
81 %t132 = insertelement <4 x float> %t130, float %t2, i32 2
82 %t134 = insertelement <4 x float> %t132, float %t1, i32 3
86 ; Test fold of two shuffles where the first shuffle vectors inputs are a
87 ; different length then the second.
88 define <4 x i8> @test9(<16 x i8> %t6) {
89 ; CHECK-LABEL: @test9(
90 ; CHECK-NEXT: [[T9:%.*]] = shufflevector <16 x i8> [[T6:%.*]], <16 x i8> undef, <4 x i32> <i32 13, i32 9, i32 4, i32 13>
91 ; CHECK-NEXT: ret <4 x i8> [[T9]]
93 %t7 = shufflevector <16 x i8> %t6, <16 x i8> undef, <4 x i32> < i32 13, i32 9, i32 4, i32 13 >
94 %t9 = shufflevector <4 x i8> %t7, <4 x i8> undef, <4 x i32> < i32 3, i32 1, i32 2, i32 0 >
98 ; Same as test9, but make sure that "undef" mask values are not confused with
99 ; mask values of 2*N, where N is the mask length. These shuffles should not
100 ; be folded (because [8,9,4,8] may not be a mask supported by the target).
102 define <4 x i8> @test9a(<16 x i8> %t6) {
103 ; CHECK-LABEL: @test9a(
104 ; CHECK-NEXT: [[T7:%.*]] = shufflevector <16 x i8> [[T6:%.*]], <16 x i8> undef, <4 x i32> <i32 undef, i32 9, i32 4, i32 8>
105 ; CHECK-NEXT: [[T9:%.*]] = shufflevector <4 x i8> [[T7]], <4 x i8> undef, <4 x i32> <i32 3, i32 1, i32 2, i32 undef>
106 ; CHECK-NEXT: ret <4 x i8> [[T9]]
108 %t7 = shufflevector <16 x i8> %t6, <16 x i8> undef, <4 x i32> < i32 undef, i32 9, i32 4, i32 8 >
109 %t9 = shufflevector <4 x i8> %t7, <4 x i8> undef, <4 x i32> < i32 3, i32 1, i32 2, i32 0 >
113 ; Test fold of two shuffles where the first shuffle vectors inputs are a
114 ; different length then the second.
115 define <4 x i8> @test9b(<4 x i8> %t6, <4 x i8> %t7) {
116 ; CHECK-LABEL: @test9b(
117 ; CHECK-NEXT: [[T9:%.*]] = shufflevector <4 x i8> [[T6:%.*]], <4 x i8> [[T7:%.*]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
118 ; CHECK-NEXT: ret <4 x i8> [[T9]]
120 %t1 = shufflevector <4 x i8> %t6, <4 x i8> %t7, <8 x i32> <i32 0, i32 1, i32 4, i32 5, i32 4, i32 5, i32 2, i32 3>
121 %t9 = shufflevector <8 x i8> %t1, <8 x i8> undef, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
125 ; Redundant vector splats should be removed. Radar 8597790.
126 define <4 x i32> @test10(<4 x i32> %t5) {
127 ; CHECK-LABEL: @test10(
128 ; CHECK-NEXT: [[T7:%.*]] = shufflevector <4 x i32> [[T5:%.*]], <4 x i32> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
129 ; CHECK-NEXT: ret <4 x i32> [[T7]]
131 %t6 = shufflevector <4 x i32> %t5, <4 x i32> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
132 %t7 = shufflevector <4 x i32> %t6, <4 x i32> undef, <4 x i32> zeroinitializer
136 ; Test fold of two shuffles where the two shufflevector inputs's op1 are the same.
138 define <8 x i8> @test11(<16 x i8> %t6) {
139 ; CHECK-LABEL: @test11(
140 ; CHECK-NEXT: [[T3:%.*]] = shufflevector <16 x i8> [[T6:%.*]], <16 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
141 ; CHECK-NEXT: ret <8 x i8> [[T3]]
143 %t1 = shufflevector <16 x i8> %t6, <16 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
144 %t2 = shufflevector <16 x i8> %t6, <16 x i8> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
145 %t3 = shufflevector <4 x i8> %t1, <4 x i8> %t2, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
149 ; Test fold of two shuffles where the first shufflevector's inputs are the same as the second.
151 define <8 x i8> @test12(<8 x i8> %t6, <8 x i8> %t2) {
152 ; CHECK-LABEL: @test12(
153 ; CHECK-NEXT: [[T3:%.*]] = shufflevector <8 x i8> [[T6:%.*]], <8 x i8> [[T2:%.*]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 9, i32 8, i32 11, i32 12>
154 ; CHECK-NEXT: ret <8 x i8> [[T3]]
156 %t1 = shufflevector <8 x i8> %t6, <8 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 5, i32 4, i32 undef, i32 7>
157 %t3 = shufflevector <8 x i8> %t1, <8 x i8> %t2, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 9, i32 8, i32 11, i32 12>
161 ; Test fold of two shuffles where the first shufflevector's inputs are the same as the second.
163 define <8 x i8> @test12a(<8 x i8> %t6, <8 x i8> %t2) {
164 ; CHECK-LABEL: @test12a(
165 ; CHECK-NEXT: [[T3:%.*]] = shufflevector <8 x i8> [[T2:%.*]], <8 x i8> [[T6:%.*]], <8 x i32> <i32 0, i32 3, i32 1, i32 4, i32 8, i32 9, i32 10, i32 11>
166 ; CHECK-NEXT: ret <8 x i8> [[T3]]
168 %t1 = shufflevector <8 x i8> %t6, <8 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 5, i32 4, i32 undef, i32 7>
169 %t3 = shufflevector <8 x i8> %t2, <8 x i8> %t1, <8 x i32> <i32 0, i32 3, i32 1, i32 4, i32 8, i32 9, i32 10, i32 11>
173 ; The mask length of the 1st shuffle can be reduced to eliminate the 2nd shuffle.
175 define <2 x i8> @extract_subvector_of_shuffle(<2 x i8> %x, <2 x i8> %y) {
176 ; CHECK-LABEL: @extract_subvector_of_shuffle(
177 ; CHECK-NEXT: [[EXTRACT_SUBV:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 2>
178 ; CHECK-NEXT: ret <2 x i8> [[EXTRACT_SUBV]]
180 %shuf = shufflevector <2 x i8> %x, <2 x i8> %y, <3 x i32> <i32 0, i32 2, i32 0>
181 %extract_subv = shufflevector <3 x i8> %shuf, <3 x i8> undef, <2 x i32> <i32 0, i32 1>
182 ret <2 x i8> %extract_subv
185 ; Undef elements in either mask are ok. Undefs from the 2nd shuffle mask should propagate to the new shuffle.
186 ; The type of the inputs does not have to match the output type.
188 define <4 x i8> @extract_subvector_of_shuffle_undefs_types(<2 x i8> %x, <2 x i8> %y) {
189 ; CHECK-LABEL: @extract_subvector_of_shuffle_undefs_types(
190 ; CHECK-NEXT: [[EXTRACT_SUBV:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]], <4 x i32> <i32 undef, i32 2, i32 0, i32 undef>
191 ; CHECK-NEXT: ret <4 x i8> [[EXTRACT_SUBV]]
193 %shuf = shufflevector <2 x i8> %x, <2 x i8> %y, <5 x i32> <i32 undef, i32 2, i32 0, i32 1, i32 0>
194 %extract_subv = shufflevector <5 x i8> %shuf, <5 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
195 ret <4 x i8> %extract_subv
198 ; Extra uses are not ok - we only do the transform when we can eliminate an instruction.
200 declare void @use_v5i8(<5 x i8>)
202 define <4 x i8> @extract_subvector_of_shuffle_extra_use(<2 x i8> %x, <2 x i8> %y) {
203 ; CHECK-LABEL: @extract_subvector_of_shuffle_extra_use(
204 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]], <5 x i32> <i32 undef, i32 2, i32 0, i32 1, i32 0>
205 ; CHECK-NEXT: call void @use_v5i8(<5 x i8> [[SHUF]])
206 ; CHECK-NEXT: [[EXTRACT_SUBV:%.*]] = shufflevector <5 x i8> [[SHUF]], <5 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
207 ; CHECK-NEXT: ret <4 x i8> [[EXTRACT_SUBV]]
209 %shuf = shufflevector <2 x i8> %x, <2 x i8> %y, <5 x i32> <i32 undef, i32 2, i32 0, i32 1, i32 0>
210 call void @use_v5i8(<5 x i8> %shuf)
211 %extract_subv = shufflevector <5 x i8> %shuf, <5 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
212 ret <4 x i8> %extract_subv
215 define <2 x i8> @test13a(i8 %x1, i8 %x2) {
216 ; CHECK-LABEL: @test13a(
217 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i8> undef, i8 [[X1:%.*]], i32 1
218 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i8> [[TMP1]], i8 [[X2:%.*]], i32 0
219 ; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i8> [[TMP2]], <i8 7, i8 5>
220 ; CHECK-NEXT: ret <2 x i8> [[TMP3]]
222 %A = insertelement <2 x i8> undef, i8 %x1, i32 0
223 %B = insertelement <2 x i8> %A, i8 %x2, i32 1
224 %C = add <2 x i8> %B, <i8 5, i8 7>
225 %D = shufflevector <2 x i8> %C, <2 x i8> undef, <2 x i32> <i32 1, i32 0>
229 ; Increasing length of vector ops is not a good canonicalization.
231 define <3 x i32> @add_wider(i32 %y, i32 %z) {
232 ; CHECK-LABEL: @add_wider(
233 ; CHECK-NEXT: [[I0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0
234 ; CHECK-NEXT: [[I1:%.*]] = insertelement <2 x i32> [[I0]], i32 [[Z:%.*]], i32 1
235 ; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[I1]], <i32 255, i32 255>
236 ; CHECK-NEXT: [[EXT:%.*]] = shufflevector <2 x i32> [[A]], <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 undef>
237 ; CHECK-NEXT: ret <3 x i32> [[EXT]]
239 %i0 = insertelement <2 x i32> undef, i32 %y, i32 0
240 %i1 = insertelement <2 x i32> %i0, i32 %z, i32 1
241 %a = add <2 x i32> %i1, <i32 255, i32 255>
242 %ext = shufflevector <2 x i32> %a, <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 undef>
246 ; Increasing length of vector ops must be safe from illegal undef propagation.
248 define <3 x i32> @div_wider(i32 %y, i32 %z) {
249 ; CHECK-LABEL: @div_wider(
250 ; CHECK-NEXT: [[I0:%.*]] = insertelement <2 x i32> undef, i32 [[Y:%.*]], i32 0
251 ; CHECK-NEXT: [[I1:%.*]] = insertelement <2 x i32> [[I0]], i32 [[Z:%.*]], i32 1
252 ; CHECK-NEXT: [[A:%.*]] = sdiv <2 x i32> [[I1]], <i32 255, i32 255>
253 ; CHECK-NEXT: [[EXT:%.*]] = shufflevector <2 x i32> [[A]], <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 undef>
254 ; CHECK-NEXT: ret <3 x i32> [[EXT]]
256 %i0 = insertelement <2 x i32> undef, i32 %y, i32 0
257 %i1 = insertelement <2 x i32> %i0, i32 %z, i32 1
258 %a = sdiv <2 x i32> %i1, <i32 255, i32 255>
259 %ext = shufflevector <2 x i32> %a, <2 x i32> undef, <3 x i32> <i32 0, i32 1, i32 undef>
263 ; Increasing length of insertelements (no math ops) is a good canonicalization.
265 define <3 x i8> @fold_inselts_with_widening_shuffle(i8 %x, i8 %y) {
266 ; CHECK-LABEL: @fold_inselts_with_widening_shuffle(
267 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x i8> undef, i8 [[X:%.*]], i32 0
268 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <3 x i8> [[TMP1]], i8 [[Y:%.*]], i32 1
269 ; CHECK-NEXT: ret <3 x i8> [[TMP2]]
271 %ins0 = insertelement <2 x i8> undef, i8 %x, i32 0
272 %ins1 = insertelement <2 x i8> %ins0, i8 %y, i32 1
273 %widen = shufflevector <2 x i8> %ins1, <2 x i8> undef, <3 x i32> <i32 0, i32 1, i32 undef>
277 define <2 x i8> @test13b(i8 %x) {
278 ; CHECK-LABEL: @test13b(
279 ; CHECK-NEXT: [[B:%.*]] = insertelement <2 x i8> undef, i8 [[X:%.*]], i32 1
280 ; CHECK-NEXT: ret <2 x i8> [[B]]
282 %A = insertelement <2 x i8> undef, i8 %x, i32 0
283 %B = shufflevector <2 x i8> %A, <2 x i8> undef, <2 x i32> <i32 undef, i32 0>
287 define <2 x i8> @test13c(i8 %x1, i8 %x2) {
288 ; CHECK-LABEL: @test13c(
289 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i8> undef, i8 [[X1:%.*]], i32 0
290 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i8> [[TMP1]], i8 [[X2:%.*]], i32 1
291 ; CHECK-NEXT: ret <2 x i8> [[TMP2]]
293 %A = insertelement <4 x i8> undef, i8 %x1, i32 0
294 %B = insertelement <4 x i8> %A, i8 %x2, i32 2
295 %C = shufflevector <4 x i8> %B, <4 x i8> undef, <2 x i32> <i32 0, i32 2>
299 define void @test14(i16 %conv10) {
300 ; CHECK-LABEL: @test14(
301 ; CHECK-NEXT: store <4 x i16> <i16 undef, i16 undef, i16 undef, i16 23>, <4 x i16>* undef, align 8
302 ; CHECK-NEXT: ret void
304 %t = alloca <4 x i16>, align 8
305 %vecinit6 = insertelement <4 x i16> undef, i16 23, i32 3
306 store <4 x i16> %vecinit6, <4 x i16>* undef
307 %t1 = load <4 x i16>, <4 x i16>* undef
308 %vecinit11 = insertelement <4 x i16> undef, i16 %conv10, i32 3
309 %div = udiv <4 x i16> %t1, %vecinit11
310 store <4 x i16> %div, <4 x i16>* %t
311 %t4 = load <4 x i16>, <4 x i16>* %t
312 %t5 = shufflevector <4 x i16> %t4, <4 x i16> undef, <2 x i32> <i32 2, i32 0>
313 %cmp = icmp ule <2 x i16> %t5, undef
314 %sext = sext <2 x i1> %cmp to <2 x i16>
318 ; Check that sequences of insert/extract element are
319 ; collapsed into valid shuffle instruction with correct shuffle indexes.
321 define <4 x float> @test15a(<4 x float> %LHS, <4 x float> %RHS) {
322 ; CHECK-LABEL: @test15a(
323 ; CHECK-NEXT: [[T4:%.*]] = shufflevector <4 x float> [[LHS:%.*]], <4 x float> [[RHS:%.*]], <4 x i32> <i32 4, i32 0, i32 6, i32 6>
324 ; CHECK-NEXT: ret <4 x float> [[T4]]
326 %t1 = extractelement <4 x float> %LHS, i32 0
327 %t2 = insertelement <4 x float> %RHS, float %t1, i32 1
328 %t3 = extractelement <4 x float> %RHS, i32 2
329 %t4 = insertelement <4 x float> %t2, float %t3, i32 3
333 define <4 x float> @test15b(<4 x float> %LHS, <4 x float> %RHS) {
334 ; CHECK-LABEL: @test15b(
335 ; CHECK-NEXT: [[T5:%.*]] = shufflevector <4 x float> [[LHS:%.*]], <4 x float> [[RHS:%.*]], <4 x i32> <i32 4, i32 3, i32 6, i32 6>
336 ; CHECK-NEXT: ret <4 x float> [[T5]]
338 %t0 = extractelement <4 x float> %LHS, i32 3
339 %t1 = insertelement <4 x float> %RHS, float %t0, i32 0
340 %t2 = extractelement <4 x float> %t1, i32 0
341 %t3 = insertelement <4 x float> %RHS, float %t2, i32 1
342 %t4 = extractelement <4 x float> %RHS, i32 2
343 %t5 = insertelement <4 x float> %t3, float %t4, i32 3
347 define <1 x i32> @test16a(i32 %ele) {
348 ; CHECK-LABEL: @test16a(
349 ; CHECK-NEXT: ret <1 x i32> <i32 2>
351 %t0 = insertelement <2 x i32> <i32 1, i32 undef>, i32 %ele, i32 1
352 %t1 = shl <2 x i32> %t0, <i32 1, i32 1>
353 %t2 = shufflevector <2 x i32> %t1, <2 x i32> undef, <1 x i32> <i32 0>
357 define <4 x i8> @test16b(i8 %ele) {
358 ; CHECK-LABEL: @test16b(
359 ; CHECK-NEXT: ret <4 x i8> <i8 2, i8 2, i8 2, i8 2>
361 %t0 = insertelement <8 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 undef, i8 1>, i8 %ele, i32 6
362 %t1 = shl <8 x i8> %t0, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
363 %t2 = shufflevector <8 x i8> %t1, <8 x i8> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 4>
367 ; If composition of two shuffles is identity, shuffles can be removed.
368 define <4 x i32> @shuffle_17ident(<4 x i32> %v) {
369 ; CHECK-LABEL: @shuffle_17ident(
370 ; CHECK-NEXT: ret <4 x i32> [[V:%.*]]
372 %shuffle = shufflevector <4 x i32> %v, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
373 %shuffle2 = shufflevector <4 x i32> %shuffle, <4 x i32> zeroinitializer, <4 x i32> <i32 3, i32 0, i32 1, i32 2>
374 ret <4 x i32> %shuffle2
377 ; swizzle can be put after operation
378 define <4 x i32> @shuffle_17and(<4 x i32> %v1, <4 x i32> %v2) {
379 ; CHECK-LABEL: @shuffle_17and(
380 ; CHECK-NEXT: [[TMP1:%.*]] = and <4 x i32> [[V1:%.*]], [[V2:%.*]]
381 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
382 ; CHECK-NEXT: ret <4 x i32> [[R]]
384 %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
385 %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
386 %r = and <4 x i32> %t1, %t2
390 declare void @use(<2 x float>)
392 ; One extra use is ok to transform.
394 define <2 x float> @shuffle_fadd_multiuse(<2 x float> %v1, <2 x float> %v2) {
395 ; CHECK-LABEL: @shuffle_fadd_multiuse(
396 ; CHECK-NEXT: [[T1:%.*]] = shufflevector <2 x float> [[V1:%.*]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
397 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <2 x float> [[V1]], [[V2:%.*]]
398 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
399 ; CHECK-NEXT: call void @use(<2 x float> [[T1]])
400 ; CHECK-NEXT: ret <2 x float> [[R]]
402 %t1 = shufflevector <2 x float> %v1, <2 x float> undef, <2 x i32> <i32 1, i32 0>
403 %t2 = shufflevector <2 x float> %v2, <2 x float> undef, <2 x i32> <i32 1, i32 0>
404 %r = fadd <2 x float> %t1, %t2
405 call void @use(<2 x float> %t1)
409 define <2 x float> @shuffle_fdiv_multiuse(<2 x float> %v1, <2 x float> %v2) {
410 ; CHECK-LABEL: @shuffle_fdiv_multiuse(
411 ; CHECK-NEXT: [[T2:%.*]] = shufflevector <2 x float> [[V2:%.*]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
412 ; CHECK-NEXT: [[TMP1:%.*]] = fdiv <2 x float> [[V1:%.*]], [[V2]]
413 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
414 ; CHECK-NEXT: call void @use(<2 x float> [[T2]])
415 ; CHECK-NEXT: ret <2 x float> [[R]]
417 %t1 = shufflevector <2 x float> %v1, <2 x float> undef, <2 x i32> <i32 1, i32 0>
418 %t2 = shufflevector <2 x float> %v2, <2 x float> undef, <2 x i32> <i32 1, i32 0>
419 %r = fdiv <2 x float> %t1, %t2
420 call void @use(<2 x float> %t2)
424 ; But 2 extra uses would require an extra instruction.
426 define <2 x float> @shuffle_fsub_multiuse(<2 x float> %v1, <2 x float> %v2) {
427 ; CHECK-LABEL: @shuffle_fsub_multiuse(
428 ; CHECK-NEXT: [[T1:%.*]] = shufflevector <2 x float> [[V1:%.*]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
429 ; CHECK-NEXT: [[T2:%.*]] = shufflevector <2 x float> [[V2:%.*]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
430 ; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> [[T1]], [[T2]]
431 ; CHECK-NEXT: call void @use(<2 x float> [[T1]])
432 ; CHECK-NEXT: call void @use(<2 x float> [[T2]])
433 ; CHECK-NEXT: ret <2 x float> [[R]]
435 %t1 = shufflevector <2 x float> %v1, <2 x float> undef, <2 x i32> <i32 1, i32 0>
436 %t2 = shufflevector <2 x float> %v2, <2 x float> undef, <2 x i32> <i32 1, i32 0>
437 %r = fsub <2 x float> %t1, %t2
438 call void @use(<2 x float> %t1)
439 call void @use(<2 x float> %t2)
443 define <4 x i32> @shuffle_17add(<4 x i32> %v1, <4 x i32> %v2) {
444 ; CHECK-LABEL: @shuffle_17add(
445 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[V1:%.*]], [[V2:%.*]]
446 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
447 ; CHECK-NEXT: ret <4 x i32> [[R]]
449 %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
450 %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
451 %r = add <4 x i32> %t1, %t2
455 define <4 x i32> @shuffle_17addnsw(<4 x i32> %v1, <4 x i32> %v2) {
456 ; CHECK-LABEL: @shuffle_17addnsw(
457 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw <4 x i32> [[V1:%.*]], [[V2:%.*]]
458 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
459 ; CHECK-NEXT: ret <4 x i32> [[R]]
461 %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
462 %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
463 %r = add nsw <4 x i32> %t1, %t2
467 define <4 x i32> @shuffle_17addnuw(<4 x i32> %v1, <4 x i32> %v2) {
468 ; CHECK-LABEL: @shuffle_17addnuw(
469 ; CHECK-NEXT: [[TMP1:%.*]] = add nuw <4 x i32> [[V1:%.*]], [[V2:%.*]]
470 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
471 ; CHECK-NEXT: ret <4 x i32> [[R]]
473 %t1 = shufflevector <4 x i32> %v1, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
474 %t2 = shufflevector <4 x i32> %v2, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
475 %r = add nuw <4 x i32> %t1, %t2
479 define <4 x float> @shuffle_17fsub_fast(<4 x float> %v1, <4 x float> %v2) {
480 ; CHECK-LABEL: @shuffle_17fsub_fast(
481 ; CHECK-NEXT: [[TMP1:%.*]] = fsub fast <4 x float> [[V1:%.*]], [[V2:%.*]]
482 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
483 ; CHECK-NEXT: ret <4 x float> [[R]]
485 %t1 = shufflevector <4 x float> %v1, <4 x float> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
486 %t2 = shufflevector <4 x float> %v2, <4 x float> zeroinitializer, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
487 %r = fsub fast <4 x float> %t1, %t2
491 define <4 x i32> @add_const(<4 x i32> %v) {
492 ; CHECK-LABEL: @add_const(
493 ; CHECK-NEXT: [[TMP1:%.*]] = add <4 x i32> [[V:%.*]], <i32 44, i32 41, i32 42, i32 43>
494 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
495 ; CHECK-NEXT: ret <4 x i32> [[R]]
497 %t1 = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
498 %r = add <4 x i32> %t1, <i32 41, i32 42, i32 43, i32 44>
502 define <4 x i32> @sub_const(<4 x i32> %v) {
503 ; CHECK-LABEL: @sub_const(
504 ; CHECK-NEXT: [[TMP1:%.*]] = sub <4 x i32> <i32 44, i32 43, i32 42, i32 41>, [[V:%.*]]
505 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
506 ; CHECK-NEXT: ret <4 x i32> [[R]]
508 %t1 = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
509 %r = sub <4 x i32> <i32 41, i32 42, i32 43, i32 44>, %t1
513 ; Math before shuffle requires an extra shuffle.
515 define <2 x float> @fadd_const_multiuse(<2 x float> %v) {
516 ; CHECK-LABEL: @fadd_const_multiuse(
517 ; CHECK-NEXT: [[T1:%.*]] = shufflevector <2 x float> [[V:%.*]], <2 x float> undef, <2 x i32> <i32 1, i32 0>
518 ; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[T1]], <float 4.100000e+01, float 4.200000e+01>
519 ; CHECK-NEXT: call void @use(<2 x float> [[T1]])
520 ; CHECK-NEXT: ret <2 x float> [[R]]
522 %t1 = shufflevector <2 x float> %v, <2 x float> undef, <2 x i32> <i32 1, i32 0>
523 %r = fadd <2 x float> %t1, <float 41.0, float 42.0>
524 call void @use(<2 x float> %t1)
528 ; Math before splat allows replacing constant elements with undef lanes.
530 define <4 x i32> @mul_const_splat(<4 x i32> %v) {
531 ; CHECK-LABEL: @mul_const_splat(
532 ; CHECK-NEXT: [[TMP1:%.*]] = mul <4 x i32> [[V:%.*]], <i32 undef, i32 42, i32 undef, i32 undef>
533 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
534 ; CHECK-NEXT: ret <4 x i32> [[R]]
536 %t1 = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
537 %r = mul <4 x i32> <i32 42, i32 42, i32 42, i32 42>, %t1
541 ; Take 2 elements of a vector and shift each of those by a different amount
543 define <4 x i32> @lshr_const_half_splat(<4 x i32> %v) {
544 ; CHECK-LABEL: @lshr_const_half_splat(
545 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> <i32 undef, i32 8, i32 9, i32 undef>, [[V:%.*]]
546 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> <i32 1, i32 1, i32 2, i32 2>
547 ; CHECK-NEXT: ret <4 x i32> [[R]]
549 %t1 = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 1, i32 1, i32 2, i32 2>
550 %r = lshr <4 x i32> <i32 8, i32 8, i32 9, i32 9>, %t1
554 ; We can't change this because there's no pre-shuffle version of the fmul constant.
556 define <2 x float> @fmul_const_invalid_constant(<2 x float> %v) {
557 ; CHECK-LABEL: @fmul_const_invalid_constant(
558 ; CHECK-NEXT: [[T1:%.*]] = shufflevector <2 x float> [[V:%.*]], <2 x float> undef, <2 x i32> zeroinitializer
559 ; CHECK-NEXT: [[R:%.*]] = fmul <2 x float> [[T1]], <float 4.100000e+01, float 4.200000e+01>
560 ; CHECK-NEXT: ret <2 x float> [[R]]
562 %t1 = shufflevector <2 x float> %v, <2 x float> undef, <2 x i32> <i32 0, i32 0>
563 %r = fmul <2 x float> %t1, <float 41.0, float 42.0>
567 ; Reduce the width of the binop by moving it ahead of a shuffle.
569 define <4 x i8> @widening_shuffle_add_1(<2 x i8> %x) {
570 ; CHECK-LABEL: @widening_shuffle_add_1(
571 ; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i8> [[X:%.*]], <i8 42, i8 43>
572 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i8> [[TMP1]], <2 x i8> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
573 ; CHECK-NEXT: ret <4 x i8> [[R]]
575 %widex = shufflevector <2 x i8> %x, <2 x i8> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
576 %r = add <4 x i8> %widex, <i8 42, i8 43, i8 44, i8 45>
580 ; Reduce the width of the binop by moving it ahead of a shuffle.
582 define <4 x i8> @widening_shuffle_add_2(<2 x i8> %x) {
583 ; CHECK-LABEL: @widening_shuffle_add_2(
584 ; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i8> [[X:%.*]], <i8 43, i8 42>
585 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i8> [[TMP1]], <2 x i8> undef, <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
586 ; CHECK-NEXT: ret <4 x i8> [[R]]
588 %widex = shufflevector <2 x i8> %x, <2 x i8> undef, <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
589 %r = add <4 x i8> %widex, <i8 42, i8 43, i8 44, i8 45>
593 ; Negative test - widening shuffles have the same mask/constant constraint as non-size-changing shuffles.
595 define <4 x i8> @widening_shuffle_add_invalid_constant(<2 x i8> %x) {
596 ; CHECK-LABEL: @widening_shuffle_add_invalid_constant(
597 ; CHECK-NEXT: [[WIDEX:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> undef, <4 x i32> <i32 1, i32 1, i32 undef, i32 undef>
598 ; CHECK-NEXT: [[R:%.*]] = add <4 x i8> [[WIDEX]], <i8 42, i8 43, i8 44, i8 45>
599 ; CHECK-NEXT: ret <4 x i8> [[R]]
601 %widex = shufflevector <2 x i8> %x, <2 x i8> undef, <4 x i32> <i32 1, i32 1, i32 undef, i32 undef>
602 %r = add <4 x i8> %widex, <i8 42, i8 43, i8 44, i8 45>
606 ; Negative test - widening shuffles have an additional constraint: they must not extend with anything but undefs.
608 define <4 x i8> @widening_shuffle_add_invalid_mask(<2 x i8> %x) {
609 ; CHECK-LABEL: @widening_shuffle_add_invalid_mask(
610 ; CHECK-NEXT: [[WIDEX:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 0>
611 ; CHECK-NEXT: [[R:%.*]] = add <4 x i8> [[WIDEX]], <i8 42, i8 43, i8 44, i8 45>
612 ; CHECK-NEXT: ret <4 x i8> [[R]]
614 %widex = shufflevector <2 x i8> %x, <2 x i8> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 0>
615 %r = add <4 x i8> %widex, <i8 42, i8 43, i8 44, i8 45>
619 ; A binop that produces undef in the high lanes can be moved before the shuffle.
620 ; This is ok because 'shl C, undef --> undef'.
622 define <4 x i16> @widening_shuffle_shl_constant_op0(<2 x i16> %v) {
623 ; CHECK-LABEL: @widening_shuffle_shl_constant_op0(
624 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i16> <i16 42, i16 -42>, [[V:%.*]]
625 ; CHECK-NEXT: [[BO:%.*]] = shufflevector <2 x i16> [[TMP1]], <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
626 ; CHECK-NEXT: ret <4 x i16> [[BO]]
628 %shuf = shufflevector <2 x i16> %v, <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
629 %bo = shl <4 x i16> <i16 42, i16 -42, i16 -1, i16 -1>, %shuf
633 ; A binop that produces undef in the high lanes can be moved before the shuffle.
634 ; This is ok because 'shl undef, 0 --> undef'.
636 define <4 x i16> @widening_shuffle_shl_constant_op1(<2 x i16> %v) {
637 ; CHECK-LABEL: @widening_shuffle_shl_constant_op1(
638 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i16> [[V:%.*]], <i16 2, i16 4>
639 ; CHECK-NEXT: [[BO:%.*]] = shufflevector <2 x i16> [[TMP1]], <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
640 ; CHECK-NEXT: ret <4 x i16> [[BO]]
642 %shuf = shufflevector <2 x i16> %v, <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
643 %bo = shl <4 x i16> %shuf, <i16 2, i16 4, i16 0, i16 0>
647 ; A binop that does not produce undef in the high lanes can not be moved before the shuffle.
648 ; This is not ok because 'shl undef, 1 (or 2)' --> 0' but moving the shuffle results in undef instead.
650 define <4 x i16> @widening_shuffle_shl_constant_op1_non0(<2 x i16> %v) {
651 ; CHECK-LABEL: @widening_shuffle_shl_constant_op1_non0(
652 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i16> [[V:%.*]], <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
653 ; CHECK-NEXT: [[BO:%.*]] = shl <4 x i16> [[SHUF]], <i16 2, i16 4, i16 1, i16 2>
654 ; CHECK-NEXT: ret <4 x i16> [[BO]]
656 %shuf = shufflevector <2 x i16> %v, <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
657 %bo = shl <4 x i16> %shuf, <i16 2, i16 4, i16 1, i16 2>
661 ; A binop that does not produce undef in the high lanes can not be moved before the shuffle.
662 ; This is not ok because 'or -1, undef --> -1' but moving the shuffle results in undef instead.
664 define <4 x i16> @widening_shuffle_or(<2 x i16> %v) {
665 ; CHECK-LABEL: @widening_shuffle_or(
666 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i16> [[V:%.*]], <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
667 ; CHECK-NEXT: [[BO:%.*]] = or <4 x i16> [[SHUF]], <i16 42, i16 -42, i16 -1, i16 -1>
668 ; CHECK-NEXT: ret <4 x i16> [[BO]]
670 %shuf = shufflevector <2 x i16> %v, <2 x i16> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
671 %bo = or <4 x i16> %shuf, <i16 42, i16 -42, i16 -1, i16 -1>
675 define <4 x i32> @shuffle_17add2(<4 x i32> %v) {
676 ; CHECK-LABEL: @shuffle_17add2(
677 ; CHECK-NEXT: [[TMP1:%.*]] = shl <4 x i32> [[V:%.*]], <i32 1, i32 1, i32 1, i32 1>
678 ; CHECK-NEXT: ret <4 x i32> [[TMP1]]
680 %t1 = shufflevector <4 x i32> %v, <4 x i32> zeroinitializer, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
681 %t2 = add <4 x i32> %t1, %t1
682 %r = shufflevector <4 x i32> %t2, <4 x i32> zeroinitializer, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
686 define <4 x i32> @shuffle_17mulsplat(<4 x i32> %v) {
687 ; CHECK-LABEL: @shuffle_17mulsplat(
688 ; CHECK-NEXT: [[TMP1:%.*]] = mul <4 x i32> [[V:%.*]], [[V]]
689 ; CHECK-NEXT: [[M1:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> undef, <4 x i32> zeroinitializer
690 ; CHECK-NEXT: ret <4 x i32> [[M1]]
692 %s1 = shufflevector <4 x i32> %v, <4 x i32> zeroinitializer, <4 x i32> zeroinitializer
693 %m1 = mul <4 x i32> %s1, %s1
694 %s2 = shufflevector <4 x i32> %m1, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
698 ; Do not reorder shuffle and binop if LHS of shuffles are of different size
699 define <2 x i32> @pr19717(<4 x i32> %in0, <2 x i32> %in1) {
700 ; CHECK-LABEL: @pr19717(
701 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[IN0:%.*]], <4 x i32> undef, <2 x i32> zeroinitializer
702 ; CHECK-NEXT: [[SHUFFLE4:%.*]] = shufflevector <2 x i32> [[IN1:%.*]], <2 x i32> undef, <2 x i32> zeroinitializer
703 ; CHECK-NEXT: [[MUL:%.*]] = mul <2 x i32> [[SHUFFLE]], [[SHUFFLE4]]
704 ; CHECK-NEXT: ret <2 x i32> [[MUL]]
706 %shuffle = shufflevector <4 x i32> %in0, <4 x i32> %in0, <2 x i32> zeroinitializer
707 %shuffle4 = shufflevector <2 x i32> %in1, <2 x i32> %in1, <2 x i32> zeroinitializer
708 %mul = mul <2 x i32> %shuffle, %shuffle4
712 define <4 x i16> @pr19717a(<8 x i16> %in0, <8 x i16> %in1) {
713 ; CHECK-LABEL: @pr19717a(
714 ; CHECK-NEXT: [[TMP1:%.*]] = mul <8 x i16> [[IN0:%.*]], [[IN1:%.*]]
715 ; CHECK-NEXT: [[MUL:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> undef, <4 x i32> <i32 5, i32 5, i32 5, i32 5>
716 ; CHECK-NEXT: ret <4 x i16> [[MUL]]
718 %shuffle = shufflevector <8 x i16> %in0, <8 x i16> %in0, <4 x i32> <i32 5, i32 5, i32 5, i32 5>
719 %shuffle1 = shufflevector <8 x i16> %in1, <8 x i16> %in1, <4 x i32> <i32 5, i32 5, i32 5, i32 5>
720 %mul = mul <4 x i16> %shuffle, %shuffle1
724 define <8 x i8> @pr19730(<16 x i8> %in0) {
725 ; CHECK-LABEL: @pr19730(
726 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <16 x i8> [[IN0:%.*]], <16 x i8> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
727 ; CHECK-NEXT: [[SHUFFLE1:%.*]] = shufflevector <8 x i8> [[SHUFFLE]], <8 x i8> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
728 ; CHECK-NEXT: ret <8 x i8> [[SHUFFLE1]]
730 %shuffle = shufflevector <16 x i8> %in0, <16 x i8> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
731 %shuffle1 = shufflevector <8 x i8> %shuffle, <8 x i8> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
732 ret <8 x i8> %shuffle1
735 define i32 @pr19737(<4 x i32> %in0) {
736 ; CHECK-LABEL: @pr19737(
737 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x i32> [[IN0:%.*]], i32 0
738 ; CHECK-NEXT: ret i32 [[TMP1]]
740 %shuffle.i = shufflevector <4 x i32> zeroinitializer, <4 x i32> %in0, <4 x i32> <i32 0, i32 4, i32 2, i32 6>
741 %neg.i = xor <4 x i32> %shuffle.i, <i32 -1, i32 -1, i32 -1, i32 -1>
742 %and.i = and <4 x i32> %in0, %neg.i
743 %rv = extractelement <4 x i32> %and.i, i32 0
747 ; In PR20059 ( http://llvm.org/pr20059 ), shufflevector operations are reordered/removed
748 ; for an srem operation. This is not a valid optimization because it may cause a trap
751 define <4 x i32> @pr20059(<4 x i32> %p1, <4 x i32> %p2) {
752 ; CHECK-LABEL: @pr20059(
753 ; CHECK-NEXT: [[SPLAT1:%.*]] = shufflevector <4 x i32> [[P1:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
754 ; CHECK-NEXT: [[SPLAT2:%.*]] = shufflevector <4 x i32> [[P2:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
755 ; CHECK-NEXT: [[RETVAL:%.*]] = srem <4 x i32> [[SPLAT1]], [[SPLAT2]]
756 ; CHECK-NEXT: ret <4 x i32> [[RETVAL]]
758 %splat1 = shufflevector <4 x i32> %p1, <4 x i32> undef, <4 x i32> zeroinitializer
759 %splat2 = shufflevector <4 x i32> %p2, <4 x i32> undef, <4 x i32> zeroinitializer
760 %retval = srem <4 x i32> %splat1, %splat2
761 ret <4 x i32> %retval
764 define <4 x i32> @pr20114(<4 x i32> %__mask) {
765 ; CHECK-LABEL: @pr20114(
766 ; CHECK-NEXT: [[MASK01_I:%.*]] = shufflevector <4 x i32> [[__MASK:%.*]], <4 x i32> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 1>
767 ; CHECK-NEXT: [[MASKED_NEW_I_I_I:%.*]] = and <4 x i32> [[MASK01_I]], bitcast (<2 x i64> <i64 ptrtoint (<4 x i32> (<4 x i32>)* @pr20114 to i64), i64 ptrtoint (<4 x i32> (<4 x i32>)* @pr20114 to i64)> to <4 x i32>)
768 ; CHECK-NEXT: ret <4 x i32> [[MASKED_NEW_I_I_I]]
770 %mask01.i = shufflevector <4 x i32> %__mask, <4 x i32> undef, <4 x i32> <i32 0, i32 0, i32 1, i32 1>
771 %masked_new.i.i.i = and <4 x i32> bitcast (<2 x i64> <i64 ptrtoint (<4 x i32> (<4 x i32>)* @pr20114 to i64), i64 ptrtoint (<4 x i32> (<4 x i32>)* @pr20114 to i64)> to <4 x i32>), %mask01.i
772 ret <4 x i32> %masked_new.i.i.i
775 define <2 x i32*> @pr23113(<4 x i32*> %A) {
776 ; CHECK-LABEL: @pr23113(
777 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32*> [[A:%.*]], <4 x i32*> undef, <2 x i32> <i32 0, i32 1>
778 ; CHECK-NEXT: ret <2 x i32*> [[TMP1]]
780 %1 = shufflevector <4 x i32*> %A, <4 x i32*> undef, <2 x i32> <i32 0, i32 1>
784 ; Unused lanes in the new binop should not kill the entire op (although it may simplify anyway as shown here).
786 define <2 x i32> @PR37648(<2 x i32> %x) {
787 ; CHECK-LABEL: @PR37648(
788 ; CHECK-NEXT: ret <2 x i32> zeroinitializer
790 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
791 %r = urem <2 x i32> %splat, <i32 1, i32 1>
795 ; Test shuffle followed by binop with splat constant for all 18 binop opcodes.
796 ; Test with constant as operand 0 and operand 1 for non-commutative opcodes.
798 define <2 x i32> @add_splat_constant(<2 x i32> %x) {
799 ; CHECK-LABEL: @add_splat_constant(
800 ; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> [[X:%.*]], <i32 42, i32 undef>
801 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
802 ; CHECK-NEXT: ret <2 x i32> [[R]]
804 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
805 %r = add <2 x i32> %splat, <i32 42, i32 42>
809 define <2 x i32> @sub_splat_constant0(<2 x i32> %x) {
810 ; CHECK-LABEL: @sub_splat_constant0(
811 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> <i32 42, i32 undef>, [[X:%.*]]
812 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
813 ; CHECK-NEXT: ret <2 x i32> [[R]]
815 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
816 %r = sub <2 x i32> <i32 42, i32 42>, %splat
820 define <2 x i32> @sub_splat_constant1(<2 x i32> %x) {
821 ; CHECK-LABEL: @sub_splat_constant1(
822 ; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> [[X:%.*]], <i32 -42, i32 undef>
823 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
824 ; CHECK-NEXT: ret <2 x i32> [[R]]
826 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
827 %r = sub <2 x i32> %splat, <i32 42, i32 42>
831 define <2 x i32> @mul_splat_constant(<2 x i32> %x) {
832 ; CHECK-LABEL: @mul_splat_constant(
833 ; CHECK-NEXT: [[TMP1:%.*]] = mul <2 x i32> [[X:%.*]], <i32 42, i32 undef>
834 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
835 ; CHECK-NEXT: ret <2 x i32> [[R]]
837 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
838 %r = mul <2 x i32> %splat, <i32 42, i32 42>
842 define <2 x i32> @shl_splat_constant0(<2 x i32> %x) {
843 ; CHECK-LABEL: @shl_splat_constant0(
844 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> <i32 5, i32 undef>, [[X:%.*]]
845 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
846 ; CHECK-NEXT: ret <2 x i32> [[R]]
848 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
849 %r = shl <2 x i32> <i32 5, i32 5>, %splat
853 define <2 x i32> @shl_splat_constant1(<2 x i32> %x) {
854 ; CHECK-LABEL: @shl_splat_constant1(
855 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[X:%.*]], <i32 5, i32 0>
856 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
857 ; CHECK-NEXT: ret <2 x i32> [[R]]
859 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
860 %r = shl <2 x i32> %splat, <i32 5, i32 5>
864 define <2 x i32> @ashr_splat_constant0(<2 x i32> %x) {
865 ; CHECK-LABEL: @ashr_splat_constant0(
866 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> <i32 5, i32 undef>, [[X:%.*]]
867 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
868 ; CHECK-NEXT: ret <2 x i32> [[R]]
870 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
871 %r = ashr <2 x i32> <i32 5, i32 5>, %splat
875 define <2 x i32> @ashr_splat_constant1(<2 x i32> %x) {
876 ; CHECK-LABEL: @ashr_splat_constant1(
877 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> [[X:%.*]], <i32 5, i32 0>
878 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
879 ; CHECK-NEXT: ret <2 x i32> [[R]]
881 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
882 %r = ashr <2 x i32> %splat, <i32 5, i32 5>
886 define <2 x i32> @lshr_splat_constant0(<2 x i32> %x) {
887 ; CHECK-LABEL: @lshr_splat_constant0(
888 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> <i32 5, i32 undef>, [[X:%.*]]
889 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
890 ; CHECK-NEXT: ret <2 x i32> [[R]]
892 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
893 %r = lshr <2 x i32> <i32 5, i32 5>, %splat
897 define <2 x i32> @lshr_splat_constant1(<2 x i32> %x) {
898 ; CHECK-LABEL: @lshr_splat_constant1(
899 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 5, i32 0>
900 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
901 ; CHECK-NEXT: ret <2 x i32> [[R]]
903 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
904 %r = lshr <2 x i32> %splat, <i32 5, i32 5>
908 define <2 x i32> @urem_splat_constant0(<2 x i32> %x) {
909 ; CHECK-LABEL: @urem_splat_constant0(
910 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> undef, <2 x i32> zeroinitializer
911 ; CHECK-NEXT: [[R:%.*]] = urem <2 x i32> <i32 42, i32 42>, [[SPLAT]]
912 ; CHECK-NEXT: ret <2 x i32> [[R]]
914 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
915 %r = urem <2 x i32> <i32 42, i32 42>, %splat
919 define <2 x i32> @urem_splat_constant1(<2 x i32> %x) {
920 ; CHECK-LABEL: @urem_splat_constant1(
921 ; CHECK-NEXT: [[TMP1:%.*]] = urem <2 x i32> [[X:%.*]], <i32 42, i32 1>
922 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
923 ; CHECK-NEXT: ret <2 x i32> [[R]]
925 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
926 %r = urem <2 x i32> %splat, <i32 42, i32 42>
930 define <2 x i32> @srem_splat_constant0(<2 x i32> %x) {
931 ; CHECK-LABEL: @srem_splat_constant0(
932 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> undef, <2 x i32> zeroinitializer
933 ; CHECK-NEXT: [[R:%.*]] = srem <2 x i32> <i32 42, i32 42>, [[SPLAT]]
934 ; CHECK-NEXT: ret <2 x i32> [[R]]
936 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
937 %r = srem <2 x i32> <i32 42, i32 42>, %splat
941 define <2 x i32> @srem_splat_constant1(<2 x i32> %x) {
942 ; CHECK-LABEL: @srem_splat_constant1(
943 ; CHECK-NEXT: [[TMP1:%.*]] = srem <2 x i32> [[X:%.*]], <i32 42, i32 1>
944 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
945 ; CHECK-NEXT: ret <2 x i32> [[R]]
947 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
948 %r = srem <2 x i32> %splat, <i32 42, i32 42>
952 define <2 x i32> @udiv_splat_constant0(<2 x i32> %x) {
953 ; CHECK-LABEL: @udiv_splat_constant0(
954 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> undef, <2 x i32> zeroinitializer
955 ; CHECK-NEXT: [[R:%.*]] = udiv <2 x i32> <i32 42, i32 42>, [[SPLAT]]
956 ; CHECK-NEXT: ret <2 x i32> [[R]]
958 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
959 %r = udiv <2 x i32> <i32 42, i32 42>, %splat
963 define <2 x i32> @udiv_splat_constant1(<2 x i32> %x) {
964 ; CHECK-LABEL: @udiv_splat_constant1(
965 ; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i32> [[X:%.*]], <i32 42, i32 1>
966 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
967 ; CHECK-NEXT: ret <2 x i32> [[R]]
969 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
970 %r = udiv <2 x i32> %splat, <i32 42, i32 42>
974 define <2 x i32> @sdiv_splat_constant0(<2 x i32> %x) {
975 ; CHECK-LABEL: @sdiv_splat_constant0(
976 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> undef, <2 x i32> zeroinitializer
977 ; CHECK-NEXT: [[R:%.*]] = sdiv <2 x i32> <i32 42, i32 42>, [[SPLAT]]
978 ; CHECK-NEXT: ret <2 x i32> [[R]]
980 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
981 %r = sdiv <2 x i32> <i32 42, i32 42>, %splat
985 define <2 x i32> @sdiv_splat_constant1(<2 x i32> %x) {
986 ; CHECK-LABEL: @sdiv_splat_constant1(
987 ; CHECK-NEXT: [[TMP1:%.*]] = sdiv <2 x i32> [[X:%.*]], <i32 42, i32 1>
988 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
989 ; CHECK-NEXT: ret <2 x i32> [[R]]
991 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
992 %r = sdiv <2 x i32> %splat, <i32 42, i32 42>
996 define <2 x i32> @and_splat_constant(<2 x i32> %x) {
997 ; CHECK-LABEL: @and_splat_constant(
998 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X:%.*]], <i32 42, i32 undef>
999 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
1000 ; CHECK-NEXT: ret <2 x i32> [[R]]
1002 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
1003 %r = and <2 x i32> %splat, <i32 42, i32 42>
1007 define <2 x i32> @or_splat_constant(<2 x i32> %x) {
1008 ; CHECK-LABEL: @or_splat_constant(
1009 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[X:%.*]], <i32 42, i32 undef>
1010 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
1011 ; CHECK-NEXT: ret <2 x i32> [[R]]
1013 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
1014 %r = or <2 x i32> %splat, <i32 42, i32 42>
1018 define <2 x i32> @xor_splat_constant(<2 x i32> %x) {
1019 ; CHECK-LABEL: @xor_splat_constant(
1020 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[X:%.*]], <i32 42, i32 undef>
1021 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> undef, <2 x i32> zeroinitializer
1022 ; CHECK-NEXT: ret <2 x i32> [[R]]
1024 %splat = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> zeroinitializer
1025 %r = xor <2 x i32> %splat, <i32 42, i32 42>
1029 define <2 x float> @fadd_splat_constant(<2 x float> %x) {
1030 ; CHECK-LABEL: @fadd_splat_constant(
1031 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <2 x float> [[X:%.*]], <float 4.200000e+01, float undef>
1032 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1033 ; CHECK-NEXT: ret <2 x float> [[R]]
1035 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1036 %r = fadd <2 x float> %splat, <float 42.0, float 42.0>
1040 define <2 x float> @fsub_splat_constant0(<2 x float> %x) {
1041 ; CHECK-LABEL: @fsub_splat_constant0(
1042 ; CHECK-NEXT: [[TMP1:%.*]] = fsub <2 x float> <float 4.200000e+01, float undef>, [[X:%.*]]
1043 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1044 ; CHECK-NEXT: ret <2 x float> [[R]]
1046 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1047 %r = fsub <2 x float> <float 42.0, float 42.0>, %splat
1051 define <2 x float> @fsub_splat_constant1(<2 x float> %x) {
1052 ; CHECK-LABEL: @fsub_splat_constant1(
1053 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <2 x float> [[X:%.*]], <float -4.200000e+01, float undef>
1054 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1055 ; CHECK-NEXT: ret <2 x float> [[R]]
1057 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1058 %r = fsub <2 x float> %splat, <float 42.0, float 42.0>
1062 define <2 x float> @fneg(<2 x float> %x) {
1063 ; CHECK-LABEL: @fneg(
1064 ; CHECK-NEXT: [[TMP1:%.*]] = fsub <2 x float> <float -0.000000e+00, float undef>, [[X:%.*]]
1065 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1066 ; CHECK-NEXT: ret <2 x float> [[R]]
1068 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1069 %r = fsub <2 x float> <float -0.0, float -0.0>, %splat
1073 define <2 x float> @fmul_splat_constant(<2 x float> %x) {
1074 ; CHECK-LABEL: @fmul_splat_constant(
1075 ; CHECK-NEXT: [[TMP1:%.*]] = fmul <2 x float> [[X:%.*]], <float 4.200000e+01, float undef>
1076 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1077 ; CHECK-NEXT: ret <2 x float> [[R]]
1079 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1080 %r = fmul <2 x float> %splat, <float 42.0, float 42.0>
1084 define <2 x float> @fdiv_splat_constant0(<2 x float> %x) {
1085 ; CHECK-LABEL: @fdiv_splat_constant0(
1086 ; CHECK-NEXT: [[TMP1:%.*]] = fdiv <2 x float> <float 4.200000e+01, float undef>, [[X:%.*]]
1087 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1088 ; CHECK-NEXT: ret <2 x float> [[R]]
1090 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1091 %r = fdiv <2 x float> <float 42.0, float 42.0>, %splat
1095 define <2 x float> @fdiv_splat_constant1(<2 x float> %x) {
1096 ; CHECK-LABEL: @fdiv_splat_constant1(
1097 ; CHECK-NEXT: [[TMP1:%.*]] = fdiv <2 x float> [[X:%.*]], <float 4.200000e+01, float undef>
1098 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1099 ; CHECK-NEXT: ret <2 x float> [[R]]
1101 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1102 %r = fdiv <2 x float> %splat, <float 42.0, float 42.0>
1106 define <2 x float> @frem_splat_constant0(<2 x float> %x) {
1107 ; CHECK-LABEL: @frem_splat_constant0(
1108 ; CHECK-NEXT: [[TMP1:%.*]] = frem <2 x float> <float 4.200000e+01, float undef>, [[X:%.*]]
1109 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1110 ; CHECK-NEXT: ret <2 x float> [[R]]
1112 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1113 %r = frem <2 x float> <float 42.0, float 42.0>, %splat
1117 define <2 x float> @frem_splat_constant1(<2 x float> %x) {
1118 ; CHECK-LABEL: @frem_splat_constant1(
1119 ; CHECK-NEXT: [[TMP1:%.*]] = frem <2 x float> [[X:%.*]], <float 4.200000e+01, float undef>
1120 ; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
1121 ; CHECK-NEXT: ret <2 x float> [[R]]
1123 %splat = shufflevector <2 x float> %x, <2 x float> undef, <2 x i32> zeroinitializer
1124 %r = frem <2 x float> %splat, <float 42.0, float 42.0>
1128 ; Equivalent shuffle masks, but only one is a narrowing op.
1130 define <2 x i1> @PR40734(<1 x i1> %x, <4 x i1> %y) {
1131 ; CHECK-LABEL: @PR40734(
1132 ; CHECK-NEXT: [[WIDEN:%.*]] = shufflevector <1 x i1> zeroinitializer, <1 x i1> [[X:%.*]], <2 x i32> <i32 0, i32 1>
1133 ; CHECK-NEXT: [[NARROW:%.*]] = shufflevector <4 x i1> [[Y:%.*]], <4 x i1> undef, <2 x i32> <i32 0, i32 1>
1134 ; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[WIDEN]], [[NARROW]]
1135 ; CHECK-NEXT: ret <2 x i1> [[R]]
1137 %widen = shufflevector <1 x i1> zeroinitializer, <1 x i1> %x, <2 x i32> <i32 0, i32 1>
1138 %narrow = shufflevector <4 x i1> %y, <4 x i1> undef, <2 x i32> <i32 0, i32 1>
1139 %r = and <2 x i1> %widen, %narrow
1143 ; Negative test - do not transform non-power-of-2 unless we know the backend handles these sequences identically.
1145 define <7 x i8> @insert_subvector_shuffles(<3 x i8> %x, <3 x i8> %y) {
1146 ; CHECK-LABEL: @insert_subvector_shuffles(
1147 ; CHECK-NEXT: [[S1:%.*]] = shufflevector <3 x i8> [[X:%.*]], <3 x i8> undef, <7 x i32> <i32 0, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1148 ; CHECK-NEXT: [[S2:%.*]] = shufflevector <3 x i8> [[Y:%.*]], <3 x i8> undef, <7 x i32> <i32 undef, i32 1, i32 2, i32 undef, i32 undef, i32 undef, i32 undef>
1149 ; CHECK-NEXT: [[S3:%.*]] = shufflevector <7 x i8> [[S1]], <7 x i8> [[S2]], <7 x i32> <i32 0, i32 8, i32 1, i32 undef, i32 8, i32 1, i32 9>
1150 ; CHECK-NEXT: ret <7 x i8> [[S3]]
1152 %s1 = shufflevector <3 x i8> %x, <3 x i8> undef, <7 x i32> <i32 0, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1153 %s2 = shufflevector <3 x i8> %y, <3 x i8> undef, <7 x i32> <i32 undef, i32 1, i32 2, i32 undef, i32 undef, i32 undef, i32 undef>
1154 %s3 = shufflevector <7 x i8> %s1, <7 x i8> %s2, <7 x i32> <i32 0, i32 8, i32 1, i32 undef, i32 8, i32 1, i32 9>
1158 define <8 x i8> @insert_subvector_shuffles_pow2elts(<2 x i8> %x, <2 x i8> %y) {
1159 ; CHECK-LABEL: @insert_subvector_shuffles_pow2elts(
1160 ; CHECK-NEXT: [[S3:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]], <8 x i32> <i32 0, i32 2, i32 1, i32 undef, i32 2, i32 1, i32 3, i32 0>
1161 ; CHECK-NEXT: ret <8 x i8> [[S3]]
1163 %s1 = shufflevector <2 x i8> %x, <2 x i8> undef, <8 x i32> <i32 0, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1164 %s2 = shufflevector <2 x i8> %y, <2 x i8> undef, <8 x i32> <i32 0, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1165 %s3 = shufflevector <8 x i8> %s1, <8 x i8> %s2, <8 x i32> <i32 0, i32 8, i32 1, i32 undef, i32 8, i32 1, i32 9, i32 0>
1169 ; The last shuffle may change the vector type.
1170 ; Negative test - do not transform non-power-of-2 unless we know the backend handles these sequences identically.
1172 define <2 x i8> @insert_subvector_shuffles_narrowing(<3 x i8> %x, <3 x i8> %y) {
1173 ; CHECK-LABEL: @insert_subvector_shuffles_narrowing(
1174 ; CHECK-NEXT: [[S1:%.*]] = shufflevector <3 x i8> [[X:%.*]], <3 x i8> undef, <7 x i32> <i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1175 ; CHECK-NEXT: [[S2:%.*]] = shufflevector <3 x i8> [[Y:%.*]], <3 x i8> undef, <7 x i32> <i32 undef, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1176 ; CHECK-NEXT: [[S3:%.*]] = shufflevector <7 x i8> [[S1]], <7 x i8> [[S2]], <2 x i32> <i32 0, i32 8>
1177 ; CHECK-NEXT: ret <2 x i8> [[S3]]
1179 %s1 = shufflevector <3 x i8> %x, <3 x i8> undef, <7 x i32> <i32 0, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1180 %s2 = shufflevector <3 x i8> %y, <3 x i8> undef, <7 x i32> <i32 undef, i32 1, i32 2, i32 undef, i32 undef, i32 undef, i32 undef>
1181 %s3 = shufflevector <7 x i8> %s1, <7 x i8> %s2, <2 x i32> <i32 0, i32 8>
1185 define <2 x i8> @insert_subvector_shuffles_narrowing_pow2elts(<4 x i8> %x, <4 x i8> %y) {
1186 ; CHECK-LABEL: @insert_subvector_shuffles_narrowing_pow2elts(
1187 ; CHECK-NEXT: [[S3:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 4>
1188 ; CHECK-NEXT: ret <2 x i8> [[S3]]
1190 %s1 = shufflevector <4 x i8> %x, <4 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
1191 %s2 = shufflevector <4 x i8> %y, <4 x i8> undef, <8 x i32> <i32 0, i32 1, i32 undef, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
1192 %s3 = shufflevector <8 x i8> %s1, <8 x i8> %s2, <2 x i32> <i32 0, i32 8>
1196 ; Similar to above, but this reduces to a widen with undefs of 'x'.
1198 define <4 x double> @insert_subvector_shuffles_identity(<2 x double> %x) {
1199 ; CHECK-LABEL: @insert_subvector_shuffles_identity(
1200 ; CHECK-NEXT: [[S3:%.*]] = shufflevector <2 x double> [[X:%.*]], <2 x double> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
1201 ; CHECK-NEXT: ret <4 x double> [[S3]]
1203 %s1 = shufflevector <2 x double> %x, <2 x double> undef, <4 x i32> <i32 undef, i32 1, i32 undef, i32 undef>
1204 %s2 = shufflevector <2 x double> %x, <2 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
1205 %s3 = shufflevector <4 x double> %s2, <4 x double> %s1, <4 x i32> <i32 0, i32 5, i32 undef, i32 undef>
1206 ret <4 x double> %s3
1209 ; Negative test - not identity with padding (although this could be folded with better analysis).
1211 define <4 x double> @not_insert_subvector_shuffle(<2 x double> %x) {
1212 ; CHECK-LABEL: @not_insert_subvector_shuffle(
1213 ; CHECK-NEXT: [[S1:%.*]] = shufflevector <2 x double> [[X:%.*]], <2 x double> undef, <4 x i32> <i32 undef, i32 1, i32 undef, i32 1>
1214 ; CHECK-NEXT: [[S2:%.*]] = shufflevector <2 x double> [[X]], <2 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
1215 ; CHECK-NEXT: [[S3:%.*]] = shufflevector <4 x double> [[S2]], <4 x double> [[S1]], <4 x i32> <i32 0, i32 5, i32 7, i32 undef>
1216 ; CHECK-NEXT: ret <4 x double> [[S3]]
1218 %s1 = shufflevector <2 x double> %x, <2 x double> undef, <4 x i32> <i32 undef, i32 1, i32 undef, i32 1>
1219 %s2 = shufflevector <2 x double> %x, <2 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
1220 %s3 = shufflevector <4 x double> %s2, <4 x double> %s1, <4 x i32> <i32 0, i32 5, i32 7, i32 undef>
1221 ret <4 x double> %s3
1224 ; Negative test - operands are not the same size (although this could be partly folded with better analysis).
1226 define <4 x double> @not_insert_subvector_shuffles_with_same_size(<2 x double> %x, <3 x double> %y) {
1227 ; CHECK-LABEL: @not_insert_subvector_shuffles_with_same_size(
1228 ; CHECK-NEXT: [[S1:%.*]] = shufflevector <2 x double> [[X:%.*]], <2 x double> undef, <4 x i32> <i32 undef, i32 1, i32 undef, i32 undef>
1229 ; CHECK-NEXT: [[S2:%.*]] = shufflevector <3 x double> [[Y:%.*]], <3 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
1230 ; CHECK-NEXT: [[S3:%.*]] = shufflevector <4 x double> [[S2]], <4 x double> [[S1]], <4 x i32> <i32 0, i32 5, i32 undef, i32 undef>
1231 ; CHECK-NEXT: ret <4 x double> [[S3]]
1233 %s1 = shufflevector <2 x double> %x, <2 x double> undef, <4 x i32> <i32 undef, i32 1, i32 undef, i32 undef>
1234 %s2 = shufflevector <3 x double> %y, <3 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
1235 %s3 = shufflevector <4 x double> %s2, <4 x double> %s1, <4 x i32> <i32 0, i32 5, i32 undef, i32 undef>
1236 ret <4 x double> %s3
1239 ; Demanded vector elements may not be able to simplify a shuffle mask
1240 ; before we try to narrow it. This used to crash.
1242 define <4 x float> @insert_subvector_crash_invalid_mask_elt(<2 x float> %x, <4 x float>* %p) {
1243 ; CHECK-LABEL: @insert_subvector_crash_invalid_mask_elt(
1244 ; CHECK-NEXT: [[WIDEN:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
1245 ; CHECK-NEXT: [[I:%.*]] = shufflevector <2 x float> [[X]], <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
1246 ; CHECK-NEXT: store <4 x float> [[I]], <4 x float>* [[P:%.*]], align 16
1247 ; CHECK-NEXT: ret <4 x float> [[WIDEN]]
1249 %widen = shufflevector <2 x float> %x, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
1250 %ext2 = extractelement <2 x float> %x, i32 0
1251 %I = insertelement <4 x float> %widen, float %ext2, i16 0
1252 store <4 x float> %I, <4 x float>* %p
1253 ret <4 x float> %widen