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=+ssse3 | FileCheck %s --check-prefixes=SSE,SSSE3
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefixes=SSE,SSE41
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefixes=AVX,AVX1
6 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=AVX,AVX2
9 ; Partial Vector Loads - PR16739
12 define <4 x float> @load_float4_float3(<4 x float>* nocapture readonly dereferenceable(16)) {
13 ; SSE-LABEL: load_float4_float3:
15 ; SSE-NEXT: movups (%rdi), %xmm0
18 ; AVX-LABEL: load_float4_float3:
20 ; AVX-NEXT: vmovups (%rdi), %xmm0
22 %p0 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 0
23 %p1 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 1
24 %p2 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
25 %ld0 = load float, float* %p0, align 4
26 %ld1 = load float, float* %p1, align 4
27 %ld2 = load float, float* %p2, align 4
28 %r0 = insertelement <4 x float> undef, float %ld0, i32 0
29 %r1 = insertelement <4 x float> %r0, float %ld1, i32 1
30 %r2 = insertelement <4 x float> %r1, float %ld2, i32 2
34 define <4 x float> @load_float4_float3_0122(<4 x float>* nocapture readonly dereferenceable(16)) {
35 ; SSE-LABEL: load_float4_float3_0122:
37 ; SSE-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
38 ; SSE-NEXT: movups (%rdi), %xmm0
39 ; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,0]
42 ; AVX-LABEL: load_float4_float3_0122:
44 ; AVX-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
45 ; AVX-NEXT: vmovups (%rdi), %xmm1
46 ; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm1[0,1],xmm0[0,0]
48 %p0 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 0
49 %p1 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 1
50 %p2 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
51 %ld0 = load float, float* %p0, align 4
52 %ld1 = load float, float* %p1, align 4
53 %ld2 = load float, float* %p2, align 4
54 %r0 = insertelement <4 x float> undef, float %ld0, i32 0
55 %r1 = insertelement <4 x float> %r0, float %ld1, i32 1
56 %r2 = insertelement <4 x float> %r1, float %ld2, i32 2
57 %r3 = insertelement <4 x float> %r2, float %ld2, i32 3
61 define <8 x float> @load_float8_float3(<4 x float>* nocapture readonly dereferenceable(16)) {
62 ; SSE-LABEL: load_float8_float3:
64 ; SSE-NEXT: movups (%rdi), %xmm0
67 ; AVX-LABEL: load_float8_float3:
69 ; AVX-NEXT: vmovups (%rdi), %xmm0
71 %p0 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 0
72 %p1 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 1
73 %p2 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
74 %ld0 = load float, float* %p0, align 4
75 %ld1 = load float, float* %p1, align 4
76 %ld2 = load float, float* %p2, align 4
77 %r0 = insertelement <8 x float> undef, float %ld0, i32 0
78 %r1 = insertelement <8 x float> %r0, float %ld1, i32 1
79 %r2 = insertelement <8 x float> %r1, float %ld2, i32 2
83 define <8 x float> @load_float8_float3_0122(<4 x float>* nocapture readonly dereferenceable(16)) {
84 ; SSE-LABEL: load_float8_float3_0122:
86 ; SSE-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
87 ; SSE-NEXT: movups (%rdi), %xmm0
88 ; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,0]
91 ; AVX-LABEL: load_float8_float3_0122:
93 ; AVX-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
94 ; AVX-NEXT: vmovups (%rdi), %xmm1
95 ; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm1[0,1],xmm0[0,0]
97 %p0 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 0
98 %p1 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 1
99 %p2 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
100 %ld0 = load float, float* %p0, align 4
101 %ld1 = load float, float* %p1, align 4
102 %ld2 = load float, float* %p2, align 4
103 %r0 = insertelement <8 x float> undef, float %ld0, i32 0
104 %r1 = insertelement <8 x float> %r0, float %ld1, i32 1
105 %r2 = insertelement <8 x float> %r1, float %ld2, i32 2
106 %r3 = insertelement <8 x float> %r2, float %ld2, i32 3
110 define <4 x float> @load_float4_float3_as_float2_float(<4 x float>* nocapture readonly dereferenceable(16)) {
111 ; SSE-LABEL: load_float4_float3_as_float2_float:
113 ; SSE-NEXT: movups (%rdi), %xmm0
116 ; AVX-LABEL: load_float4_float3_as_float2_float:
118 ; AVX-NEXT: vmovups (%rdi), %xmm0
120 %2 = bitcast <4 x float>* %0 to <2 x float>*
121 %3 = load <2 x float>, <2 x float>* %2, align 4
122 %4 = extractelement <2 x float> %3, i32 0
123 %5 = insertelement <4 x float> undef, float %4, i32 0
124 %6 = extractelement <2 x float> %3, i32 1
125 %7 = insertelement <4 x float> %5, float %6, i32 1
126 %8 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
127 %9 = load float, float* %8, align 4
128 %10 = insertelement <4 x float> %7, float %9, i32 2
132 define <4 x float> @load_float4_float3_as_float2_float_0122(<4 x float>* nocapture readonly dereferenceable(16)) {
133 ; SSE-LABEL: load_float4_float3_as_float2_float_0122:
135 ; SSE-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
136 ; SSE-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
137 ; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,0]
140 ; AVX-LABEL: load_float4_float3_as_float2_float_0122:
142 ; AVX-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero
143 ; AVX-NEXT: vmovss {{.*#+}} xmm1 = mem[0],zero,zero,zero
144 ; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,0]
146 %2 = bitcast <4 x float>* %0 to <2 x float>*
147 %3 = load <2 x float>, <2 x float>* %2, align 4
148 %4 = extractelement <2 x float> %3, i32 0
149 %5 = insertelement <4 x float> undef, float %4, i32 0
150 %6 = extractelement <2 x float> %3, i32 1
151 %7 = insertelement <4 x float> %5, float %6, i32 1
152 %8 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
153 %9 = load float, float* %8, align 4
154 %10 = insertelement <4 x float> %7, float %9, i32 2
155 %11 = insertelement <4 x float> %10, float %9, i32 3
159 define <4 x float> @load_float4_float3_trunc(<4 x float>* nocapture readonly dereferenceable(16)) {
160 ; SSE-LABEL: load_float4_float3_trunc:
162 ; SSE-NEXT: movaps (%rdi), %xmm0
165 ; AVX-LABEL: load_float4_float3_trunc:
167 ; AVX-NEXT: vmovaps (%rdi), %xmm0
169 %2 = bitcast <4 x float>* %0 to i64*
170 %3 = load i64, i64* %2, align 16
171 %4 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
172 %5 = bitcast float* %4 to i64*
173 %6 = load i64, i64* %5, align 8
174 %7 = trunc i64 %3 to i32
175 %8 = bitcast i32 %7 to float
176 %9 = insertelement <4 x float> undef, float %8, i32 0
177 %10 = lshr i64 %3, 32
178 %11 = trunc i64 %10 to i32
179 %12 = bitcast i32 %11 to float
180 %13 = insertelement <4 x float> %9, float %12, i32 1
181 %14 = trunc i64 %6 to i32
182 %15 = bitcast i32 %14 to float
183 %16 = insertelement <4 x float> %13, float %15, i32 2
187 define <4 x float> @load_float4_float3_trunc_0122(<4 x float>* nocapture readonly dereferenceable(16)) {
188 ; SSE-LABEL: load_float4_float3_trunc_0122:
190 ; SSE-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
191 ; SSE-NEXT: movaps (%rdi), %xmm0
192 ; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,0]
195 ; AVX-LABEL: load_float4_float3_trunc_0122:
197 ; AVX-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
198 ; AVX-NEXT: vmovaps (%rdi), %xmm1
199 ; AVX-NEXT: vshufps {{.*#+}} xmm0 = xmm1[0,1],xmm0[0,0]
201 %2 = bitcast <4 x float>* %0 to i64*
202 %3 = load i64, i64* %2, align 16
203 %4 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
204 %5 = bitcast float* %4 to i64*
205 %6 = load i64, i64* %5, align 8
206 %7 = trunc i64 %3 to i32
207 %8 = bitcast i32 %7 to float
208 %9 = insertelement <4 x float> undef, float %8, i32 0
209 %10 = lshr i64 %3, 32
210 %11 = trunc i64 %10 to i32
211 %12 = bitcast i32 %11 to float
212 %13 = insertelement <4 x float> %9, float %12, i32 1
213 %14 = trunc i64 %6 to i32
214 %15 = bitcast i32 %14 to float
215 %16 = insertelement <4 x float> %13, float %15, i32 2
216 %17 = insertelement <4 x float> %16, float %15, i32 3
220 define <4 x float> @load_float4_float3_trunc_0123(<4 x float>* nocapture readonly dereferenceable(16)) {
221 ; SSE2-LABEL: load_float4_float3_trunc_0123:
223 ; SSE2-NEXT: movaps (%rdi), %xmm0
224 ; SSE2-NEXT: movhps {{.*#+}} xmm0 = xmm0[0,1],mem[0,1]
227 ; SSSE3-LABEL: load_float4_float3_trunc_0123:
229 ; SSSE3-NEXT: movaps (%rdi), %xmm0
230 ; SSSE3-NEXT: movhps {{.*#+}} xmm0 = xmm0[0,1],mem[0,1]
233 ; SSE41-LABEL: load_float4_float3_trunc_0123:
235 ; SSE41-NEXT: movaps (%rdi), %xmm0
236 ; SSE41-NEXT: insertps {{.*#+}} xmm0 = xmm0[0,1],mem[0],xmm0[3]
237 ; SSE41-NEXT: insertps {{.*#+}} xmm0 = xmm0[0,1,2],mem[0]
240 ; AVX-LABEL: load_float4_float3_trunc_0123:
242 ; AVX-NEXT: vmovaps (%rdi), %xmm0
243 ; AVX-NEXT: vinsertps {{.*#+}} xmm0 = xmm0[0,1],mem[0],xmm0[3]
244 ; AVX-NEXT: vinsertps {{.*#+}} xmm0 = xmm0[0,1,2],mem[0]
246 %2 = bitcast <4 x float>* %0 to i64*
247 %3 = load i64, i64* %2, align 16
248 %4 = getelementptr inbounds <4 x float>, <4 x float>* %0, i64 0, i64 2
249 %5 = bitcast float* %4 to i64*
250 %6 = load i64, i64* %5, align 8
251 %7 = trunc i64 %3 to i32
252 %8 = bitcast i32 %7 to float
253 %9 = insertelement <4 x float> undef, float %8, i32 0
254 %10 = lshr i64 %3, 32
255 %11 = trunc i64 %10 to i32
256 %12 = bitcast i32 %11 to float
257 %13 = insertelement <4 x float> %9, float %12, i32 1
258 %14 = trunc i64 %6 to i32
259 %15 = bitcast i32 %14 to float
260 %16 = insertelement <4 x float> %13, float %15, i32 2
261 %17 = lshr i64 %6, 32
262 %18 = trunc i64 %17 to i32
263 %19 = bitcast i32 %18 to float
264 %20 = insertelement <4 x float> %16, float %19, i32 3
269 define <4 x double> @load_double4_0u2u(double* nocapture readonly dereferenceable(32)) {
270 ; SSE2-LABEL: load_double4_0u2u:
272 ; SSE2-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
273 ; SSE2-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
274 ; SSE2-NEXT: movlhps {{.*#+}} xmm0 = xmm0[0,0]
275 ; SSE2-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0,0]
278 ; SSSE3-LABEL: load_double4_0u2u:
280 ; SSSE3-NEXT: movddup {{.*#+}} xmm0 = mem[0,0]
281 ; SSSE3-NEXT: movddup {{.*#+}} xmm1 = mem[0,0]
284 ; SSE41-LABEL: load_double4_0u2u:
286 ; SSE41-NEXT: movddup {{.*#+}} xmm0 = mem[0,0]
287 ; SSE41-NEXT: movddup {{.*#+}} xmm1 = mem[0,0]
290 ; AVX-LABEL: load_double4_0u2u:
292 ; AVX-NEXT: vmovddup {{.*#+}} ymm0 = mem[0,0,2,2]
294 %2 = load double, double* %0, align 8
295 %3 = insertelement <4 x double> undef, double %2, i32 0
296 %4 = getelementptr inbounds double, double* %0, i64 2
297 %5 = load double, double* %4, align 8
298 %6 = insertelement <4 x double> %3, double %5, i32 2
299 %7 = shufflevector <4 x double> %6, <4 x double> undef, <4 x i32> <i32 0, i32 0, i32 2, i32 2>
303 ; Test case identified in rL366501
304 @h = local_unnamed_addr global i8 0, align 1
305 define i32 @load_partial_illegal_type() {
306 ; SSE2-LABEL: load_partial_illegal_type:
308 ; SSE2-NEXT: movzwl {{.*}}(%rip), %eax
309 ; SSE2-NEXT: movd %eax, %xmm0
310 ; SSE2-NEXT: pand {{.*}}(%rip), %xmm0
311 ; SSE2-NEXT: por {{.*}}(%rip), %xmm0
312 ; SSE2-NEXT: movd %xmm0, %eax
315 ; SSSE3-LABEL: load_partial_illegal_type:
317 ; SSSE3-NEXT: movzwl {{.*}}(%rip), %eax
318 ; SSSE3-NEXT: movd %eax, %xmm0
319 ; SSSE3-NEXT: pshufb {{.*#+}} xmm0 = xmm0[0,1],zero,xmm0[3,4,5,6,7,8,9,10,11,12,13,14,15]
320 ; SSSE3-NEXT: por {{.*}}(%rip), %xmm0
321 ; SSSE3-NEXT: movd %xmm0, %eax
324 ; SSE41-LABEL: load_partial_illegal_type:
326 ; SSE41-NEXT: movzwl {{.*}}(%rip), %eax
327 ; SSE41-NEXT: movd %eax, %xmm0
328 ; SSE41-NEXT: movl $2, %eax
329 ; SSE41-NEXT: pinsrb $2, %eax, %xmm0
330 ; SSE41-NEXT: movd %xmm0, %eax
333 ; AVX-LABEL: load_partial_illegal_type:
335 ; AVX-NEXT: movzwl {{.*}}(%rip), %eax
336 ; AVX-NEXT: vmovd %eax, %xmm0
337 ; AVX-NEXT: movl $2, %eax
338 ; AVX-NEXT: vpinsrb $2, %eax, %xmm0, %xmm0
339 ; AVX-NEXT: vmovd %xmm0, %eax
341 %1 = load <2 x i8>, <2 x i8>* bitcast (i8* @h to <2 x i8>*), align 1
342 %2 = shufflevector <2 x i8> %1, <2 x i8> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
343 %3 = insertelement <4 x i8> %2, i8 2, i32 2
344 %4 = bitcast <4 x i8> %3 to i32
348 define void @PR43227(i32* %explicit_0, <8 x i32>* %explicit_1) {
349 ; SSE2-LABEL: PR43227:
351 ; SSE2-NEXT: movq {{.*#+}} xmm0 = mem[0],zero
352 ; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,1,2,3]
353 ; SSE2-NEXT: xorps %xmm1, %xmm1
354 ; SSE2-NEXT: xorps %xmm2, %xmm2
355 ; SSE2-NEXT: movss {{.*#+}} xmm2 = xmm0[0],xmm2[1,2,3]
356 ; SSE2-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
357 ; SSE2-NEXT: movlhps {{.*#+}} xmm2 = xmm2[0],xmm0[0]
358 ; SSE2-NEXT: movaps %xmm1, 672(%rsi)
359 ; SSE2-NEXT: movaps %xmm2, 688(%rsi)
362 ; SSSE3-LABEL: PR43227:
364 ; SSSE3-NEXT: movq {{.*#+}} xmm0 = mem[0],zero
365 ; SSSE3-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,1,2,3]
366 ; SSSE3-NEXT: xorps %xmm1, %xmm1
367 ; SSSE3-NEXT: xorps %xmm2, %xmm2
368 ; SSSE3-NEXT: movss {{.*#+}} xmm2 = xmm0[0],xmm2[1,2,3]
369 ; SSSE3-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
370 ; SSSE3-NEXT: movlhps {{.*#+}} xmm2 = xmm2[0],xmm0[0]
371 ; SSSE3-NEXT: movaps %xmm1, 672(%rsi)
372 ; SSSE3-NEXT: movaps %xmm2, 688(%rsi)
375 ; SSE41-LABEL: PR43227:
377 ; SSE41-NEXT: movq {{.*#+}} xmm0 = mem[0],zero
378 ; SSE41-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,1,2,3]
379 ; SSE41-NEXT: pxor %xmm1, %xmm1
380 ; SSE41-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3,4,5,6,7]
381 ; SSE41-NEXT: movd {{.*#+}} xmm2 = mem[0],zero,zero,zero
382 ; SSE41-NEXT: punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm2[0]
383 ; SSE41-NEXT: movdqa %xmm1, 672(%rsi)
384 ; SSE41-NEXT: movdqa %xmm0, 688(%rsi)
387 ; AVX-LABEL: PR43227:
389 ; AVX-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero
390 ; AVX-NEXT: vpermilps {{.*#+}} xmm0 = xmm0[1,1,2,3]
391 ; AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1
392 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
393 ; AVX-NEXT: vmovss {{.*#+}} xmm1 = mem[0],zero,zero,zero
394 ; AVX-NEXT: vmovlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
395 ; AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1
396 ; AVX-NEXT: vinsertf128 $1, %xmm0, %ymm1, %ymm0
397 ; AVX-NEXT: vmovaps %ymm0, 672(%rsi)
398 ; AVX-NEXT: vzeroupper
400 %1 = getelementptr i32, i32* %explicit_0, i64 63
401 %2 = bitcast i32* %1 to <3 x i32>*
402 %3 = load <3 x i32>, <3 x i32>* %2, align 1
403 %4 = shufflevector <3 x i32> %3, <3 x i32> undef, <2 x i32> <i32 1, i32 2>
404 %5 = shufflevector <2 x i32> %4, <2 x i32> undef, <8 x i32> <i32 0, i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
405 %6 = shufflevector <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 undef, i32 0, i32 undef, i32 0>, <8 x i32> %5, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 5, i32 9, i32 7>
406 %7 = getelementptr inbounds <8 x i32>, <8 x i32>* %explicit_1, i64 21
407 store <8 x i32> %6, <8 x i32>* %7, align 32