1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=avx2 | FileCheck %s --check-prefixes=X86,X86_AVX256
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx2 | FileCheck %s --check-prefixes=X64,X64_AVX256
4 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=avx512f | FileCheck %s --check-prefixes=X86,X86_AVX512
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx512f | FileCheck %s --check-prefixes=X64,X64_AVX512
7 define <8 x float> @insert_subvector_256(i16 %x0, i16 %x1, <8 x float> %v) nounwind {
8 ; X86-LABEL: insert_subvector_256:
10 ; X86-NEXT: vmovd {{.*#+}} xmm1 = mem[0],zero,zero,zero
11 ; X86-NEXT: vpinsrw $1, {{[0-9]+}}(%esp), %xmm1, %xmm1
12 ; X86-NEXT: vpbroadcastd %xmm1, %xmm1
13 ; X86-NEXT: vpblendd {{.*#+}} ymm0 = ymm0[0],ymm1[1],ymm0[2,3,4,5,6,7]
16 ; X64-LABEL: insert_subvector_256:
18 ; X64-NEXT: vmovd %edi, %xmm1
19 ; X64-NEXT: vpinsrw $1, %esi, %xmm1, %xmm1
20 ; X64-NEXT: vpbroadcastd %xmm1, %xmm1
21 ; X64-NEXT: vpblendd {{.*#+}} ymm0 = ymm0[0],ymm1[1],ymm0[2,3,4,5,6,7]
23 %ins1 = insertelement <2 x i16> undef, i16 %x0, i32 0
24 %ins2 = insertelement <2 x i16> %ins1, i16 %x1, i32 1
25 %bc = bitcast <2 x i16> %ins2 to float
26 %ins3 = insertelement <8 x float> %v, float %bc, i32 1
30 define <8 x i64> @insert_subvector_512(i32 %x0, i32 %x1, <8 x i64> %v) nounwind {
31 ; X86_AVX256-LABEL: insert_subvector_512:
32 ; X86_AVX256: # %bb.0:
33 ; X86_AVX256-NEXT: pushl %ebp
34 ; X86_AVX256-NEXT: movl %esp, %ebp
35 ; X86_AVX256-NEXT: andl $-8, %esp
36 ; X86_AVX256-NEXT: subl $8, %esp
37 ; X86_AVX256-NEXT: vmovsd {{.*#+}} xmm2 = mem[0],zero
38 ; X86_AVX256-NEXT: vmovlps %xmm2, (%esp)
39 ; X86_AVX256-NEXT: vextracti128 $1, %ymm0, %xmm2
40 ; X86_AVX256-NEXT: vpinsrd $0, (%esp), %xmm2, %xmm2
41 ; X86_AVX256-NEXT: vpinsrd $1, {{[0-9]+}}(%esp), %xmm2, %xmm2
42 ; X86_AVX256-NEXT: vinserti128 $1, %xmm2, %ymm0, %ymm0
43 ; X86_AVX256-NEXT: movl %ebp, %esp
44 ; X86_AVX256-NEXT: popl %ebp
45 ; X86_AVX256-NEXT: retl
47 ; X64_AVX256-LABEL: insert_subvector_512:
48 ; X64_AVX256: # %bb.0:
49 ; X64_AVX256-NEXT: vmovd %edi, %xmm2
50 ; X64_AVX256-NEXT: vpinsrd $1, %esi, %xmm2, %xmm2
51 ; X64_AVX256-NEXT: vmovq %xmm2, %rax
52 ; X64_AVX256-NEXT: vextracti128 $1, %ymm0, %xmm2
53 ; X64_AVX256-NEXT: vpinsrq $0, %rax, %xmm2, %xmm2
54 ; X64_AVX256-NEXT: vinserti128 $1, %xmm2, %ymm0, %ymm0
55 ; X64_AVX256-NEXT: retq
57 ; X86_AVX512-LABEL: insert_subvector_512:
58 ; X86_AVX512: # %bb.0:
59 ; X86_AVX512-NEXT: vmovq {{.*#+}} xmm1 = mem[0],zero
60 ; X86_AVX512-NEXT: vmovdqa64 {{.*#+}} zmm2 = [0,0,1,0,8,0,3,0,4,0,5,0,6,0,7,0]
61 ; X86_AVX512-NEXT: vpermt2q %zmm1, %zmm2, %zmm0
62 ; X86_AVX512-NEXT: retl
64 ; X64_AVX512-LABEL: insert_subvector_512:
65 ; X64_AVX512: # %bb.0:
66 ; X64_AVX512-NEXT: vmovd %edi, %xmm1
67 ; X64_AVX512-NEXT: vpinsrd $1, %esi, %xmm1, %xmm1
68 ; X64_AVX512-NEXT: vmovdqa64 {{.*#+}} zmm2 = [0,1,8,3,4,5,6,7]
69 ; X64_AVX512-NEXT: vpermt2q %zmm1, %zmm2, %zmm0
70 ; X64_AVX512-NEXT: retq
71 %ins1 = insertelement <2 x i32> undef, i32 %x0, i32 0
72 %ins2 = insertelement <2 x i32> %ins1, i32 %x1, i32 1
73 %bc = bitcast <2 x i32> %ins2 to i64
74 %ins3 = insertelement <8 x i64> %v, i64 %bc, i32 2
78 ; PR34716 - https://bugs.llvm.org/show_bug.cgi?id=34716
79 ; Special case: if we're inserting into an undef vector, we can optimize more.
81 define <8 x i64> @insert_subvector_into_undef(i32 %x0, i32 %x1) nounwind {
82 ; X86_AVX256-LABEL: insert_subvector_into_undef:
83 ; X86_AVX256: # %bb.0:
84 ; X86_AVX256-NEXT: vbroadcastsd {{[0-9]+}}(%esp), %ymm0
85 ; X86_AVX256-NEXT: vmovaps %ymm0, %ymm1
86 ; X86_AVX256-NEXT: retl
88 ; X64_AVX256-LABEL: insert_subvector_into_undef:
89 ; X64_AVX256: # %bb.0:
90 ; X64_AVX256-NEXT: vmovd %edi, %xmm0
91 ; X64_AVX256-NEXT: vpinsrd $1, %esi, %xmm0, %xmm0
92 ; X64_AVX256-NEXT: vpbroadcastq %xmm0, %ymm0
93 ; X64_AVX256-NEXT: vmovdqa %ymm0, %ymm1
94 ; X64_AVX256-NEXT: retq
96 ; X86_AVX512-LABEL: insert_subvector_into_undef:
97 ; X86_AVX512: # %bb.0:
98 ; X86_AVX512-NEXT: vbroadcastsd {{[0-9]+}}(%esp), %zmm0
99 ; X86_AVX512-NEXT: retl
101 ; X64_AVX512-LABEL: insert_subvector_into_undef:
102 ; X64_AVX512: # %bb.0:
103 ; X64_AVX512-NEXT: vmovd %edi, %xmm0
104 ; X64_AVX512-NEXT: vpinsrd $1, %esi, %xmm0, %xmm0
105 ; X64_AVX512-NEXT: vpbroadcastq %xmm0, %zmm0
106 ; X64_AVX512-NEXT: retq
107 %ins1 = insertelement <2 x i32> undef, i32 %x0, i32 0
108 %ins2 = insertelement <2 x i32> %ins1, i32 %x1, i32 1
109 %bc = bitcast <2 x i32> %ins2 to i64
110 %ins3 = insertelement <8 x i64> undef, i64 %bc, i32 0
111 %splat = shufflevector <8 x i64> %ins3, <8 x i64> undef, <8 x i32> zeroinitializer