1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine %s | FileCheck %s
4 define <1 x i8> @test1(<8 x i8> %in) {
6 ; CHECK-NEXT: [[VEC:%.*]] = shufflevector <8 x i8> [[IN:%.*]], <8 x i8> undef, <1 x i32> <i32 5>
7 ; CHECK-NEXT: ret <1 x i8> [[VEC]]
9 %val = extractelement <8 x i8> %in, i32 5
10 %vec = insertelement <1 x i8> undef, i8 %val, i32 0
14 define <4 x i16> @test2(<8 x i16> %in, <8 x i16> %in2) {
15 ; CHECK-LABEL: @test2(
16 ; CHECK-NEXT: [[VEC_3:%.*]] = shufflevector <8 x i16> [[IN2:%.*]], <8 x i16> [[IN:%.*]], <4 x i32> <i32 11, i32 9, i32 0, i32 10>
17 ; CHECK-NEXT: ret <4 x i16> [[VEC_3]]
19 %elt0 = extractelement <8 x i16> %in, i32 3
20 %elt1 = extractelement <8 x i16> %in, i32 1
21 %elt2 = extractelement <8 x i16> %in2, i32 0
22 %elt3 = extractelement <8 x i16> %in, i32 2
24 %vec.0 = insertelement <4 x i16> undef, i16 %elt0, i32 0
25 %vec.1 = insertelement <4 x i16> %vec.0, i16 %elt1, i32 1
26 %vec.2 = insertelement <4 x i16> %vec.1, i16 %elt2, i32 2
27 %vec.3 = insertelement <4 x i16> %vec.2, i16 %elt3, i32 3
32 define <2 x i64> @test_vcopyq_lane_p64(<2 x i64> %a, <1 x i64> %b) {
33 ; CHECK-LABEL: @test_vcopyq_lane_p64(
34 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <1 x i64> [[B:%.*]], <1 x i64> undef, <2 x i32> <i32 0, i32 undef>
35 ; CHECK-NEXT: [[RES:%.*]] = shufflevector <2 x i64> [[A:%.*]], <2 x i64> [[TMP1]], <2 x i32> <i32 0, i32 2>
36 ; CHECK-NEXT: ret <2 x i64> [[RES]]
38 %elt = extractelement <1 x i64> %b, i32 0
39 %res = insertelement <2 x i64> %a, i64 %elt, i32 1
43 ; PR2109: https://llvm.org/bugs/show_bug.cgi?id=2109
45 define <4 x float> @widen_extract2(<4 x float> %ins, <2 x float> %ext) {
46 ; CHECK-LABEL: @widen_extract2(
47 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[EXT:%.*]], <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
48 ; CHECK-NEXT: [[I2:%.*]] = shufflevector <4 x float> [[INS:%.*]], <4 x float> [[TMP1]], <4 x i32> <i32 0, i32 4, i32 2, i32 5>
49 ; CHECK-NEXT: ret <4 x float> [[I2]]
51 %e1 = extractelement <2 x float> %ext, i32 0
52 %e2 = extractelement <2 x float> %ext, i32 1
53 %i1 = insertelement <4 x float> %ins, float %e1, i32 1
54 %i2 = insertelement <4 x float> %i1, float %e2, i32 3
58 define <4 x float> @widen_extract3(<4 x float> %ins, <3 x float> %ext) {
59 ; CHECK-LABEL: @widen_extract3(
60 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <3 x float> [[EXT:%.*]], <3 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
61 ; CHECK-NEXT: [[I3:%.*]] = shufflevector <4 x float> [[INS:%.*]], <4 x float> [[TMP1]], <4 x i32> <i32 6, i32 5, i32 4, i32 3>
62 ; CHECK-NEXT: ret <4 x float> [[I3]]
64 %e1 = extractelement <3 x float> %ext, i32 0
65 %e2 = extractelement <3 x float> %ext, i32 1
66 %e3 = extractelement <3 x float> %ext, i32 2
67 %i1 = insertelement <4 x float> %ins, float %e1, i32 2
68 %i2 = insertelement <4 x float> %i1, float %e2, i32 1
69 %i3 = insertelement <4 x float> %i2, float %e3, i32 0
73 define <8 x float> @widen_extract4(<8 x float> %ins, <2 x float> %ext) {
74 ; CHECK-LABEL: @widen_extract4(
75 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[EXT:%.*]], <2 x float> undef, <8 x i32> <i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
76 ; CHECK-NEXT: [[I1:%.*]] = shufflevector <8 x float> [[INS:%.*]], <8 x float> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 8, i32 3, i32 4, i32 5, i32 6, i32 7>
77 ; CHECK-NEXT: ret <8 x float> [[I1]]
79 %e1 = extractelement <2 x float> %ext, i32 0
80 %i1 = insertelement <8 x float> %ins, float %e1, i32 2
84 ; PR26015: https://llvm.org/bugs/show_bug.cgi?id=26015
85 ; The widening shuffle must be inserted before any uses.
87 define <8 x i16> @pr26015(<4 x i16> %t0) {
88 ; CHECK-LABEL: @pr26015(
89 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i16> [[T0:%.*]], <4 x i16> undef, <8 x i32> <i32 undef, i32 undef, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
90 ; CHECK-NEXT: [[T5:%.*]] = shufflevector <8 x i16> <i16 0, i16 0, i16 0, i16 undef, i16 0, i16 0, i16 0, i16 undef>, <8 x i16> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 2, i32 10, i32 4, i32 5, i32 6, i32 11>
91 ; CHECK-NEXT: ret <8 x i16> [[T5]]
93 %t1 = extractelement <4 x i16> %t0, i32 2
94 %t2 = insertelement <8 x i16> zeroinitializer, i16 %t1, i32 3
95 %t3 = insertelement <8 x i16> %t2, i16 0, i32 6
96 %t4 = extractelement <4 x i16> %t0, i32 3
97 %t5 = insertelement <8 x i16> %t3, i16 %t4, i32 7
101 ; PR25999: https://llvm.org/bugs/show_bug.cgi?id=25999
102 ; TODO: The widening shuffle could be inserted at the start of the function to allow the first extract to use it.
104 define <8 x i16> @pr25999(<4 x i16> %t0, i1 %b) {
105 ; CHECK-LABEL: @pr25999(
106 ; CHECK-NEXT: [[T1:%.*]] = extractelement <4 x i16> [[T0:%.*]], i32 2
107 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF:%.*]], label [[END:%.*]]
109 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i16> [[T0]], <4 x i16> undef, <8 x i32> <i32 undef, i32 undef, i32 undef, i32 3, i32 undef, i32 undef, i32 undef, i32 undef>
110 ; CHECK-NEXT: [[T3:%.*]] = insertelement <8 x i16> <i16 0, i16 0, i16 0, i16 undef, i16 0, i16 0, i16 0, i16 undef>, i16 [[T1]], i32 3
111 ; CHECK-NEXT: [[T5:%.*]] = shufflevector <8 x i16> [[T3]], <8 x i16> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 11>
112 ; CHECK-NEXT: ret <8 x i16> [[T5]]
114 ; CHECK-NEXT: [[A1:%.*]] = add i16 [[T1]], 4
115 ; CHECK-NEXT: [[T6:%.*]] = insertelement <8 x i16> <i16 undef, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>, i16 [[A1]], i32 0
116 ; CHECK-NEXT: ret <8 x i16> [[T6]]
119 %t1 = extractelement <4 x i16> %t0, i32 2
120 br i1 %b, label %if, label %end
123 %t2 = insertelement <8 x i16> zeroinitializer, i16 %t1, i32 3
124 %t3 = insertelement <8 x i16> %t2, i16 0, i32 6
125 %t4 = extractelement <4 x i16> %t0, i32 3
126 %t5 = insertelement <8 x i16> %t3, i16 %t4, i32 7
131 %t6 = insertelement <8 x i16> zeroinitializer, i16 %a1, i32 0
135 ; The widening shuffle must be inserted at a valid point (after the PHIs).
137 define <4 x double> @pr25999_phis1(i1 %c, <2 x double> %a, <4 x double> %b) {
138 ; CHECK-LABEL: @pr25999_phis1(
140 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB2:%.*]], label [[BB3:%.*]]
142 ; CHECK-NEXT: [[R:%.*]] = call <2 x double> @dummy(<2 x double> [[A:%.*]])
143 ; CHECK-NEXT: br label [[BB3]]
145 ; CHECK-NEXT: [[TMP1:%.*]] = phi <2 x double> [ [[A]], [[BB1:%.*]] ], [ [[R]], [[BB2]] ]
146 ; CHECK-NEXT: [[TMP2:%.*]] = phi <4 x double> [ [[B:%.*]], [[BB1]] ], [ zeroinitializer, [[BB2]] ]
147 ; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x double> [[TMP1]], <2 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
148 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x double> [[TMP2]], <4 x double> [[TMP0]], <4 x i32> <i32 0, i32 1, i32 4, i32 3>
149 ; CHECK-NEXT: ret <4 x double> [[TMP4]]
152 br i1 %c, label %bb2, label %bb3
155 %r = call <2 x double> @dummy(<2 x double> %a)
159 %tmp1 = phi <2 x double> [ %a, %bb1 ], [ %r, %bb2 ]
160 %tmp2 = phi <4 x double> [ %b, %bb1 ], [ zeroinitializer, %bb2 ]
161 %tmp3 = extractelement <2 x double> %tmp1, i32 0
162 %tmp4 = insertelement <4 x double> %tmp2, double %tmp3, i32 2
163 ret <4 x double> %tmp4
166 declare <2 x double> @dummy(<2 x double>)
168 define <4 x double> @pr25999_phis2(i1 %c, <2 x double> %a, <4 x double> %b) {
169 ; CHECK-LABEL: @pr25999_phis2(
171 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB2:%.*]], label [[BB3:%.*]]
173 ; CHECK-NEXT: [[R:%.*]] = call <2 x double> @dummy(<2 x double> [[A:%.*]])
174 ; CHECK-NEXT: br label [[BB3]]
176 ; CHECK-NEXT: [[TMP1:%.*]] = phi <2 x double> [ [[A]], [[BB1:%.*]] ], [ [[R]], [[BB2]] ]
177 ; CHECK-NEXT: [[TMP2:%.*]] = phi <4 x double> [ [[B:%.*]], [[BB1]] ], [ zeroinitializer, [[BB2]] ]
178 ; CHECK-NEXT: [[D:%.*]] = fadd <2 x double> [[TMP1]], [[TMP1]]
179 ; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x double> [[D]], <2 x double> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
180 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x double> [[TMP2]], <4 x double> [[TMP0]], <4 x i32> <i32 0, i32 1, i32 4, i32 3>
181 ; CHECK-NEXT: ret <4 x double> [[TMP4]]
184 br i1 %c, label %bb2, label %bb3
187 %r = call <2 x double> @dummy(<2 x double> %a)
191 %tmp1 = phi <2 x double> [ %a, %bb1 ], [ %r, %bb2 ]
192 %tmp2 = phi <4 x double> [ %b, %bb1 ], [ zeroinitializer, %bb2 ]
193 %d = fadd <2 x double> %tmp1, %tmp1
194 %tmp3 = extractelement <2 x double> %d, i32 0
195 %tmp4 = insertelement <4 x double> %tmp2, double %tmp3, i32 2
196 ret <4 x double> %tmp4
199 ; PR26354: https://llvm.org/bugs/show_bug.cgi?id=26354
200 ; Don't create a shufflevector if we know that we're not going to replace the insertelement.
202 define double @pr26354(<2 x double>* %tmp, i1 %B) {
203 ; CHECK-LABEL: @pr26354(
205 ; CHECK-NEXT: [[LD:%.*]] = load <2 x double>, <2 x double>* [[TMP:%.*]], align 16
206 ; CHECK-NEXT: [[E1:%.*]] = extractelement <2 x double> [[LD]], i32 0
207 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF:%.*]], label [[END:%.*]]
209 ; CHECK-NEXT: [[E2:%.*]] = extractelement <2 x double> [[LD]], i32 1
210 ; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x double> <double 0.000000e+00, double 0.000000e+00, double 0.000000e+00, double undef>, double [[E2]], i32 3
211 ; CHECK-NEXT: br label [[END]]
213 ; CHECK-NEXT: [[PH:%.*]] = phi <4 x double> [ undef, [[ENTRY:%.*]] ], [ [[I1]], [[IF]] ]
214 ; CHECK-NEXT: [[E3:%.*]] = extractelement <4 x double> [[PH]], i32 1
215 ; CHECK-NEXT: [[MU:%.*]] = fmul double [[E1]], [[E3]]
216 ; CHECK-NEXT: ret double [[MU]]
220 %ld = load <2 x double>, <2 x double>* %tmp
221 %e1 = extractelement <2 x double> %ld, i32 0
222 %e2 = extractelement <2 x double> %ld, i32 1
223 br i1 %B, label %if, label %end
226 %i1 = insertelement <4 x double> zeroinitializer, double %e2, i32 3
230 %ph = phi <4 x double> [ undef, %entry ], [ %i1, %if ]
231 %e3 = extractelement <4 x double> %ph, i32 1
232 %mu = fmul double %e1, %e3
236 ; https://llvm.org/bugs/show_bug.cgi?id=30923
237 ; Delete the widening shuffle if we're not going to reduce the extract/insert to a shuffle.
239 define <4 x float> @PR30923(<2 x float> %x) {
240 ; CHECK-LABEL: @PR30923(
242 ; CHECK-NEXT: [[EXT1:%.*]] = extractelement <2 x float> [[X:%.*]], i32 1
243 ; CHECK-NEXT: store float [[EXT1]], float* undef, align 4
244 ; CHECK-NEXT: br label [[BB2:%.*]]
246 ; CHECK-NEXT: [[EXT2:%.*]] = extractelement <2 x float> [[X]], i32 0
247 ; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> <float 0.000000e+00, float 0.000000e+00, float undef, float undef>, float [[EXT2]], i32 2
248 ; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float [[EXT1]], i32 3
249 ; CHECK-NEXT: ret <4 x float> [[INS2]]
252 %ext1 = extractelement <2 x float> %x, i32 1
253 store float %ext1, float* undef, align 4
257 %widen = shufflevector <2 x float> %x, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
258 %ext2 = extractelement <4 x float> %widen, i32 0
259 %ins1 = insertelement <4 x float> <float 0.0, float 0.0, float undef, float undef>, float %ext2, i32 2
260 %ins2 = insertelement <4 x float> %ins1, float %ext1, i32 3
261 ret <4 x float> %ins2
264 ; Don't insert extractelements from the wider vector before the def of the index operand.
266 define <4 x i32> @extractelt_insertion(<2 x i32> %x, i32 %y) {
267 ; CHECK-LABEL: @extractelt_insertion(
269 ; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
270 ; CHECK-NEXT: [[B:%.*]] = shufflevector <4 x i32> <i32 0, i32 0, i32 0, i32 undef>, <4 x i32> [[TMP0]], <4 x i32> <i32 0, i32 1, i32 2, i32 5>
271 ; CHECK-NEXT: [[C:%.*]] = add i32 [[Y:%.*]], 3
272 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x i32> [[TMP0]], i32 [[C]]
273 ; CHECK-NEXT: [[E:%.*]] = icmp eq i32 [[TMP1]], 0
274 ; CHECK-NEXT: [[RET:%.*]] = select i1 [[E]], <4 x i32> [[B]], <4 x i32> zeroinitializer
275 ; CHECK-NEXT: ret <4 x i32> [[RET]]
278 %a = extractelement <2 x i32> %x, i32 1
279 %b = insertelement <4 x i32> zeroinitializer, i32 %a, i64 3
281 %d = extractelement <2 x i32> %x, i32 %c
282 %e = icmp eq i32 %d, 0
283 %ret = select i1 %e, <4 x i32> %b, <4 x i32> zeroinitializer
287 ; PR34724: https://bugs.llvm.org/show_bug.cgi?id=34724
289 define <4 x float> @collectShuffleElts(<2 x float> %x, float %y) {
290 ; CHECK-LABEL: @collectShuffleElts(
291 ; CHECK-NEXT: [[X0:%.*]] = extractelement <2 x float> [[X:%.*]], i32 0
292 ; CHECK-NEXT: [[X1:%.*]] = extractelement <2 x float> [[X]], i32 1
293 ; CHECK-NEXT: [[V1:%.*]] = insertelement <4 x float> undef, float [[X0]], i32 1
294 ; CHECK-NEXT: [[V2:%.*]] = insertelement <4 x float> [[V1]], float [[X1]], i32 2
295 ; CHECK-NEXT: [[V3:%.*]] = insertelement <4 x float> [[V2]], float [[Y:%.*]], i32 3
296 ; CHECK-NEXT: ret <4 x float> [[V3]]
298 %x0 = extractelement <2 x float> %x, i32 0
299 %x1 = extractelement <2 x float> %x, i32 1
300 %v1 = insertelement <4 x float> undef, float %x0, i32 1
301 %v2 = insertelement <4 x float> %v1, float %x1, i32 2
302 %v3 = insertelement <4 x float> %v2, float %y, i32 3
306 ; Simplest case - insert scalar into undef, then shuffle that value in place into another vector.
308 define <4 x float> @insert_shuffle(float %x, <4 x float> %y) {
309 ; CHECK-LABEL: @insert_shuffle(
310 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[X:%.*]], i32 0
311 ; CHECK-NEXT: ret <4 x float> [[R]]
313 %xv = insertelement <4 x float> undef, float %x, i32 0
314 %r = shufflevector <4 x float> %xv, <4 x float> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7>
318 ; Insert scalar into some element of a dummy vector, then move it to a different element in another vector.
320 define <4 x float> @insert_shuffle_translate(float %x, <4 x float> %y) {
321 ; CHECK-LABEL: @insert_shuffle_translate(
322 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[X:%.*]], i32 1
323 ; CHECK-NEXT: ret <4 x float> [[R]]
325 %xv = insertelement <4 x float> undef, float %x, i32 0
326 %r = shufflevector <4 x float> %xv, <4 x float> %y, <4 x i32> <i32 4, i32 0, i32 6, i32 7>
330 ; The vector operand of the insert is irrelevant.
332 define <4 x float> @insert_not_undef_shuffle_translate(float %x, <4 x float> %y, <4 x float> %q) {
333 ; CHECK-LABEL: @insert_not_undef_shuffle_translate(
334 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[X:%.*]], i32 2
335 ; CHECK-NEXT: ret <4 x float> [[R]]
337 %xv = insertelement <4 x float> %q, float %x, i32 3
338 %r = shufflevector <4 x float> %xv, <4 x float> %y, <4 x i32> <i32 4, i32 5, i32 3, i32 7>
342 ; The insert may be the 2nd operand of the shuffle. The shuffle mask can include undef elements.
344 define <4 x float> @insert_not_undef_shuffle_translate_commute(float %x, <4 x float> %y, <4 x float> %q) {
345 ; CHECK-LABEL: @insert_not_undef_shuffle_translate_commute(
346 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[X:%.*]], i32 1
347 ; CHECK-NEXT: ret <4 x float> [[R]]
349 %xv = insertelement <4 x float> %q, float %x, i32 2
350 %r = shufflevector <4 x float> %y, <4 x float> %xv, <4 x i32> <i32 0, i32 6, i32 2, i32 undef>
354 ; Both shuffle operands may be inserts - choose the correct side.
356 define <4 x float> @insert_insert_shuffle_translate(float %x1, float %x2, <4 x float> %q) {
357 ; CHECK-LABEL: @insert_insert_shuffle_translate(
358 ; CHECK-NEXT: [[XV2:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X2:%.*]], i32 2
359 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[XV2]], float [[X1:%.*]], i32 1
360 ; CHECK-NEXT: ret <4 x float> [[R]]
362 %xv1 = insertelement <4 x float> %q, float %x1, i32 0
363 %xv2 = insertelement <4 x float> %q, float %x2, i32 2
364 %r = shufflevector <4 x float> %xv1, <4 x float> %xv2, <4 x i32> <i32 4, i32 0, i32 6, i32 7>
368 ; Both shuffle operands may be inserts - choose the correct side.
370 define <4 x float> @insert_insert_shuffle_translate_commute(float %x1, float %x2, <4 x float> %q) {
371 ; CHECK-LABEL: @insert_insert_shuffle_translate_commute(
372 ; CHECK-NEXT: [[XV1:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X1:%.*]], i32 0
373 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[XV1]], float [[X2:%.*]], i32 1
374 ; CHECK-NEXT: ret <4 x float> [[R]]
376 %xv1 = insertelement <4 x float> %q, float %x1, i32 0
377 %xv2 = insertelement <4 x float> %q, float %x2, i32 2
378 %r = shufflevector <4 x float> %xv1, <4 x float> %xv2, <4 x i32> <i32 0, i32 6, i32 2, i32 3>
382 ; Negative test - this only works if the shuffle is choosing exactly 1 element from 1 of the inputs.
383 ; TODO: But this could be a special-case because we're inserting into the same base vector.
385 define <4 x float> @insert_insert_shuffle_translate_wrong_mask(float %x1, float %x2, <4 x float> %q) {
386 ; CHECK-LABEL: @insert_insert_shuffle_translate_wrong_mask(
387 ; CHECK-NEXT: [[XV1:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X1:%.*]], i32 0
388 ; CHECK-NEXT: [[XV2:%.*]] = insertelement <4 x float> [[Q]], float [[X2:%.*]], i32 2
389 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV1]], <4 x float> [[XV2]], <4 x i32> <i32 0, i32 6, i32 2, i32 7>
390 ; CHECK-NEXT: ret <4 x float> [[R]]
392 %xv1 = insertelement <4 x float> %q, float %x1, i32 0
393 %xv2 = insertelement <4 x float> %q, float %x2, i32 2
394 %r = shufflevector <4 x float> %xv1, <4 x float> %xv2, <4 x i32> <i32 0, i32 6, i32 2, i32 7>
398 ; The insert may have other uses.
400 declare void @use(<4 x float>)
402 define <4 x float> @insert_not_undef_shuffle_translate_commute_uses(float %x, <4 x float> %y, <4 x float> %q) {
403 ; CHECK-LABEL: @insert_not_undef_shuffle_translate_commute_uses(
404 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> [[Q:%.*]], float [[X:%.*]], i32 2
405 ; CHECK-NEXT: call void @use(<4 x float> [[XV]])
406 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[X]], i32 0
407 ; CHECK-NEXT: ret <4 x float> [[R]]
409 %xv = insertelement <4 x float> %q, float %x, i32 2
410 call void @use(<4 x float> %xv)
411 %r = shufflevector <4 x float> %y, <4 x float> %xv, <4 x i32> <i32 6, i32 undef, i32 2, i32 3>
415 ; Negative test - size-changing shuffle.
417 define <5 x float> @insert_not_undef_shuffle_translate_commute_lengthen(float %x, <4 x float> %y, <4 x float> %q) {
418 ; CHECK-LABEL: @insert_not_undef_shuffle_translate_commute_lengthen(
419 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 2
420 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> [[XV]], <5 x i32> <i32 0, i32 6, i32 2, i32 undef, i32 undef>
421 ; CHECK-NEXT: ret <5 x float> [[R]]
423 %xv = insertelement <4 x float> %q, float %x, i32 2
424 %r = shufflevector <4 x float> %y, <4 x float> %xv, <5 x i32> <i32 0, i32 6, i32 2, i32 undef, i32 undef>
428 define <4 x float> @insert_nonzero_index_splat(float %x) {
429 ; CHECK-LABEL: @insert_nonzero_index_splat(
430 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 0
431 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 undef>
432 ; CHECK-NEXT: ret <4 x float> [[SPLAT]]
434 %xv = insertelement <4 x float> undef, float %x, i32 2
435 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 2, i32 2, i32 undef>
436 ret <4 x float> %splat
439 define <3 x double> @insert_nonzero_index_splat_narrow(double %x) {
440 ; CHECK-LABEL: @insert_nonzero_index_splat_narrow(
441 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> undef, double [[X:%.*]], i32 0
442 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <3 x double> [[TMP1]], <3 x double> undef, <3 x i32> <i32 0, i32 undef, i32 0>
443 ; CHECK-NEXT: ret <3 x double> [[SPLAT]]
445 %xv = insertelement <4 x double> undef, double %x, i32 3
446 %splat = shufflevector <4 x double> %xv, <4 x double> undef, <3 x i32> <i32 3, i32 undef, i32 3>
447 ret <3 x double> %splat
450 define <5 x i7> @insert_nonzero_index_splat_widen(i7 %x) {
451 ; CHECK-LABEL: @insert_nonzero_index_splat_widen(
452 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> undef, i7 [[X:%.*]], i32 0
453 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <5 x i7> [[TMP1]], <5 x i7> undef, <5 x i32> <i32 undef, i32 0, i32 0, i32 undef, i32 0>
454 ; CHECK-NEXT: ret <5 x i7> [[SPLAT]]
456 %xv = insertelement <4 x i7> undef, i7 %x, i32 1
457 %splat = shufflevector <4 x i7> %xv, <4 x i7> undef, <5 x i32> <i32 undef, i32 1, i32 1, i32 undef, i32 1>
461 ; Negative test - don't increase instruction count
463 define <4 x float> @insert_nonzero_index_splat_extra_use(float %x) {
464 ; CHECK-LABEL: @insert_nonzero_index_splat_extra_use(
465 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 2
466 ; CHECK-NEXT: call void @use(<4 x float> [[XV]])
467 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 2, i32 2, i32 undef>
468 ; CHECK-NEXT: ret <4 x float> [[SPLAT]]
470 %xv = insertelement <4 x float> undef, float %x, i32 2
471 call void @use(<4 x float> %xv)
472 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 2, i32 2, i32 undef>
473 ret <4 x float> %splat
476 ; Negative test - non-undef base vector
478 define <4 x float> @insert_nonzero_index_splat_wrong_base(float %x, <4 x float> %y) {
479 ; CHECK-LABEL: @insert_nonzero_index_splat_wrong_base(
480 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[X:%.*]], i32 2
481 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 2, i32 3, i32 undef>
482 ; CHECK-NEXT: ret <4 x float> [[SPLAT]]
484 %xv = insertelement <4 x float> %y, float %x, i32 2
485 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 2, i32 3, i32 undef>
486 ret <4 x float> %splat
489 ; Negative test - non-constant insert index
491 define <4 x float> @insert_nonzero_index_splat_wrong_index(float %x, i32 %index) {
492 ; CHECK-LABEL: @insert_nonzero_index_splat_wrong_index(
493 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 [[INDEX:%.*]]
494 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 1, i32 1, i32 undef>
495 ; CHECK-NEXT: ret <4 x float> [[SPLAT]]
497 %xv = insertelement <4 x float> undef, float %x, i32 %index
498 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 1, i32 1, i32 undef>
499 ret <4 x float> %splat
502 define <4 x float> @insert_in_splat(float %x) {
503 ; CHECK-LABEL: @insert_in_splat(
504 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 0
505 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 0>
506 ; CHECK-NEXT: ret <4 x float> [[R]]
508 %xv = insertelement <4 x float> undef, float %x, i32 0
509 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 undef>
510 %r = insertelement <4 x float> %splat, float %x, i32 3
514 define <4 x float> @insert_in_splat_extra_uses(float %x) {
515 ; CHECK-LABEL: @insert_in_splat_extra_uses(
516 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 0
517 ; CHECK-NEXT: call void @use(<4 x float> [[XV]])
518 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 undef>
519 ; CHECK-NEXT: call void @use(<4 x float> [[SPLAT]])
520 ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 0>
521 ; CHECK-NEXT: ret <4 x float> [[R]]
523 %xv = insertelement <4 x float> undef, float %x, i32 0
524 call void @use(<4 x float> %xv)
525 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 undef>
526 call void @use(<4 x float> %splat)
527 %r = insertelement <4 x float> %splat, float %x, i32 3
531 ; Negative test - not a constant index insert
533 define <4 x float> @insert_in_splat_variable_index(float %x, i32 %y) {
534 ; CHECK-LABEL: @insert_in_splat_variable_index(
535 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 0
536 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 undef>
537 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[SPLAT]], float [[X]], i32 [[Y:%.*]]
538 ; CHECK-NEXT: ret <4 x float> [[R]]
540 %xv = insertelement <4 x float> undef, float %x, i32 0
541 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 undef>
542 %r = insertelement <4 x float> %splat, float %x, i32 %y
546 ; Negative test - not a splat shuffle
548 define <4 x float> @insert_in_nonsplat(float %x, <4 x float> %y) {
549 ; CHECK-LABEL: @insert_in_nonsplat(
550 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i32 0
551 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> [[Y:%.*]], <4 x i32> <i32 undef, i32 0, i32 4, i32 undef>
552 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[SPLAT]], float [[X]], i32 3
553 ; CHECK-NEXT: ret <4 x float> [[R]]
555 %xv = insertelement <4 x float> undef, float %x, i32 0
556 %splat = shufflevector <4 x float> %xv, <4 x float> %y, <4 x i32> <i32 undef, i32 0, i32 4, i32 undef>
557 %r = insertelement <4 x float> %splat, float %x, i32 3
561 ; Negative test - not a splat shuffle
563 define <4 x float> @insert_in_nonsplat2(float %x, <4 x float> %y) {
564 ; CHECK-LABEL: @insert_in_nonsplat2(
565 ; CHECK-NEXT: [[XV:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[X:%.*]], i32 0
566 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[XV]], <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 1, i32 undef>
567 ; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[SPLAT]], float [[X]], i32 3
568 ; CHECK-NEXT: ret <4 x float> [[R]]
570 %xv = insertelement <4 x float> %y, float %x, i32 0
571 %splat = shufflevector <4 x float> %xv, <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 1, i32 undef>
572 %r = insertelement <4 x float> %splat, float %x, i32 3