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-prefix=ALL --check-prefix=SSEANY --check-prefix=SSE2
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=sse4.1 | FileCheck %s --check-prefix=ALL --check-prefix=SSEANY --check-prefix=SSE4
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx | FileCheck %s --check-prefix=ALL --check-prefix=AVX
6 define <4 x i32> @ins_elt_0(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
7 ; SSE2-LABEL: ins_elt_0:
9 ; SSE2-NEXT: movaps %xmm1, %xmm0
10 ; SSE2-NEXT: movd %edi, %xmm1
11 ; SSE2-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
14 ; SSE4-LABEL: ins_elt_0:
16 ; SSE4-NEXT: movdqa %xmm1, %xmm0
17 ; SSE4-NEXT: pinsrd $0, %edi, %xmm0
20 ; AVX-LABEL: ins_elt_0:
22 ; AVX-NEXT: vpinsrd $0, %edi, %xmm1, %xmm0
24 %ins = insertelement <4 x i32> %v1, i32 %x, i32 0
25 %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 0, i32 5, i32 6, i32 7>
29 define <4 x i32> @ins_elt_1(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
30 ; SSE2-LABEL: ins_elt_1:
32 ; SSE2-NEXT: movd %edi, %xmm0
33 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,0],xmm1[0,0]
34 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[2,0],xmm1[2,3]
37 ; SSE4-LABEL: ins_elt_1:
39 ; SSE4-NEXT: movdqa %xmm1, %xmm0
40 ; SSE4-NEXT: pinsrd $1, %edi, %xmm0
43 ; AVX-LABEL: ins_elt_1:
45 ; AVX-NEXT: vpinsrd $1, %edi, %xmm1, %xmm0
47 %ins = insertelement <4 x i32> %v1, i32 %x, i32 1
48 %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 4, i32 1, i32 6, i32 7>
52 ; Verify that the transform still works when the insert element is the 2nd operand to the shuffle.
54 define <4 x i32> @ins_elt_2_commute(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
55 ; SSE2-LABEL: ins_elt_2_commute:
57 ; SSE2-NEXT: movaps %xmm1, %xmm0
58 ; SSE2-NEXT: movd %edi, %xmm1
59 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[3,0]
60 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,2]
63 ; SSE4-LABEL: ins_elt_2_commute:
65 ; SSE4-NEXT: movdqa %xmm1, %xmm0
66 ; SSE4-NEXT: pinsrd $2, %edi, %xmm0
69 ; AVX-LABEL: ins_elt_2_commute:
71 ; AVX-NEXT: vpinsrd $2, %edi, %xmm1, %xmm0
73 %ins = insertelement <4 x i32> %v1, i32 %x, i32 2
74 %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 1, i32 6, i32 3>
78 define <4 x i32> @ins_elt_3_commute(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
79 ; SSE2-LABEL: ins_elt_3_commute:
81 ; SSE2-NEXT: movaps %xmm1, %xmm0
82 ; SSE2-NEXT: movd %edi, %xmm1
83 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[2,0]
84 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,0]
87 ; SSE4-LABEL: ins_elt_3_commute:
89 ; SSE4-NEXT: movdqa %xmm1, %xmm0
90 ; SSE4-NEXT: pinsrd $3, %edi, %xmm0
93 ; AVX-LABEL: ins_elt_3_commute:
95 ; AVX-NEXT: vpinsrd $3, %edi, %xmm1, %xmm0
97 %ins = insertelement <4 x i32> %v1, i32 %x, i32 3
98 %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 1, i32 2, i32 7>
102 ; In the next 4 tests, the shuffle moves the inserted scalar to a different position in the output vector.
104 define <4 x i32> @ins_elt_0_to_2(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
105 ; SSE2-LABEL: ins_elt_0_to_2:
107 ; SSE2-NEXT: movaps %xmm1, %xmm0
108 ; SSE2-NEXT: movd %edi, %xmm1
109 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[3,0]
110 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,2]
113 ; SSE4-LABEL: ins_elt_0_to_2:
115 ; SSE4-NEXT: movdqa %xmm1, %xmm0
116 ; SSE4-NEXT: pinsrd $2, %edi, %xmm0
119 ; AVX-LABEL: ins_elt_0_to_2:
121 ; AVX-NEXT: vpinsrd $2, %edi, %xmm1, %xmm0
123 %ins = insertelement <4 x i32> %v1, i32 %x, i32 0
124 %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 4, i32 5, i32 0, i32 7>
128 define <4 x i32> @ins_elt_1_to_0(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
129 ; SSE2-LABEL: ins_elt_1_to_0:
131 ; SSE2-NEXT: movaps %xmm1, %xmm0
132 ; SSE2-NEXT: movd %edi, %xmm1
133 ; SSE2-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
136 ; SSE4-LABEL: ins_elt_1_to_0:
138 ; SSE4-NEXT: movdqa %xmm1, %xmm0
139 ; SSE4-NEXT: pinsrd $0, %edi, %xmm0
142 ; AVX-LABEL: ins_elt_1_to_0:
144 ; AVX-NEXT: vpinsrd $0, %edi, %xmm1, %xmm0
146 %ins = insertelement <4 x i32> %v1, i32 %x, i32 1
147 %shuf = shufflevector <4 x i32> %ins, <4 x i32> %v2, <4 x i32> <i32 1, i32 5, i32 6, i32 7>
151 define <4 x i32> @ins_elt_2_to_3(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
152 ; SSE2-LABEL: ins_elt_2_to_3:
154 ; SSE2-NEXT: movaps %xmm1, %xmm0
155 ; SSE2-NEXT: movd %edi, %xmm1
156 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[2,0]
157 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,0]
160 ; SSE4-LABEL: ins_elt_2_to_3:
162 ; SSE4-NEXT: movdqa %xmm1, %xmm0
163 ; SSE4-NEXT: pinsrd $3, %edi, %xmm0
166 ; AVX-LABEL: ins_elt_2_to_3:
168 ; AVX-NEXT: vpinsrd $3, %edi, %xmm1, %xmm0
170 %ins = insertelement <4 x i32> %v1, i32 %x, i32 2
171 %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 1, i32 2, i32 6>
175 define <4 x i32> @ins_elt_3_to_1(i32 %x, <4 x i32> %v1, <4 x i32> %v2) {
176 ; SSE2-LABEL: ins_elt_3_to_1:
178 ; SSE2-NEXT: movd %edi, %xmm0
179 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,0],xmm1[0,0]
180 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[2,0],xmm1[2,3]
183 ; SSE4-LABEL: ins_elt_3_to_1:
185 ; SSE4-NEXT: movdqa %xmm1, %xmm0
186 ; SSE4-NEXT: pinsrd $1, %edi, %xmm0
189 ; AVX-LABEL: ins_elt_3_to_1:
191 ; AVX-NEXT: vpinsrd $1, %edi, %xmm1, %xmm0
193 %ins = insertelement <4 x i32> %v1, i32 %x, i32 3
194 %shuf = shufflevector <4 x i32> %v2, <4 x i32> %ins, <4 x i32> <i32 0, i32 7, i32 2, i32 3>