1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefixes=SSE,SSE2
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefixes=SSE,SSE41
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefixes=AVX
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=AVX
7 ; 0'th element insertion into an SSE register.
9 define <4 x float> @insert_f32_firstelt(<4 x float> %x, float %s) {
10 ; SSE2-LABEL: insert_f32_firstelt:
12 ; SSE2-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
15 ; SSE41-LABEL: insert_f32_firstelt:
17 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
20 ; AVX-LABEL: insert_f32_firstelt:
22 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
24 %i0 = insertelement <4 x float> %x, float %s, i32 0
28 define <2 x double> @insert_f64_firstelt(<2 x double> %x, double %s) {
29 ; SSE2-LABEL: insert_f64_firstelt:
31 ; SSE2-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1]
34 ; SSE41-LABEL: insert_f64_firstelt:
36 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
39 ; AVX-LABEL: insert_f64_firstelt:
41 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
43 %i0 = insertelement <2 x double> %x, double %s, i32 0
47 define <16 x i8> @insert_i8_firstelt(<16 x i8> %x, i8 %s) {
48 ; SSE2-LABEL: insert_i8_firstelt:
50 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]
51 ; SSE2-NEXT: pand %xmm1, %xmm0
52 ; SSE2-NEXT: movd %edi, %xmm2
53 ; SSE2-NEXT: pandn %xmm2, %xmm1
54 ; SSE2-NEXT: por %xmm1, %xmm0
57 ; SSE41-LABEL: insert_i8_firstelt:
59 ; SSE41-NEXT: pinsrb $0, %edi, %xmm0
62 ; AVX-LABEL: insert_i8_firstelt:
64 ; AVX-NEXT: vpinsrb $0, %edi, %xmm0, %xmm0
66 %i0 = insertelement <16 x i8> %x, i8 %s, i32 0
70 define <8 x i16> @insert_i16_firstelt(<8 x i16> %x, i16 %s) {
71 ; SSE-LABEL: insert_i16_firstelt:
73 ; SSE-NEXT: pinsrw $0, %edi, %xmm0
76 ; AVX-LABEL: insert_i16_firstelt:
78 ; AVX-NEXT: vpinsrw $0, %edi, %xmm0, %xmm0
80 %i0 = insertelement <8 x i16> %x, i16 %s, i32 0
84 define <4 x i32> @insert_i32_firstelt(<4 x i32> %x, i32 %s) {
85 ; SSE2-LABEL: insert_i32_firstelt:
87 ; SSE2-NEXT: movd %edi, %xmm1
88 ; SSE2-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
91 ; SSE41-LABEL: insert_i32_firstelt:
93 ; SSE41-NEXT: pinsrd $0, %edi, %xmm0
96 ; AVX-LABEL: insert_i32_firstelt:
98 ; AVX-NEXT: vpinsrd $0, %edi, %xmm0, %xmm0
100 %i0 = insertelement <4 x i32> %x, i32 %s, i32 0
104 define <2 x i64> @insert_i64_firstelt(<2 x i64> %x, i64 %s) {
105 ; SSE2-LABEL: insert_i64_firstelt:
107 ; SSE2-NEXT: movq %rdi, %xmm1
108 ; SSE2-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1]
111 ; SSE41-LABEL: insert_i64_firstelt:
113 ; SSE41-NEXT: pinsrq $0, %rdi, %xmm0
116 ; AVX-LABEL: insert_i64_firstelt:
118 ; AVX-NEXT: vpinsrq $0, %rdi, %xmm0, %xmm0
120 %i0 = insertelement <2 x i64> %x, i64 %s, i32 0
124 ; 1'th element insertion.
126 define <4 x float> @insert_f32_secondelt(<4 x float> %x, float %s) {
127 ; SSE2-LABEL: insert_f32_secondelt:
129 ; SSE2-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0],xmm0[0]
130 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[2,0],xmm0[2,3]
131 ; SSE2-NEXT: movaps %xmm1, %xmm0
134 ; SSE41-LABEL: insert_f32_secondelt:
136 ; SSE41-NEXT: insertps {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[2,3]
139 ; AVX-LABEL: insert_f32_secondelt:
141 ; AVX-NEXT: vinsertps {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[2,3]
143 %i0 = insertelement <4 x float> %x, float %s, i32 1
147 define <2 x double> @insert_f64_secondelt(<2 x double> %x, double %s) {
148 ; SSE-LABEL: insert_f64_secondelt:
150 ; SSE-NEXT: movlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
153 ; AVX-LABEL: insert_f64_secondelt:
155 ; AVX-NEXT: vmovlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
157 %i0 = insertelement <2 x double> %x, double %s, i32 1
161 define <16 x i8> @insert_i8_secondelt(<16 x i8> %x, i8 %s) {
162 ; SSE2-LABEL: insert_i8_secondelt:
164 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255]
165 ; SSE2-NEXT: pand %xmm1, %xmm0
166 ; SSE2-NEXT: movd %edi, %xmm2
167 ; SSE2-NEXT: psllw $8, %xmm2
168 ; SSE2-NEXT: pandn %xmm2, %xmm1
169 ; SSE2-NEXT: por %xmm1, %xmm0
172 ; SSE41-LABEL: insert_i8_secondelt:
174 ; SSE41-NEXT: pinsrb $1, %edi, %xmm0
177 ; AVX-LABEL: insert_i8_secondelt:
179 ; AVX-NEXT: vpinsrb $1, %edi, %xmm0, %xmm0
181 %i0 = insertelement <16 x i8> %x, i8 %s, i32 1
185 define <8 x i16> @insert_i16_secondelt(<8 x i16> %x, i16 %s) {
186 ; SSE-LABEL: insert_i16_secondelt:
188 ; SSE-NEXT: pinsrw $1, %edi, %xmm0
191 ; AVX-LABEL: insert_i16_secondelt:
193 ; AVX-NEXT: vpinsrw $1, %edi, %xmm0, %xmm0
195 %i0 = insertelement <8 x i16> %x, i16 %s, i32 1
199 define <4 x i32> @insert_i32_secondelt(<4 x i32> %x, i32 %s) {
200 ; SSE2-LABEL: insert_i32_secondelt:
202 ; SSE2-NEXT: movd %edi, %xmm1
203 ; SSE2-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
204 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[2,0],xmm0[2,3]
205 ; SSE2-NEXT: movaps %xmm1, %xmm0
208 ; SSE41-LABEL: insert_i32_secondelt:
210 ; SSE41-NEXT: pinsrd $1, %edi, %xmm0
213 ; AVX-LABEL: insert_i32_secondelt:
215 ; AVX-NEXT: vpinsrd $1, %edi, %xmm0, %xmm0
217 %i0 = insertelement <4 x i32> %x, i32 %s, i32 1
221 define <2 x i64> @insert_i64_secondelt(<2 x i64> %x, i64 %s) {
222 ; SSE2-LABEL: insert_i64_secondelt:
224 ; SSE2-NEXT: movq %rdi, %xmm1
225 ; SSE2-NEXT: punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm1[0]
228 ; SSE41-LABEL: insert_i64_secondelt:
230 ; SSE41-NEXT: pinsrq $1, %rdi, %xmm0
233 ; AVX-LABEL: insert_i64_secondelt:
235 ; AVX-NEXT: vpinsrq $1, %rdi, %xmm0, %xmm0
237 %i0 = insertelement <2 x i64> %x, i64 %s, i32 1
241 ; element insertion into two elements
243 define <4 x float> @insert_f32_two_elts(<4 x float> %x, float %s) {
244 ; SSE-LABEL: insert_f32_two_elts:
246 ; SSE-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[2,3]
247 ; SSE-NEXT: movaps %xmm1, %xmm0
250 ; AVX-LABEL: insert_f32_two_elts:
252 ; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm1[0,0],xmm0[2,3]
254 %i0 = insertelement <4 x float> %x, float %s, i32 0
255 %i1 = insertelement <4 x float> %i0, float %s, i32 1
259 define <2 x double> @insert_f64_two_elts(<2 x double> %x, double %s) {
260 ; SSE2-LABEL: insert_f64_two_elts:
262 ; SSE2-NEXT: movaps %xmm1, %xmm0
263 ; SSE2-NEXT: movlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
266 ; SSE41-LABEL: insert_f64_two_elts:
268 ; SSE41-NEXT: movddup {{.*#+}} xmm0 = xmm1[0,0]
271 ; AVX-LABEL: insert_f64_two_elts:
273 ; AVX-NEXT: vmovddup {{.*#+}} xmm0 = xmm1[0,0]
275 %i0 = insertelement <2 x double> %x, double %s, i32 0
276 %i1 = insertelement <2 x double> %i0, double %s, i32 1
280 define <16 x i8> @insert_i8_two_elts(<16 x i8> %x, i8 %s) {
281 ; SSE2-LABEL: insert_i8_two_elts:
283 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]
284 ; SSE2-NEXT: pand %xmm1, %xmm0
285 ; SSE2-NEXT: movd %edi, %xmm2
286 ; SSE2-NEXT: pandn %xmm2, %xmm1
287 ; SSE2-NEXT: por %xmm1, %xmm0
288 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255]
289 ; SSE2-NEXT: pand %xmm1, %xmm0
290 ; SSE2-NEXT: psllw $8, %xmm2
291 ; SSE2-NEXT: pandn %xmm2, %xmm1
292 ; SSE2-NEXT: por %xmm1, %xmm0
295 ; SSE41-LABEL: insert_i8_two_elts:
297 ; SSE41-NEXT: pinsrb $0, %edi, %xmm0
298 ; SSE41-NEXT: pinsrb $1, %edi, %xmm0
301 ; AVX-LABEL: insert_i8_two_elts:
303 ; AVX-NEXT: vpinsrb $0, %edi, %xmm0, %xmm0
304 ; AVX-NEXT: vpinsrb $1, %edi, %xmm0, %xmm0
306 %i0 = insertelement <16 x i8> %x, i8 %s, i32 0
307 %i1 = insertelement <16 x i8> %i0, i8 %s, i32 1
311 define <8 x i16> @insert_i16_two_elts(<8 x i16> %x, i16 %s) {
312 ; SSE-LABEL: insert_i16_two_elts:
314 ; SSE-NEXT: pinsrw $0, %edi, %xmm0
315 ; SSE-NEXT: pinsrw $1, %edi, %xmm0
318 ; AVX-LABEL: insert_i16_two_elts:
320 ; AVX-NEXT: vpinsrw $0, %edi, %xmm0, %xmm0
321 ; AVX-NEXT: vpinsrw $1, %edi, %xmm0, %xmm0
323 %i0 = insertelement <8 x i16> %x, i16 %s, i32 0
324 %i1 = insertelement <8 x i16> %i0, i16 %s, i32 1
328 define <4 x i32> @insert_i32_two_elts(<4 x i32> %x, i32 %s) {
329 ; SSE2-LABEL: insert_i32_two_elts:
331 ; SSE2-NEXT: movd %edi, %xmm2
332 ; SSE2-NEXT: movd %edi, %xmm1
333 ; SSE2-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm2[0]
334 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[2,0],xmm0[2,3]
335 ; SSE2-NEXT: movaps %xmm1, %xmm0
338 ; SSE41-LABEL: insert_i32_two_elts:
340 ; SSE41-NEXT: pinsrd $0, %edi, %xmm0
341 ; SSE41-NEXT: pinsrd $1, %edi, %xmm0
344 ; AVX-LABEL: insert_i32_two_elts:
346 ; AVX-NEXT: vpinsrd $0, %edi, %xmm0, %xmm0
347 ; AVX-NEXT: vpinsrd $1, %edi, %xmm0, %xmm0
349 %i0 = insertelement <4 x i32> %x, i32 %s, i32 0
350 %i1 = insertelement <4 x i32> %i0, i32 %s, i32 1
354 define <2 x i64> @insert_i64_two_elts(<2 x i64> %x, i64 %s) {
355 ; SSE-LABEL: insert_i64_two_elts:
357 ; SSE-NEXT: movq %rdi, %xmm0
358 ; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
360 %i0 = insertelement <2 x i64> %x, i64 %s, i32 0
361 %i1 = insertelement <2 x i64> %i0, i64 %s, i32 1