Revert "AVX512: Implemented encoding and intrinsics for vextracti64x4 ,vextracti64x...
[oota-llvm.git] / test / CodeGen / X86 / avx512-insert-extract.ll
1 ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-apple-darwin -mcpu=knl | FileCheck --check-prefix=KNL --check-prefix=CHECK %s
2 ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-apple-darwin -mcpu=skx | FileCheck --check-prefix=SKX --check-prefix=CHECK %s
3
4 ;CHECK-LABEL: test1:
5 ;CHECK: vinsertps
6 ;CHECK: vinsertf32x4
7 ;CHECK: ret
8 define <16 x float> @test1(<16 x float> %x, float* %br, float %y) nounwind {
9   %rrr = load float, float* %br
10   %rrr2 = insertelement <16 x float> %x, float %rrr, i32 1
11   %rrr3 = insertelement <16 x float> %rrr2, float %y, i32 14
12   ret <16 x float> %rrr3
13 }
14
15 ;CHECK-LABEL: test2:
16 ;KNL: vinsertf32x4 $0
17 ;SKX: vinsertf64x2 $0
18 ;CHECK: vextractf32x4 $3
19 ;KNL: vinsertf32x4 $3
20 ;SKX: vinsertf64x2 $3
21 ;CHECK: ret
22 define <8 x double> @test2(<8 x double> %x, double* %br, double %y) nounwind {
23   %rrr = load double, double* %br
24   %rrr2 = insertelement <8 x double> %x, double %rrr, i32 1
25   %rrr3 = insertelement <8 x double> %rrr2, double %y, i32 6
26   ret <8 x double> %rrr3
27 }
28
29 ;CHECK-LABEL: test3:
30 ;CHECK: vextractf32x4 $1
31 ;CHECK: vinsertf32x4 $0
32 ;CHECK: ret
33 define <16 x float> @test3(<16 x float> %x) nounwind {
34   %eee = extractelement <16 x float> %x, i32 4
35   %rrr2 = insertelement <16 x float> %x, float %eee, i32 1
36   ret <16 x float> %rrr2
37 }
38
39 ;CHECK-LABEL: test4:
40 ;CHECK: vextracti32x4 $2
41 ;KNL: vinserti32x4 $0
42 ;SKX: vinserti64x2 $0
43 ;CHECK: ret
44 define <8 x i64> @test4(<8 x i64> %x) nounwind {
45   %eee = extractelement <8 x i64> %x, i32 4
46   %rrr2 = insertelement <8 x i64> %x, i64 %eee, i32 1
47   ret <8 x i64> %rrr2
48 }
49
50 ;CHECK-LABEL: test5:
51 ;CHECK: vextractps
52 ;CHECK: ret
53 define i32 @test5(<4 x float> %x) nounwind {
54   %ef = extractelement <4 x float> %x, i32 3
55   %ei = bitcast float %ef to i32
56   ret i32 %ei
57 }
58
59 ;CHECK-LABEL: test6:
60 ;CHECK: vextractps {{.*}}, (%rdi)
61 ;CHECK: ret
62 define void @test6(<4 x float> %x, float* %out) nounwind {
63   %ef = extractelement <4 x float> %x, i32 3
64   store float %ef, float* %out, align 4
65   ret void
66 }
67
68 ;CHECK-LABEL: test7
69 ;CHECK: vmovd
70 ;CHECK: vpermps %zmm
71 ;CHECK: ret
72 define float @test7(<16 x float> %x, i32 %ind) nounwind {
73   %e = extractelement <16 x float> %x, i32 %ind
74   ret float %e
75 }
76
77 ;CHECK-LABEL: test8
78 ;CHECK: vmovq
79 ;CHECK: vpermpd %zmm
80 ;CHECK: ret
81 define double @test8(<8 x double> %x, i32 %ind) nounwind {
82   %e = extractelement <8 x double> %x, i32 %ind
83   ret double %e
84 }
85
86 ;CHECK-LABEL: test9
87 ;CHECK: vmovd
88 ;CHECK: vpermps %ymm
89 ;CHECK: ret
90 define float @test9(<8 x float> %x, i32 %ind) nounwind {
91   %e = extractelement <8 x float> %x, i32 %ind
92   ret float %e
93 }
94
95 ;CHECK-LABEL: test10
96 ;CHECK: vmovd
97 ;CHECK: vpermd %zmm
98 ;CHECK: vmovd  %xmm0, %eax
99 ;CHECK: ret
100 define i32 @test10(<16 x i32> %x, i32 %ind) nounwind {
101   %e = extractelement <16 x i32> %x, i32 %ind
102   ret i32 %e
103 }
104
105 ;CHECK-LABEL: test11
106 ;CHECK: vpcmpltud
107 ;CHECK: kshiftlw $11
108 ;CHECK: kshiftrw $15
109 ;CHECK: testb
110 ;CHECK: je
111 ;CHECK: ret
112 ;CHECK: ret
113 define <16 x i32> @test11(<16 x i32>%a, <16 x i32>%b) {
114   %cmp_res = icmp ult <16 x i32> %a, %b
115   %ia = extractelement <16 x i1> %cmp_res, i32 4
116   br i1 %ia, label %A, label %B
117   A:
118     ret <16 x i32>%b
119   B:
120    %c = add <16 x i32>%b, %a
121    ret <16 x i32>%c
122 }
123
124 ;CHECK-LABEL: test12
125 ;CHECK: vpcmpgtq
126 ;CHECK: kshiftlw $15
127 ;CHECK: kshiftrw $15
128 ;CHECK: testb
129 ;CHECK: ret
130
131 define i64 @test12(<16 x i64>%a, <16 x i64>%b, i64 %a1, i64 %b1) {
132
133   %cmpvector_func.i = icmp slt <16 x i64> %a, %b
134   %extract24vector_func.i = extractelement <16 x i1> %cmpvector_func.i, i32 0
135   %res = select i1 %extract24vector_func.i, i64 %a1, i64 %b1
136   ret i64 %res
137 }
138
139 ;CHECK-LABEL: test13
140 ;CHECK: cmpl    %esi, %edi
141 ;CHECK: setb    %al
142 ;CHECK: andl    $1, %eax
143 ;CHECK: kmovw   %eax, %k0
144 ;CHECK: movw    $-4
145 ;CHECK: korw    
146 define i16 @test13(i32 %a, i32 %b) {
147   %cmp_res = icmp ult i32 %a, %b
148   %maskv = insertelement <16 x i1> <i1 true, i1 false, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, i1 %cmp_res, i32 0
149   %res = bitcast <16 x i1> %maskv to i16
150   ret i16 %res
151 }
152
153 ;CHECK-LABEL: test14
154 ;CHECK: vpcmpgtq
155 ;KNL: kshiftlw $11
156 ;KNL: kshiftrw $15
157 ;KNL: testb
158 ;SKX: kshiftlb $3
159 ;SKX: kshiftrb $7
160 ;SKX: testb
161 ;CHECK: ret
162
163 define i64 @test14(<8 x i64>%a, <8 x i64>%b, i64 %a1, i64 %b1) {
164
165   %cmpvector_func.i = icmp slt <8 x i64> %a, %b
166   %extract24vector_func.i = extractelement <8 x i1> %cmpvector_func.i, i32 4
167   %res = select i1 %extract24vector_func.i, i64 %a1, i64 %b1
168   ret i64 %res
169 }
170
171 ;CHECK-LABEL: test15
172 ;CHECK: movb (%rdi), %al
173 ;CHECK: andb $1, %al
174 ;CHECK: movw    $-1, %ax
175 ;CHECK: cmovew
176 define i16 @test15(i1 *%addr) {
177   %x = load i1 , i1 * %addr, align 1
178   %x1 = insertelement <16 x i1> undef, i1 %x, i32 10
179   %x2 = bitcast <16 x i1>%x1 to i16
180   ret i16 %x2
181 }
182
183 ;CHECK-LABEL: test16
184 ;CHECK: movb (%rdi), %al
185 ;CHECK: andw $1, %ax
186 ;CHECK: kmovw
187 ;CHECK: kshiftlw        $10
188 ;CHECK: korw
189 ;CHECK: ret
190 define i16 @test16(i1 *%addr, i16 %a) {
191   %x = load i1 , i1 * %addr, align 128
192   %a1 = bitcast i16 %a to <16 x i1>
193   %x1 = insertelement <16 x i1> %a1, i1 %x, i32 10
194   %x2 = bitcast <16 x i1>%x1 to i16
195   ret i16 %x2
196 }
197
198 ;CHECK-LABEL: test17
199 ;KNL: movb (%rdi), %al
200 ;KNL: andw $1, %ax
201 ;KNL: kshiftlw $4
202 ;KNL: korw
203 ;SKX: kshiftlb $4
204 ;SKX: korb
205 ;CHECK: ret
206 define i8 @test17(i1 *%addr, i8 %a) {
207   %x = load i1 , i1 * %addr, align 128
208   %a1 = bitcast i8 %a to <8 x i1>
209   %x1 = insertelement <8 x i1> %a1, i1 %x, i32 4
210   %x2 = bitcast <8 x i1>%x1 to i8
211   ret i8 %x2
212 }
213