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(ptr %dest, ptr %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: movl $1, %edx
16 ; X86-NEXT: movd %edx, %xmm0
17 ; X86-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
18 ; X86-NEXT: movdqa %xmm0, (%eax)
22 ; X64: # %bb.0: # %entry
23 ; X64-NEXT: movl $1, %eax
24 ; X64-NEXT: movd %eax, %xmm0
25 ; X64-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
26 ; X64-NEXT: movdqa %xmm0, (%rdi)
29 %tmp3 = load <8 x i16>, ptr %old
30 %tmp6 = shufflevector <8 x i16> %tmp3,
31 <8 x i16> < i16 1, i16 undef, i16 undef, i16 undef, i16 undef, i16 undef, i16 undef, i16 undef >,
32 <8 x i32> < i32 8, i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef >
33 store <8 x i16> %tmp6, ptr %dest
37 define <8 x i16> @t1(ptr %A, ptr %B) nounwind {
40 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
41 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
42 ; X86-NEXT: movaps {{.*#+}} xmm0 = [0,65535,65535,65535,65535,65535,65535,65535]
43 ; X86-NEXT: movaps %xmm0, %xmm1
44 ; X86-NEXT: andnps (%ecx), %xmm1
45 ; X86-NEXT: andps (%eax), %xmm0
46 ; X86-NEXT: orps %xmm1, %xmm0
51 ; X64-NEXT: movaps {{.*#+}} xmm0 = [0,65535,65535,65535,65535,65535,65535,65535]
52 ; X64-NEXT: movaps %xmm0, %xmm1
53 ; X64-NEXT: andnps (%rsi), %xmm1
54 ; X64-NEXT: andps (%rdi), %xmm0
55 ; X64-NEXT: orps %xmm1, %xmm0
57 %tmp1 = load <8 x i16>, ptr %A
58 %tmp2 = load <8 x i16>, ptr %B
59 %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 >
64 define <8 x i16> @t2(<8 x i16> %A, <8 x i16> %B) nounwind {
67 ; X86-NEXT: movdqa {{.*#+}} xmm2 = [0,65535,65535,0,65535,65535,65535,65535]
68 ; X86-NEXT: pand %xmm2, %xmm0
69 ; X86-NEXT: pshuflw {{.*#+}} xmm1 = xmm1[1,1,1,1,4,5,6,7]
70 ; X86-NEXT: pandn %xmm1, %xmm2
71 ; X86-NEXT: por %xmm2, %xmm0
76 ; X64-NEXT: movdqa {{.*#+}} xmm2 = [0,65535,65535,0,65535,65535,65535,65535]
77 ; X64-NEXT: pand %xmm2, %xmm0
78 ; X64-NEXT: pshuflw {{.*#+}} xmm1 = xmm1[1,1,1,1,4,5,6,7]
79 ; X64-NEXT: pandn %xmm1, %xmm2
80 ; X64-NEXT: por %xmm2, %xmm0
82 %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 >
86 define <8 x i16> @t3(<8 x i16> %A, <8 x i16> %B) nounwind {
89 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
90 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,5,6,5]
91 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
92 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,3,2,1,4,5,6,7]
93 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,7,6,5,4]
98 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
99 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,5,6,5]
100 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
101 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,3,2,1,4,5,6,7]
102 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,7,6,5,4]
104 %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 >
108 define <8 x i16> @t4(<8 x i16> %A, <8 x i16> %B) nounwind {
111 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,1,0,3]
112 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
113 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
114 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,5,7,4,7]
119 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,1,0,3]
120 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
121 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,0]
122 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,5,7,4,7]
124 %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 >
128 define <8 x i16> @t5(<8 x i16> %A, <8 x i16> %B) nounwind {
131 ; X86-NEXT: unpcklps {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
132 ; X86-NEXT: movaps %xmm1, %xmm0
137 ; X64-NEXT: unpcklps {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
138 ; X64-NEXT: movaps %xmm1, %xmm0
140 %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 >
144 define <8 x i16> @t6(<8 x i16> %A, <8 x i16> %B) nounwind {
147 ; X86-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
152 ; X64-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
154 %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 >
158 define <8 x i16> @t7(<8 x i16> %A, <8 x i16> %B) nounwind {
161 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,0,3,2,4,5,6,7]
162 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,4,7]
167 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,0,3,2,4,5,6,7]
168 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,4,7]
170 %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 >
174 define void @t8(ptr %res, ptr %A) nounwind {
177 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
178 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
179 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = mem[2,1,0,3,4,5,6,7]
180 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
181 ; X86-NEXT: movdqa %xmm0, (%eax)
186 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = mem[2,1,0,3,4,5,6,7]
187 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,6,5,4,7]
188 ; X64-NEXT: movdqa %xmm0, (%rdi)
190 %tmp = load <2 x i64>, ptr %A
191 %tmp.upgrd.1 = bitcast <2 x i64> %tmp to <8 x i16>
192 %tmp0 = extractelement <8 x i16> %tmp.upgrd.1, i32 0
193 %tmp1 = extractelement <8 x i16> %tmp.upgrd.1, i32 1
194 %tmp2 = extractelement <8 x i16> %tmp.upgrd.1, i32 2
195 %tmp3 = extractelement <8 x i16> %tmp.upgrd.1, i32 3
196 %tmp4 = extractelement <8 x i16> %tmp.upgrd.1, i32 4
197 %tmp5 = extractelement <8 x i16> %tmp.upgrd.1, i32 5
198 %tmp6 = extractelement <8 x i16> %tmp.upgrd.1, i32 6
199 %tmp7 = extractelement <8 x i16> %tmp.upgrd.1, i32 7
200 %tmp8 = insertelement <8 x i16> undef, i16 %tmp2, i32 0
201 %tmp9 = insertelement <8 x i16> %tmp8, i16 %tmp1, i32 1
202 %tmp10 = insertelement <8 x i16> %tmp9, i16 %tmp0, i32 2
203 %tmp11 = insertelement <8 x i16> %tmp10, i16 %tmp3, i32 3
204 %tmp12 = insertelement <8 x i16> %tmp11, i16 %tmp6, i32 4
205 %tmp13 = insertelement <8 x i16> %tmp12, i16 %tmp5, i32 5
206 %tmp14 = insertelement <8 x i16> %tmp13, i16 %tmp4, i32 6
207 %tmp15 = insertelement <8 x i16> %tmp14, i16 %tmp7, i32 7
208 %tmp15.upgrd.2 = bitcast <8 x i16> %tmp15 to <2 x i64>
209 store <2 x i64> %tmp15.upgrd.2, ptr %res
213 define void @t9(ptr %r, ptr %A) nounwind {
216 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
217 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
218 ; X86-NEXT: movaps (%ecx), %xmm0
219 ; X86-NEXT: movhps {{.*#+}} xmm0 = xmm0[0,1],mem[0,1]
220 ; X86-NEXT: movaps %xmm0, (%ecx)
225 ; X64-NEXT: movaps (%rdi), %xmm0
226 ; X64-NEXT: movhps {{.*#+}} xmm0 = xmm0[0,1],mem[0,1]
227 ; X64-NEXT: movaps %xmm0, (%rdi)
229 %tmp = load <4 x float>, ptr %r
230 %tmp.upgrd.4 = load double, ptr %A
231 %tmp.upgrd.5 = insertelement <2 x double> undef, double %tmp.upgrd.4, i32 0
232 %tmp5 = insertelement <2 x double> %tmp.upgrd.5, double undef, i32 1
233 %tmp6 = bitcast <2 x double> %tmp5 to <4 x float>
234 %tmp.upgrd.6 = extractelement <4 x float> %tmp, i32 0
235 %tmp7 = extractelement <4 x float> %tmp, i32 1
236 %tmp8 = extractelement <4 x float> %tmp6, i32 0
237 %tmp9 = extractelement <4 x float> %tmp6, i32 1
238 %tmp10 = insertelement <4 x float> undef, float %tmp.upgrd.6, i32 0
239 %tmp11 = insertelement <4 x float> %tmp10, float %tmp7, i32 1
240 %tmp12 = insertelement <4 x float> %tmp11, float %tmp8, i32 2
241 %tmp13 = insertelement <4 x float> %tmp12, float %tmp9, i32 3
242 store <4 x float> %tmp13, ptr %r
248 ; FIXME: This testcase produces icky code. It can be made much better!
251 @g1 = external dso_local constant <4 x i32>
252 @g2 = external dso_local constant <4 x i16>
254 define void @t10() nounwind {
257 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = mem[0,2,2,3,4,5,6,7]
258 ; X86-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,6,7]
259 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
260 ; X86-NEXT: movq %xmm0, g2
265 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = mem[0,2,2,3,4,5,6,7]
266 ; X64-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,6,7]
267 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
268 ; X64-NEXT: movq %xmm0, g2(%rip)
270 load <4 x i32>, ptr @g1, align 16
271 bitcast <4 x i32> %1 to <8 x i16>
272 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 >
273 bitcast <8 x i16> %3 to <2 x i64>
274 extractelement <2 x i64> %4, i32 0
275 bitcast i64 %5 to <4 x i16>
276 store <4 x i16> %6, ptr @g2, align 8
280 ; Pack various elements via shuffles.
281 define <8 x i16> @t11(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
283 ; X86: # %bb.0: # %entry
284 ; X86-NEXT: psrld $16, %xmm0
285 ; X86-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
289 ; X64: # %bb.0: # %entry
290 ; X64-NEXT: psrld $16, %xmm0
291 ; X64-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
294 %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 >
299 define <8 x i16> @t12(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
301 ; X86: # %bb.0: # %entry
302 ; X86-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
303 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,2,2,3,4,5,6,7]
304 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
308 ; X64: # %bb.0: # %entry
309 ; X64-NEXT: punpcklwd {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
310 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,2,2,3,4,5,6,7]
311 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
314 %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 >
319 define <8 x i16> @t13(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
321 ; X86: # %bb.0: # %entry
322 ; X86-NEXT: punpcklwd {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3]
323 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm1[0,2,2,3,4,5,6,7]
324 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
328 ; X64: # %bb.0: # %entry
329 ; X64-NEXT: punpcklwd {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3]
330 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm1[0,2,2,3,4,5,6,7]
331 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,3,3]
334 %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 >
338 define <8 x i16> @t14(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
340 ; X86: # %bb.0: # %entry
341 ; X86-NEXT: psrlq $16, %xmm0
342 ; X86-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
343 ; X86-NEXT: movdqa %xmm1, %xmm0
347 ; X64: # %bb.0: # %entry
348 ; X64-NEXT: psrlq $16, %xmm0
349 ; X64-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
350 ; X64-NEXT: movdqa %xmm1, %xmm0
353 %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 >
357 ; FIXME: t15 is worse off from disabling of scheduler 2-address hack.
358 define <8 x i16> @t15(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
360 ; X86: # %bb.0: # %entry
361 ; X86-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,3]
362 ; X86-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,1,1,2,4,5,6,7]
363 ; X86-NEXT: punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm1[0]
367 ; X64: # %bb.0: # %entry
368 ; X64-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,3]
369 ; X64-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,1,1,2,4,5,6,7]
370 ; X64-NEXT: punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm1[0]
373 %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 >
377 ; Test yonah where we convert a shuffle to pextrw and pinrsw
378 define <16 x i8> @t16(<16 x i8> %T0) nounwind readnone {
380 ; X86: # %bb.0: # %entry
381 ; X86-NEXT: pslld $16, %xmm0
385 ; X64: # %bb.0: # %entry
386 ; X64-NEXT: pslld $16, %xmm0
389 %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 >
390 %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 >
395 define <4 x i32> @t17() nounwind {
397 ; X86: # %bb.0: # %entry
398 ; X86-NEXT: pshufd {{.*#+}} xmm0 = mem[0,1,0,1]
399 ; X86-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
403 ; X64: # %bb.0: # %entry
404 ; X64-NEXT: pshufd {{.*#+}} xmm0 = mem[0,1,0,1]
405 ; X64-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
408 %tmp1 = load <4 x float>, ptr undef, align 16
409 %tmp2 = shufflevector <4 x float> %tmp1, <4 x float> undef, <4 x i32> <i32 4, i32 1, i32 2, i32 3>
410 %tmp3 = load <4 x float>, ptr undef, align 16
411 %tmp4 = shufflevector <4 x float> %tmp2, <4 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
412 %tmp5 = bitcast <4 x float> %tmp3 to <4 x i32>
413 %tmp6 = shufflevector <4 x i32> %tmp5, <4 x i32> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
414 %tmp7 = and <4 x i32> %tmp6, <i32 undef, i32 undef, i32 -1, i32 0>