1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse3 | FileCheck %s --check-prefix=X86
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse3 | FileCheck %s --check-prefix=X64
5 ; These are tests for SSE3 codegen.
7 ; Test for v8xi16 lowering where we extract the first element of the vector and
8 ; placed it in the second element of the result.
10 define void @t0(<8 x i16>* %dest, <8 x i16>* %old) nounwind {
12 ; X86: # %bb.0: # %entry
13 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
14 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
15 ; X86-NEXT: movdqa {{.*#+}} xmm0 = [1,1,1,1]
16 ; X86-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
17 ; X86-NEXT: movdqa %xmm0, (%eax)
21 ; X64: # %bb.0: # %entry
22 ; X64-NEXT: movdqa {{.*#+}} xmm0 = [1,1,1,1]
23 ; X64-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
24 ; X64-NEXT: movdqa %xmm0, (%rdi)
27 %tmp3 = load <8 x i16>, <8 x i16>* %old
28 %tmp6 = shufflevector <8 x i16> %tmp3,
29 <8 x i16> < i16 1, i16 undef, i16 undef, i16 undef, i16 undef, i16 undef, i16 undef, i16 undef >,
30 <8 x i32> < i32 8, i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef >
31 store <8 x i16> %tmp6, <8 x i16>* %dest
35 define <8 x i16> @t1(<8 x i16>* %A, <8 x i16>* %B) nounwind {
38 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
39 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
40 ; X86-NEXT: movaps {{.*#+}} xmm0 = [0,65535,65535,65535,65535,65535,65535,65535]
41 ; X86-NEXT: movaps %xmm0, %xmm1
42 ; X86-NEXT: andnps (%ecx), %xmm1
43 ; X86-NEXT: andps (%eax), %xmm0
44 ; X86-NEXT: orps %xmm1, %xmm0
49 ; X64-NEXT: movaps {{.*#+}} xmm0 = [0,65535,65535,65535,65535,65535,65535,65535]
50 ; X64-NEXT: movaps %xmm0, %xmm1
51 ; X64-NEXT: andnps (%rsi), %xmm1
52 ; X64-NEXT: andps (%rdi), %xmm0
53 ; X64-NEXT: orps %xmm1, %xmm0
55 %tmp1 = load <8 x i16>, <8 x i16>* %A
56 %tmp2 = load <8 x i16>, <8 x i16>* %B
57 %tmp3 = shufflevector <8 x i16> %tmp1, <8 x i16> %tmp2, <8 x i32> < i32 8, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 >
62 define <8 x i16> @t2(<8 x i16> %A, <8 x i16> %B) nounwind {
65 ; X86-NEXT: movdqa {{.*#+}} xmm2 = [0,65535,65535,0,65535,65535,65535,65535]
66 ; X86-NEXT: pand %xmm2, %xmm0
67 ; X86-NEXT: pshuflw {{.*#+}} xmm1 = xmm1[1,1,2,1,4,5,6,7]
68 ; X86-NEXT: pandn %xmm1, %xmm2
69 ; X86-NEXT: por %xmm2, %xmm0
74 ; X64-NEXT: movdqa {{.*#+}} xmm2 = [0,65535,65535,0,65535,65535,65535,65535]
75 ; X64-NEXT: pand %xmm2, %xmm0
76 ; X64-NEXT: pshuflw {{.*#+}} xmm1 = xmm1[1,1,2,1,4,5,6,7]
77 ; X64-NEXT: pandn %xmm1, %xmm2
78 ; X64-NEXT: por %xmm2, %xmm0
80 %tmp = shufflevector <8 x i16> %A, <8 x i16> %B, <8 x i32> < i32 9, i32 1, i32 2, i32 9, i32 4, i32 5, i32 6, i32 7 >
84 define <8 x i16> @t3(<8 x i16> %A, <8 x i16> %B) nounwind {
87 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
88 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,5,6,5]
89 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
90 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,3,2,1,4,5,6,7]
91 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,7,6,5,4]
96 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
97 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,5,6,5]
98 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
99 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,3,2,1,4,5,6,7]
100 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,7,6,5,4]
102 %tmp = shufflevector <8 x i16> %A, <8 x i16> %A, <8 x i32> < i32 8, i32 3, i32 2, i32 13, i32 7, i32 6, i32 5, i32 4 >
106 define <8 x i16> @t4(<8 x i16> %A, <8 x i16> %B) nounwind {
109 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,1,0,3]
110 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
111 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
112 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,5,7,4,7]
117 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,1,0,3]
118 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
119 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
120 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,5,7,4,7]
122 %tmp = shufflevector <8 x i16> %A, <8 x i16> %B, <8 x i32> < i32 0, i32 7, i32 2, i32 3, i32 1, i32 5, i32 6, i32 5 >
126 define <8 x i16> @t5(<8 x i16> %A, <8 x i16> %B) nounwind {
129 ; X86-NEXT: unpcklps {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
130 ; X86-NEXT: movaps %xmm1, %xmm0
135 ; X64-NEXT: unpcklps {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
136 ; X64-NEXT: movaps %xmm1, %xmm0
138 %tmp = shufflevector <8 x i16> %A, <8 x i16> %B, <8 x i32> < i32 8, i32 9, i32 0, i32 1, i32 10, i32 11, i32 2, i32 3 >
142 define <8 x i16> @t6(<8 x i16> %A, <8 x i16> %B) nounwind {
145 ; X86-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
150 ; X64-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
152 %tmp = shufflevector <8 x i16> %A, <8 x i16> %B, <8 x i32> < i32 8, i32 9, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 >
156 define <8 x i16> @t7(<8 x i16> %A, <8 x i16> %B) nounwind {
159 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,0,3,2,4,5,6,7]
160 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,4,7]
165 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,0,3,2,4,5,6,7]
166 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,4,7]
168 %tmp = shufflevector <8 x i16> %A, <8 x i16> %B, <8 x i32> < i32 0, i32 0, i32 3, i32 2, i32 4, i32 6, i32 4, i32 7 >
172 define void @t8(<2 x i64>* %res, <2 x i64>* %A) nounwind {
175 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
176 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
177 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = mem[2,1,0,3,4,5,6,7]
178 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
179 ; X86-NEXT: movdqa %xmm0, (%eax)
184 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = mem[2,1,0,3,4,5,6,7]
185 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
186 ; X64-NEXT: movdqa %xmm0, (%rdi)
188 %tmp = load <2 x i64>, <2 x i64>* %A
189 %tmp.upgrd.1 = bitcast <2 x i64> %tmp to <8 x i16>
190 %tmp0 = extractelement <8 x i16> %tmp.upgrd.1, i32 0
191 %tmp1 = extractelement <8 x i16> %tmp.upgrd.1, i32 1
192 %tmp2 = extractelement <8 x i16> %tmp.upgrd.1, i32 2
193 %tmp3 = extractelement <8 x i16> %tmp.upgrd.1, i32 3
194 %tmp4 = extractelement <8 x i16> %tmp.upgrd.1, i32 4
195 %tmp5 = extractelement <8 x i16> %tmp.upgrd.1, i32 5
196 %tmp6 = extractelement <8 x i16> %tmp.upgrd.1, i32 6
197 %tmp7 = extractelement <8 x i16> %tmp.upgrd.1, i32 7
198 %tmp8 = insertelement <8 x i16> undef, i16 %tmp2, i32 0
199 %tmp9 = insertelement <8 x i16> %tmp8, i16 %tmp1, i32 1
200 %tmp10 = insertelement <8 x i16> %tmp9, i16 %tmp0, i32 2
201 %tmp11 = insertelement <8 x i16> %tmp10, i16 %tmp3, i32 3
202 %tmp12 = insertelement <8 x i16> %tmp11, i16 %tmp6, i32 4
203 %tmp13 = insertelement <8 x i16> %tmp12, i16 %tmp5, i32 5
204 %tmp14 = insertelement <8 x i16> %tmp13, i16 %tmp4, i32 6
205 %tmp15 = insertelement <8 x i16> %tmp14, i16 %tmp7, i32 7
206 %tmp15.upgrd.2 = bitcast <8 x i16> %tmp15 to <2 x i64>
207 store <2 x i64> %tmp15.upgrd.2, <2 x i64>* %res
211 define void @t9(<4 x float>* %r, <2 x i32>* %A) nounwind {
214 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
215 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
216 ; X86-NEXT: movaps (%ecx), %xmm0
217 ; X86-NEXT: movhps {{.*#+}} xmm0 = xmm0[0,1],mem[0,1]
218 ; X86-NEXT: movaps %xmm0, (%ecx)
223 ; X64-NEXT: movaps (%rdi), %xmm0
224 ; X64-NEXT: movhps {{.*#+}} xmm0 = xmm0[0,1],mem[0,1]
225 ; X64-NEXT: movaps %xmm0, (%rdi)
227 %tmp = load <4 x float>, <4 x float>* %r
228 %tmp.upgrd.3 = bitcast <2 x i32>* %A to double*
229 %tmp.upgrd.4 = load double, double* %tmp.upgrd.3
230 %tmp.upgrd.5 = insertelement <2 x double> undef, double %tmp.upgrd.4, i32 0
231 %tmp5 = insertelement <2 x double> %tmp.upgrd.5, double undef, i32 1
232 %tmp6 = bitcast <2 x double> %tmp5 to <4 x float>
233 %tmp.upgrd.6 = extractelement <4 x float> %tmp, i32 0
234 %tmp7 = extractelement <4 x float> %tmp, i32 1
235 %tmp8 = extractelement <4 x float> %tmp6, i32 0
236 %tmp9 = extractelement <4 x float> %tmp6, i32 1
237 %tmp10 = insertelement <4 x float> undef, float %tmp.upgrd.6, i32 0
238 %tmp11 = insertelement <4 x float> %tmp10, float %tmp7, i32 1
239 %tmp12 = insertelement <4 x float> %tmp11, float %tmp8, i32 2
240 %tmp13 = insertelement <4 x float> %tmp12, float %tmp9, i32 3
241 store <4 x float> %tmp13, <4 x float>* %r
247 ; FIXME: This testcase produces icky code. It can be made much better!
250 @g1 = external constant <4 x i32>
251 @g2 = external constant <4 x i16>
253 define void @t10() nounwind {
256 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = mem[0,2,2,3,4,5,6,7]
257 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,6,7]
258 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
259 ; X86-NEXT: movq %xmm0, g2
264 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = mem[0,2,2,3,4,5,6,7]
265 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,6,7]
266 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
267 ; X64-NEXT: movq %xmm0, {{.*}}(%rip)
269 load <4 x i32>, <4 x i32>* @g1, align 16
270 bitcast <4 x i32> %1 to <8 x i16>
271 shufflevector <8 x i16> %2, <8 x i16> undef, <8 x i32> < i32 0, i32 2, i32 4, i32 6, i32 undef, i32 undef, i32 undef, i32 undef >
272 bitcast <8 x i16> %3 to <2 x i64>
273 extractelement <2 x i64> %4, i32 0
274 bitcast i64 %5 to <4 x i16>
275 store <4 x i16> %6, <4 x i16>* @g2, align 8
279 ; Pack various elements via shuffles.
280 define <8 x i16> @t11(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
282 ; X86: # %bb.0: # %entry
283 ; X86-NEXT: psrld $16, %xmm0
284 ; X86-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
288 ; X64: # %bb.0: # %entry
289 ; X64-NEXT: psrld $16, %xmm0
290 ; X64-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
293 %tmp7 = shufflevector <8 x i16> %T0, <8 x i16> %T1, <8 x i32> < i32 1, i32 8, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef , i32 undef >
298 define <8 x i16> @t12(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
300 ; X86: # %bb.0: # %entry
301 ; X86-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
302 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,2,2,3,4,5,6,7]
303 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
307 ; X64: # %bb.0: # %entry
308 ; X64-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
309 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,2,2,3,4,5,6,7]
310 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
313 %tmp9 = shufflevector <8 x i16> %T0, <8 x i16> %T1, <8 x i32> < i32 0, i32 1, i32 undef, i32 undef, i32 3, i32 11, i32 undef , i32 undef >
318 define <8 x i16> @t13(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
320 ; X86: # %bb.0: # %entry
321 ; X86-NEXT: punpcklwd {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3]
322 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm1[0,2,2,3,4,5,6,7]
323 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
327 ; X64: # %bb.0: # %entry
328 ; X64-NEXT: punpcklwd {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3]
329 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm1[0,2,2,3,4,5,6,7]
330 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
333 %tmp9 = shufflevector <8 x i16> %T0, <8 x i16> %T1, <8 x i32> < i32 8, i32 9, i32 undef, i32 undef, i32 11, i32 3, i32 undef , i32 undef >
337 define <8 x i16> @t14(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
339 ; X86: # %bb.0: # %entry
340 ; X86-NEXT: psrlq $16, %xmm0
341 ; X86-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
342 ; X86-NEXT: movdqa %xmm1, %xmm0
346 ; X64: # %bb.0: # %entry
347 ; X64-NEXT: psrlq $16, %xmm0
348 ; X64-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
349 ; X64-NEXT: movdqa %xmm1, %xmm0
352 %tmp9 = shufflevector <8 x i16> %T0, <8 x i16> %T1, <8 x i32> < i32 8, i32 9, i32 undef, i32 undef, i32 undef, i32 2, i32 undef , i32 undef >
356 ; FIXME: t15 is worse off from disabling of scheduler 2-address hack.
357 define <8 x i16> @t15(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
359 ; X86: # %bb.0: # %entry
360 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,3]
361 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,1,1,2,4,5,6,7]
362 ; X86-NEXT: punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm1[0]
366 ; X64: # %bb.0: # %entry
367 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,3]
368 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,1,1,2,4,5,6,7]
369 ; X64-NEXT: punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm1[0]
372 %tmp8 = shufflevector <8 x i16> %T0, <8 x i16> %T1, <8 x i32> < i32 undef, i32 undef, i32 7, i32 2, i32 8, i32 undef, i32 undef , i32 undef >
376 ; Test yonah where we convert a shuffle to pextrw and pinrsw
377 define <16 x i8> @t16(<16 x i8> %T0) nounwind readnone {
379 ; X86: # %bb.0: # %entry
380 ; X86-NEXT: pslld $16, %xmm0
384 ; X64: # %bb.0: # %entry
385 ; X64-NEXT: pslld $16, %xmm0
388 %tmp8 = shufflevector <16 x i8> <i8 0, i8 0, i8 0, i8 0, i8 1, i8 1, i8 1, i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>, <16 x i8> %T0, <16 x i32> < i32 0, i32 1, i32 16, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef , i32 undef >
389 %tmp9 = shufflevector <16 x i8> %tmp8, <16 x i8> %T0, <16 x i32> < i32 0, i32 1, i32 2, i32 17, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef , i32 undef >
394 define <4 x i32> @t17() nounwind {
396 ; X86: # %bb.0: # %entry
397 ; X86-NEXT: pshufd {{.*#+}} xmm0 = mem[0,1,0,1]
398 ; X86-NEXT: pand {{\.LCPI.*}}, %xmm0
402 ; X64: # %bb.0: # %entry
403 ; X64-NEXT: pshufd {{.*#+}} xmm0 = mem[0,1,0,1]
404 ; X64-NEXT: pand {{.*}}(%rip), %xmm0
407 %tmp1 = load <4 x float>, <4 x float>* undef, align 16
408 %tmp2 = shufflevector <4 x float> %tmp1, <4 x float> undef, <4 x i32> <i32 4, i32 1, i32 2, i32 3>
409 %tmp3 = load <4 x float>, <4 x float>* undef, align 16
410 %tmp4 = shufflevector <4 x float> %tmp2, <4 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
411 %tmp5 = bitcast <4 x float> %tmp3 to <4 x i32>
412 %tmp6 = shufflevector <4 x i32> %tmp5, <4 x i32> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
413 %tmp7 = and <4 x i32> %tmp6, <i32 undef, i32 undef, i32 -1, i32 0>