1 ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-apple-darwin -mcpu=knl | FileCheck %s --check-prefix=KNL --check-prefix=CHECK
2 ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-apple-darwin -mcpu=skx | FileCheck %s --check-prefix=SKX --check-prefix=CHECK
8 define i16 @mask16(i16 %x) {
9 %m0 = bitcast i16 %x to <16 x i1>
10 %m1 = xor <16 x i1> %m0, <i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1>
11 %ret = bitcast <16 x i1> %m1 to i16
23 define i8 @mask8(i8 %x) {
24 %m0 = bitcast i8 %x to <8 x i1>
25 %m1 = xor <8 x i1> %m0, <i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1>
26 %ret = bitcast <8 x i1> %m1 to i8
30 ; CHECK-LABEL: mask16_mem
31 ; CHECK: kmovw ([[ARG1:%rdi|%rcx]]), %k{{[0-7]}}
33 ; CHECK-NEXT: kmovw %k{{[0-7]}}, ([[ARG1]])
36 define void @mask16_mem(i16* %ptr) {
37 %x = load i16, i16* %ptr, align 4
38 %m0 = bitcast i16 %x to <16 x i1>
39 %m1 = xor <16 x i1> %m0, <i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1>
40 %ret = bitcast <16 x i1> %m1 to i16
41 store i16 %ret, i16* %ptr, align 4
45 ; CHECK-LABEL: mask8_mem
46 ; KNL: kmovw ([[ARG1]]), %k{{[0-7]}}
48 ; KNL-NEXT: kmovw %k{{[0-7]}}, ([[ARG1]])
49 ; SKX: kmovb ([[ARG1]]), %k{{[0-7]}}
51 ; SKX-NEXT: kmovb %k{{[0-7]}}, ([[ARG1]])
53 define void @mask8_mem(i8* %ptr) {
54 %x = load i8, i8* %ptr, align 4
55 %m0 = bitcast i8 %x to <8 x i1>
56 %m1 = xor <8 x i1> %m0, <i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1, i1 -1>
57 %ret = bitcast <8 x i1> %m1 to i8
58 store i8 %ret, i8* %ptr, align 4
66 define i16 @mand16(i16 %x, i16 %y) {
67 %ma = bitcast i16 %x to <16 x i1>
68 %mb = bitcast i16 %y to <16 x i1>
69 %mc = and <16 x i1> %ma, %mb
70 %md = xor <16 x i1> %ma, %mb
71 %me = or <16 x i1> %mc, %md
72 %ret = bitcast <16 x i1> %me to i16
76 ; CHECK-LABEL: shuf_test1
78 define i8 @shuf_test1(i16 %v) nounwind {
79 %v1 = bitcast i16 %v to <16 x i1>
80 %mask = shufflevector <16 x i1> %v1, <16 x i1> undef, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
81 %mask1 = bitcast <8 x i1> %mask to i8
85 ; CHECK-LABEL: zext_test1
90 define i32 @zext_test1(<16 x i32> %a, <16 x i32> %b) {
91 %cmp_res = icmp ugt <16 x i32> %a, %b
92 %cmp_res.i1 = extractelement <16 x i1> %cmp_res, i32 5
93 %res = zext i1 %cmp_res.i1 to i32
97 ; CHECK-LABEL: zext_test2
102 define i16 @zext_test2(<16 x i32> %a, <16 x i32> %b) {
103 %cmp_res = icmp ugt <16 x i32> %a, %b
104 %cmp_res.i1 = extractelement <16 x i1> %cmp_res, i32 5
105 %res = zext i1 %cmp_res.i1 to i16
109 ; CHECK-LABEL: zext_test3
114 define i8 @zext_test3(<16 x i32> %a, <16 x i32> %b) {
115 %cmp_res = icmp ugt <16 x i32> %a, %b
116 %cmp_res.i1 = extractelement <16 x i1> %cmp_res, i32 5
117 %res = zext i1 %cmp_res.i1 to i8
122 ; KNL: kmovw %k0, %eax
123 ; KNL: movb %al, (%rdi)
124 ; SKX: kmovb %k0, (%rdi)
125 define i8 @conv1(<8 x i1>* %R) {
127 store <8 x i1> <i1 1, i1 1, i1 1, i1 1, i1 1, i1 1, i1 1, i1 1>, <8 x i1>* %R
129 %maskPtr = alloca <8 x i1>
130 store <8 x i1> <i1 0, i1 1, i1 1, i1 1, i1 1, i1 1, i1 1, i1 1>, <8 x i1>* %maskPtr
131 %mask = load <8 x i1>, <8 x i1>* %maskPtr
132 %mask_convert = bitcast <8 x i1> %mask to i8
141 define <4 x i32> @test4(<4 x i64> %x, <4 x i64> %y, <4 x i64> %x1, <4 x i64> %y1) {
142 %x_gt_y = icmp sgt <4 x i64> %x, %y
143 %x1_gt_y1 = icmp sgt <4 x i64> %x1, %y1
144 %res = icmp sgt <4 x i1>%x_gt_y, %x1_gt_y1
145 %resse = sext <4 x i1>%res to <4 x i32>
154 define <2 x i64> @test5(<2 x i64> %x, <2 x i64> %y, <2 x i64> %x1, <2 x i64> %y1) {
155 %x_gt_y = icmp slt <2 x i64> %x, %y
156 %x1_gt_y1 = icmp sgt <2 x i64> %x1, %y1
157 %res = icmp slt <2 x i1>%x_gt_y, %x1_gt_y1
158 %resse = sext <2 x i1>%res to <2 x i64>
165 ; KNL: kmovw %eax, %k1
166 ; KNL vptestmd {{.*}}, %k0 {%k1}
170 ; SKX: kmovw %eax, %k1
172 define void @test6(<16 x i1> %mask) {
174 %a= and <16 x i1> %mask, <i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false>
175 %b = bitcast <16 x i1> %a to i16
176 %c = icmp eq i16 %b, 0
177 br i1 %c, label %true, label %false
189 ; KNL: vptestmq {{.*}}, %k0
194 ; SKX: kmovb %eax, %k1
197 define void @test7(<8 x i1> %mask) {
199 %a= or <8 x i1> %mask, <i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false>
200 %b = bitcast <8 x i1> %a to i8
201 %c = icmp eq i8 %b, 0
202 br i1 %c, label %true, label %false
212 ; KNL: vpxord %zmm2, %zmm2, %zmm2
214 ; KNL: vpcmpltud %zmm2, %zmm1, %k1
216 ; KNL: vpcmpgtd %zmm2, %zmm0, %k1
220 ; SKX: vpcmpltud {{.*}}, %k0
222 ; SKX: vpcmpgtd {{.*}}, %k0
225 define <16 x i8> @test8(<16 x i32>%a, <16 x i32>%b, i32 %a1, i32 %b1) {
226 %cond = icmp sgt i32 %a1, %b1
227 %cmp1 = icmp sgt <16 x i32> %a, zeroinitializer
228 %cmp2 = icmp ult <16 x i32> %b, zeroinitializer
229 %mix = select i1 %cond, <16 x i1> %cmp1, <16 x i1> %cmp2
230 %res = sext <16 x i1> %mix to <16 x i8>
236 ; KNL: vpmovsxbd %xmm1, %zmm0
238 ; KNL: vpmovsxbd %xmm0, %zmm0
241 ; SKX: vpmovb2m %xmm1, %k0
242 ; SKX: vpmovm2b %k0, %xmm0
244 ; SKX: vpmovb2m %xmm0, %k0
245 ; SKX: vpmovm2b %k0, %xmm0
247 define <16 x i1> @test9(<16 x i1>%a, <16 x i1>%b, i32 %a1, i32 %b1) {
248 %mask = icmp sgt i32 %a1, %b1
249 %c = select i1 %mask, <16 x i1>%a, <16 x i1>%b
255 ; KNL: vpmovsxwq %xmm1, %zmm0
257 ; KNL: vpmovsxwq %xmm0, %zmm0
261 ; SKX: vpmovw2m %xmm1, %k0
262 ; SKX: vpmovm2w %k0, %xmm0
264 ; SKX: vpmovw2m %xmm0, %k0
265 ; SKX: vpmovm2w %k0, %xmm0
266 define <8 x i1> @test10(<8 x i1>%a, <8 x i1>%b, i32 %a1, i32 %b1) {
267 %mask = icmp sgt i32 %a1, %b1
268 %c = select i1 %mask, <8 x i1>%a, <8 x i1>%b
274 ; SKX: vpmovd2m %xmm1, %k0
275 ; SKX: vpmovm2d %k0, %xmm0
277 ; SKX: vpmovd2m %xmm0, %k0
278 ; SKX: vpmovm2d %k0, %xmm0
279 define <4 x i1> @test11(<4 x i1>%a, <4 x i1>%b, i32 %a1, i32 %b1) {
280 %mask = icmp sgt i32 %a1, %b1
281 %c = select i1 %mask, <4 x i1>%a, <4 x i1>%b
286 ; KNL: movl %edi, %eax
287 define i32 @test12(i32 %x, i32 %y) {
288 %a = bitcast i16 21845 to <16 x i1>
289 %b = extractelement <16 x i1> %a, i32 0
290 %c = select i1 %b, i32 %x, i32 %y
295 ; KNL: movl %esi, %eax
296 define i32 @test13(i32 %x, i32 %y) {
297 %a = bitcast i16 21845 to <16 x i1>
298 %b = extractelement <16 x i1> %a, i32 3
299 %c = select i1 %b, i32 %x, i32 %y
305 ; SKX: kmovb %eax, %k0
306 ; SKX: vpmovm2d %k0, %xmm0
308 define <4 x i1> @test14() {
309 %a = bitcast i16 21845 to <16 x i1>
310 %b = extractelement <16 x i1> %a, i32 2
311 %c = insertelement <4 x i1> <i1 true, i1 false, i1 false, i1 true>, i1 %b, i32 1
317 define <16 x i1> @test15(i32 %x, i32 %y) {
318 %a = bitcast i16 21845 to <16 x i1>
319 %b = bitcast i16 1 to <16 x i1>
320 %mask = icmp sgt i32 %x, %y
321 %c = select i1 %mask, <16 x i1> %a, <16 x i1> %b
326 ; SKX: kxnorw %k1, %k1, %k1
327 ; SKX: kshiftrw $15, %k1, %k1
328 ; SKX: kshiftlq $5, %k1, %k1
329 ; SKX: korq %k1, %k0, %k0
330 ; SKX: vpmovm2b %k0, %zmm0
331 define <64 x i8> @test16(i64 %x) {
332 %a = bitcast i64 %x to <64 x i1>
333 %b = insertelement <64 x i1>%a, i1 true, i32 5
334 %c = sext <64 x i1>%b to <64 x i8>
341 ; SKX: kmovw %eax, %k1
342 ; SKX: kshiftlq $5, %k1, %k1
343 ; SKX: korq %k1, %k0, %k0
344 ; SKX: vpmovm2b %k0, %zmm0
345 define <64 x i8> @test17(i64 %x, i32 %y, i32 %z) {
346 %a = bitcast i64 %x to <64 x i1>
347 %b = icmp sgt i32 %y, %z
348 %c = insertelement <64 x i1>%a, i1 %b, i32 5
349 %d = sext <64 x i1>%c to <64 x i8>
354 define <8 x i1> @test18(i8 %a, i16 %y) {
355 %b = bitcast i8 %a to <8 x i1>
356 %b1 = bitcast i16 %y to <16 x i1>
357 %el1 = extractelement <16 x i1>%b1, i32 8
358 %el2 = extractelement <16 x i1>%b1, i32 9
359 %c = insertelement <8 x i1>%b, i1 %el1, i32 7
360 %d = insertelement <8 x i1>%c, i1 %el2, i32 6
366 ; KNL: vextracti128 $1, %ymm2
371 ; SKX: vmovdqu16 {{.*}}%k1
373 define <32 x i16> @test21(<32 x i16> %x , <32 x i1> %mask) nounwind readnone {
374 %ret = select <32 x i1> %mask, <32 x i16> %x, <32 x i16> zeroinitializer
380 define void @test22(<4 x i1> %a, <4 x i1>* %addr) {
381 store <4 x i1> %a, <4 x i1>* %addr
387 define void @test23(<2 x i1> %a, <2 x i1>* %addr) {
388 store <2 x i1> %a, <2 x i1>* %addr