AVX-512: Fixed a bug in extracting subvector from v64i1
[oota-llvm.git] / test / CodeGen / X86 / avx512-vec-cmp.ll
1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl | FileCheck %s --check-prefix=KNL
2 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=skx | FileCheck %s --check-prefix=SKX
3
4 define <16 x float> @test1(<16 x float> %x, <16 x float> %y) nounwind {
5 ; KNL-LABEL: test1:
6 ; KNL:       ## BB#0:
7 ; KNL-NEXT:    vcmpleps %zmm1, %zmm0, %k1
8 ; KNL-NEXT:    vmovaps %zmm0, %zmm1 {%k1}
9 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
10 ; KNL-NEXT:    retq
11   %mask = fcmp ole <16 x float> %x, %y
12   %max = select <16 x i1> %mask, <16 x float> %x, <16 x float> %y
13   ret <16 x float> %max
14 }
15
16 define <8 x double> @test2(<8 x double> %x, <8 x double> %y) nounwind {
17 ; KNL-LABEL: test2:
18 ; KNL:       ## BB#0:
19 ; KNL-NEXT:    vcmplepd %zmm1, %zmm0, %k1
20 ; KNL-NEXT:    vmovapd %zmm0, %zmm1 {%k1}
21 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
22 ; KNL-NEXT:    retq
23   %mask = fcmp ole <8 x double> %x, %y
24   %max = select <8 x i1> %mask, <8 x double> %x, <8 x double> %y
25   ret <8 x double> %max
26 }
27
28 define <16 x i32> @test3(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %yp) nounwind {
29 ; KNL-LABEL: test3:
30 ; KNL:       ## BB#0:
31 ; KNL-NEXT:    vpcmpeqd (%rdi), %zmm0, %k1
32 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
33 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
34 ; KNL-NEXT:    retq
35   %y = load <16 x i32>, <16 x i32>* %yp, align 4
36   %mask = icmp eq <16 x i32> %x, %y
37   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
38   ret <16 x i32> %max
39 }
40
41 define <16 x i32> @test4_unsigned(<16 x i32> %x, <16 x i32> %y, <16 x i32> %x1) nounwind {
42 ; KNL-LABEL: test4_unsigned:
43 ; KNL:       ## BB#0:
44 ; KNL-NEXT:    vpcmpnltud %zmm1, %zmm0, %k1
45 ; KNL-NEXT:    vmovdqa32 %zmm2, %zmm1 {%k1}
46 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
47 ; KNL-NEXT:    retq
48   %mask = icmp uge <16 x i32> %x, %y
49   %max = select <16 x i1> %mask, <16 x i32> %x1, <16 x i32> %y
50   ret <16 x i32> %max
51 }
52
53 define <8 x i64> @test5(<8 x i64> %x, <8 x i64> %y) nounwind {
54 ; KNL-LABEL: test5:
55 ; KNL:       ## BB#0:
56 ; KNL-NEXT:    vpcmpeqq %zmm1, %zmm0, %k1
57 ; KNL-NEXT:    vmovdqa64 %zmm0, %zmm1 {%k1}
58 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
59 ; KNL-NEXT:    retq
60   %mask = icmp eq <8 x i64> %x, %y
61   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %y
62   ret <8 x i64> %max
63 }
64
65 define <8 x i64> @test6_unsigned(<8 x i64> %x, <8 x i64> %y, <8 x i64> %x1) nounwind {
66 ; KNL-LABEL: test6_unsigned:
67 ; KNL:       ## BB#0:
68 ; KNL-NEXT:    vpcmpnleuq %zmm1, %zmm0, %k1
69 ; KNL-NEXT:    vmovdqa64 %zmm2, %zmm1 {%k1}
70 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
71 ; KNL-NEXT:    retq
72   %mask = icmp ugt <8 x i64> %x, %y
73   %max = select <8 x i1> %mask, <8 x i64> %x1, <8 x i64> %y
74   ret <8 x i64> %max
75 }
76
77 define <4 x float> @test7(<4 x float> %a, <4 x float> %b) {
78 ; KNL-LABEL: test7:
79 ; KNL:       ## BB#0:
80 ; KNL-NEXT:    vxorps %xmm2, %xmm2, %xmm2
81 ; KNL-NEXT:    vcmpltps %xmm2, %xmm0, %xmm2
82 ; KNL-NEXT:    vblendvps %xmm2, %xmm0, %xmm1, %xmm0
83 ; KNL-NEXT:    retq
84 ; SKX-LABEL: test7:
85 ; SKX:       ## BB#0:
86 ; SKX:    vxorps   %xmm2, %xmm2, %xmm2
87 ; SKX:    vcmpltps %xmm2, %xmm0, %k1 
88 ; SKX:    vmovaps  %xmm0, %xmm1 {%k1}
89 ; SKX:    vmovaps  %zmm1, %zmm0
90 ; SKX:    retq
91
92   %mask = fcmp olt <4 x float> %a, zeroinitializer
93   %c = select <4 x i1>%mask, <4 x float>%a, <4 x float>%b
94   ret <4 x float>%c
95 }
96
97 define <2 x double> @test8(<2 x double> %a, <2 x double> %b) {
98 ; KNL-LABEL: test8:
99 ; KNL:       ## BB#0:
100 ; KNL-NEXT:    vxorpd %xmm2, %xmm2, %xmm2
101 ; KNL-NEXT:    vcmpltpd %xmm2, %xmm0, %xmm2
102 ; KNL-NEXT:    vblendvpd %xmm2, %xmm0, %xmm1, %xmm0
103 ; KNL-NEXT:    retq
104 ; SKX-LABEL: test8:
105 ; SKX:       ## BB#0:
106 ; SKX: vxorpd  %xmm2, %xmm2, %xmm2
107 ; SKX: vcmpltpd    %xmm2, %xmm0, %k1 
108 ; SKX: vmovapd %xmm0, %xmm1 {%k1}
109 ; SKX: vmovaps %zmm1, %zmm0
110 ; SKX: retq
111   %mask = fcmp olt <2 x double> %a, zeroinitializer
112   %c = select <2 x i1>%mask, <2 x double>%a, <2 x double>%b
113   ret <2 x double>%c
114 }
115
116 define <8 x i32> @test9(<8 x i32> %x, <8 x i32> %y) nounwind {
117 ; KNL-LABEL: test9:
118 ; KNL:       ## BB#0:
119 ; KNL-NEXT:      ## kill: YMM1<def> YMM1<kill> ZMM1<def>
120 ; KNL-NEXT:      ## kill: YMM0<def> YMM0<kill> ZMM0<def>
121 ; KNL-NEXT:    vpcmpeqd %zmm1, %zmm0, %k1
122 ; KNL-NEXT:    vpblendmd %zmm0, %zmm1, %zmm0 {%k1}
123 ; KNL-NEXT:      ## kill: YMM0<def> YMM0<kill> ZMM0<kill>
124 ; KNL-NEXT:    retq
125   %mask = icmp eq <8 x i32> %x, %y
126   %max = select <8 x i1> %mask, <8 x i32> %x, <8 x i32> %y
127   ret <8 x i32> %max
128 }
129
130 define <8 x float> @test10(<8 x float> %x, <8 x float> %y) nounwind {
131 ; KNL-LABEL: test10:
132 ; KNL:       ## BB#0:
133 ; KNL-NEXT:      ## kill: YMM1<def> YMM1<kill> ZMM1<def>
134 ; KNL-NEXT:      ## kill: YMM0<def> YMM0<kill> ZMM0<def>
135 ; KNL-NEXT:    vcmpeqps %zmm1, %zmm0, %k1
136 ; KNL-NEXT:    vblendmps %zmm0, %zmm1, %zmm0 {%k1}
137 ; KNL-NEXT:      ## kill: YMM0<def> YMM0<kill> ZMM0<kill>
138 ; KNL-NEXT:    retq
139 ; SKX-LABEL: test10:
140 ; SKX:       ## BB#0:
141 ; SKX: vcmpeqps    %ymm1, %ymm0, %k1 
142 ; SKX: vmovaps %ymm0, %ymm1 {%k1}
143 ; SKX: vmovaps %zmm1, %zmm0
144 ; SKX: retq
145
146   %mask = fcmp oeq <8 x float> %x, %y
147   %max = select <8 x i1> %mask, <8 x float> %x, <8 x float> %y
148   ret <8 x float> %max
149 }
150
151 define <8 x i32> @test11_unsigned(<8 x i32> %x, <8 x i32> %y) nounwind {
152 ; KNL-LABEL: test11_unsigned:
153 ; KNL:       ## BB#0:
154 ; KNL-NEXT:    vpmaxud %ymm1, %ymm0, %ymm0
155 ; KNL-NEXT:    retq
156   %mask = icmp ugt <8 x i32> %x, %y
157   %max = select <8 x i1> %mask, <8 x i32> %x, <8 x i32> %y
158   ret <8 x i32> %max
159 }
160
161
162 define i16 @test12(<16 x i64> %a, <16 x i64> %b) nounwind {
163 ; KNL-LABEL: test12:
164 ; KNL:       ## BB#0:
165 ; KNL-NEXT:    vpcmpeqq %zmm2, %zmm0, %k0
166 ; KNL-NEXT:    vpcmpeqq %zmm3, %zmm1, %k1
167 ; KNL-NEXT:    kunpckbw %k0, %k1, %k0
168 ; KNL-NEXT:    kmovw %k0, %eax
169 ; KNL-NEXT:      ## kill: AX<def> AX<kill> EAX<kill>
170 ; KNL-NEXT:    retq
171   %res = icmp eq <16 x i64> %a, %b
172   %res1 = bitcast <16 x i1> %res to i16
173   ret i16 %res1
174 }
175
176 define <16 x i32> @test13(<16 x float>%a, <16 x float>%b)
177 ; KNL-LABEL: test13:
178 ; KNL:       ## BB#0:
179 ; KNL-NEXT:    vcmpeqps %zmm1, %zmm0, %k1
180 ; KNL-NEXT:    vpbroadcastd {{.*}}(%rip), %zmm0 {%k1} {z}
181 ; KNL-NEXT:    retq
182 {
183   %cmpvector_i = fcmp oeq <16 x float> %a, %b
184   %conv = zext <16 x i1> %cmpvector_i to <16 x i32>
185   ret <16 x i32> %conv
186 }
187
188 define <16 x i32> @test14(<16 x i32>%a, <16 x i32>%b) {
189 ; KNL-LABEL: test14:
190 ; KNL:       ## BB#0:
191 ; KNL-NEXT:    vpsubd %zmm1, %zmm0, %zmm1
192 ; KNL-NEXT:    vpcmpgtd %zmm0, %zmm1, %k0
193 ; KNL-NEXT:    knotw %k0, %k0
194 ; KNL-NEXT:    knotw %k0, %k1
195 ; KNL-NEXT:    vmovdqu32 %zmm1, %zmm0 {%k1} {z}
196 ; KNL-NEXT:    retq
197   %sub_r = sub <16 x i32> %a, %b
198   %cmp.i2.i = icmp sgt <16 x i32> %sub_r, %a
199   %sext.i3.i = sext <16 x i1> %cmp.i2.i to <16 x i32>
200   %mask = icmp eq <16 x i32> %sext.i3.i, zeroinitializer
201   %res = select <16 x i1> %mask, <16 x i32> zeroinitializer, <16 x i32> %sub_r
202   ret <16 x i32>%res
203 }
204
205 define <8 x i64> @test15(<8 x i64>%a, <8 x i64>%b) {
206 ; KNL-LABEL: test15:
207 ; KNL:       ## BB#0:
208 ; KNL-NEXT:    vpsubq %zmm1, %zmm0, %zmm1
209 ; KNL-NEXT:    vpcmpgtq %zmm0, %zmm1, %k0
210 ; KNL-NEXT:    knotw %k0, %k0
211 ; KNL-NEXT:    knotw %k0, %k1
212 ; KNL-NEXT:    vmovdqu64 %zmm1, %zmm0 {%k1} {z}
213 ; KNL-NEXT:    retq
214   %sub_r = sub <8 x i64> %a, %b
215   %cmp.i2.i = icmp sgt <8 x i64> %sub_r, %a
216   %sext.i3.i = sext <8 x i1> %cmp.i2.i to <8 x i64>
217   %mask = icmp eq <8 x i64> %sext.i3.i, zeroinitializer
218   %res = select <8 x i1> %mask, <8 x i64> zeroinitializer, <8 x i64> %sub_r
219   ret <8 x i64>%res
220 }
221
222 define <16 x i32> @test16(<16 x i32> %x, <16 x i32> %y, <16 x i32> %x1) nounwind {
223 ; KNL-LABEL: test16:
224 ; KNL:       ## BB#0:
225 ; KNL-NEXT:    vpcmpled %zmm0, %zmm1, %k1
226 ; KNL-NEXT:    vmovdqa32 %zmm2, %zmm1 {%k1}
227 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
228 ; KNL-NEXT:    retq
229   %mask = icmp sge <16 x i32> %x, %y
230   %max = select <16 x i1> %mask, <16 x i32> %x1, <16 x i32> %y
231   ret <16 x i32> %max
232 }
233
234 define <16 x i32> @test17(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %y.ptr) nounwind {
235 ; KNL-LABEL: test17:
236 ; KNL:       ## BB#0:
237 ; KNL-NEXT:    vpcmpgtd (%rdi), %zmm0, %k1
238 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
239 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
240 ; KNL-NEXT:    retq
241   %y = load <16 x i32>, <16 x i32>* %y.ptr, align 4
242   %mask = icmp sgt <16 x i32> %x, %y
243   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
244   ret <16 x i32> %max
245 }
246
247 define <16 x i32> @test18(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %y.ptr) nounwind {
248 ; KNL-LABEL: test18:
249 ; KNL:       ## BB#0:
250 ; KNL-NEXT:    vpcmpled (%rdi), %zmm0, %k1
251 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
252 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
253 ; KNL-NEXT:    retq
254   %y = load <16 x i32>, <16 x i32>* %y.ptr, align 4
255   %mask = icmp sle <16 x i32> %x, %y
256   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
257   ret <16 x i32> %max
258 }
259
260 define <16 x i32> @test19(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %y.ptr) nounwind {
261 ; KNL-LABEL: test19:
262 ; KNL:       ## BB#0:
263 ; KNL-NEXT:    vpcmpleud (%rdi), %zmm0, %k1
264 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
265 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
266 ; KNL-NEXT:    retq
267   %y = load <16 x i32>, <16 x i32>* %y.ptr, align 4
268   %mask = icmp ule <16 x i32> %x, %y
269   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
270   ret <16 x i32> %max
271 }
272
273 define <16 x i32> @test20(<16 x i32> %x, <16 x i32> %y, <16 x i32> %x1, <16 x i32> %y1) nounwind {
274 ; KNL-LABEL: test20:
275 ; KNL:       ## BB#0:
276 ; KNL-NEXT:    vpcmpeqd %zmm1, %zmm0, %k1
277 ; KNL-NEXT:    vpcmpeqd %zmm3, %zmm2, %k1 {%k1}
278 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
279 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
280 ; KNL-NEXT:    retq
281   %mask1 = icmp eq <16 x i32> %x1, %y1
282   %mask0 = icmp eq <16 x i32> %x, %y
283   %mask = select <16 x i1> %mask0, <16 x i1> %mask1, <16 x i1> zeroinitializer
284   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %y
285   ret <16 x i32> %max
286 }
287
288 define <8 x i64> @test21(<8 x i64> %x, <8 x i64> %y, <8 x i64> %x1, <8 x i64> %y1) nounwind {
289 ; KNL-LABEL: test21:
290 ; KNL:       ## BB#0:
291 ; KNL-NEXT:    vpcmpleq %zmm1, %zmm0, %k1
292 ; KNL-NEXT:    vpcmpleq %zmm2, %zmm3, %k1 {%k1}
293 ; KNL-NEXT:    vmovdqa64 %zmm0, %zmm2 {%k1}
294 ; KNL-NEXT:    vmovaps %zmm2, %zmm0
295 ; KNL-NEXT:    retq
296   %mask1 = icmp sge <8 x i64> %x1, %y1
297   %mask0 = icmp sle <8 x i64> %x, %y
298   %mask = select <8 x i1> %mask0, <8 x i1> %mask1, <8 x i1> zeroinitializer
299   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
300   ret <8 x i64> %max
301 }
302
303 define <8 x i64> @test22(<8 x i64> %x, <8 x i64>* %y.ptr, <8 x i64> %x1, <8 x i64> %y1) nounwind {
304 ; KNL-LABEL: test22:
305 ; KNL:       ## BB#0:
306 ; KNL-NEXT:    vpcmpgtq %zmm2, %zmm1, %k1
307 ; KNL-NEXT:    vpcmpgtq (%rdi), %zmm0, %k1 {%k1}
308 ; KNL-NEXT:    vmovdqa64 %zmm0, %zmm1 {%k1}
309 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
310 ; KNL-NEXT:    retq
311   %mask1 = icmp sgt <8 x i64> %x1, %y1
312   %y = load <8 x i64>, <8 x i64>* %y.ptr, align 4
313   %mask0 = icmp sgt <8 x i64> %x, %y
314   %mask = select <8 x i1> %mask0, <8 x i1> %mask1, <8 x i1> zeroinitializer
315   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
316   ret <8 x i64> %max
317 }
318
319 define <16 x i32> @test23(<16 x i32> %x, <16 x i32>* %y.ptr, <16 x i32> %x1, <16 x i32> %y1) nounwind {
320 ; KNL-LABEL: test23:
321 ; KNL:       ## BB#0:
322 ; KNL-NEXT:    vpcmpled %zmm1, %zmm2, %k1
323 ; KNL-NEXT:    vpcmpleud (%rdi), %zmm0, %k1 {%k1}
324 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
325 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
326 ; KNL-NEXT:    retq
327   %mask1 = icmp sge <16 x i32> %x1, %y1
328   %y = load <16 x i32>, <16 x i32>* %y.ptr, align 4
329   %mask0 = icmp ule <16 x i32> %x, %y
330   %mask = select <16 x i1> %mask0, <16 x i1> %mask1, <16 x i1> zeroinitializer
331   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
332   ret <16 x i32> %max
333 }
334
335 define <8 x i64> @test24(<8 x i64> %x, <8 x i64> %x1, i64* %yb.ptr) nounwind {
336 ; KNL-LABEL: test24:
337 ; KNL:       ## BB#0:
338 ; KNL-NEXT:    vpcmpeqq (%rdi){1to8}, %zmm0, %k1
339 ; KNL-NEXT:    vmovdqa64 %zmm0, %zmm1 {%k1}
340 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
341 ; KNL-NEXT:    retq
342   %yb = load i64, i64* %yb.ptr, align 4
343   %y.0 = insertelement <8 x i64> undef, i64 %yb, i32 0
344   %y = shufflevector <8 x i64> %y.0, <8 x i64> undef, <8 x i32> zeroinitializer
345   %mask = icmp eq <8 x i64> %x, %y
346   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
347   ret <8 x i64> %max
348 }
349
350 define <16 x i32> @test25(<16 x i32> %x, i32* %yb.ptr, <16 x i32> %x1) nounwind {
351 ; KNL-LABEL: test25:
352 ; KNL:       ## BB#0:
353 ; KNL-NEXT:    vpcmpled (%rdi){1to16}, %zmm0, %k1
354 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
355 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
356 ; KNL-NEXT:    retq
357   %yb = load i32, i32* %yb.ptr, align 4
358   %y.0 = insertelement <16 x i32> undef, i32 %yb, i32 0
359   %y = shufflevector <16 x i32> %y.0, <16 x i32> undef, <16 x i32> zeroinitializer
360   %mask = icmp sle <16 x i32> %x, %y
361   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
362   ret <16 x i32> %max
363 }
364
365 define <16 x i32> @test26(<16 x i32> %x, i32* %yb.ptr, <16 x i32> %x1, <16 x i32> %y1) nounwind {
366 ; KNL-LABEL: test26:
367 ; KNL:       ## BB#0:
368 ; KNL-NEXT:    vpcmpled %zmm1, %zmm2, %k1
369 ; KNL-NEXT:    vpcmpgtd (%rdi){1to16}, %zmm0, %k1 {%k1}
370 ; KNL-NEXT:    vmovdqa32 %zmm0, %zmm1 {%k1}
371 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
372 ; KNL-NEXT:    retq
373   %mask1 = icmp sge <16 x i32> %x1, %y1
374   %yb = load i32, i32* %yb.ptr, align 4
375   %y.0 = insertelement <16 x i32> undef, i32 %yb, i32 0
376   %y = shufflevector <16 x i32> %y.0, <16 x i32> undef, <16 x i32> zeroinitializer
377   %mask0 = icmp sgt <16 x i32> %x, %y
378   %mask = select <16 x i1> %mask0, <16 x i1> %mask1, <16 x i1> zeroinitializer
379   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
380   ret <16 x i32> %max
381 }
382
383 define <8 x i64> @test27(<8 x i64> %x, i64* %yb.ptr, <8 x i64> %x1, <8 x i64> %y1) nounwind {
384 ; KNL-LABEL: test27:
385 ; KNL:       ## BB#0:
386 ; KNL-NEXT:    vpcmpleq        %zmm1, %zmm2, %k1
387 ; KNL-NEXT:    vpcmpleq        (%rdi){1to8}, %zmm0, %k1 {%k1}
388 ; KNL-NEXT:    vmovdqa64 %zmm0, %zmm1 {%k1}
389 ; KNL-NEXT:    vmovaps %zmm1, %zmm0
390 ; KNL-NEXT:    retq
391   %mask1 = icmp sge <8 x i64> %x1, %y1
392   %yb = load i64, i64* %yb.ptr, align 4
393   %y.0 = insertelement <8 x i64> undef, i64 %yb, i32 0
394   %y = shufflevector <8 x i64> %y.0, <8 x i64> undef, <8 x i32> zeroinitializer
395   %mask0 = icmp sle <8 x i64> %x, %y
396   %mask = select <8 x i1> %mask0, <8 x i1> %mask1, <8 x i1> zeroinitializer
397   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
398   ret <8 x i64> %max
399 }
400
401 ; KNL-LABEL: test28
402 ; KNL: vpcmpgtq
403 ; KNL: vpcmpgtq
404 ; KNL: kxorw
405 define <8 x i32>@test28(<8 x i64> %x, <8 x i64> %y, <8 x i64> %x1, <8 x i64> %y1) {
406   %x_gt_y = icmp sgt <8 x i64> %x, %y
407   %x1_gt_y1 = icmp sgt <8 x i64> %x1, %y1
408   %res = icmp eq <8 x i1>%x_gt_y, %x1_gt_y1
409   %resse = sext <8 x i1>%res to <8 x i32>
410   ret <8 x i32> %resse
411 }
412
413 ; KNL-LABEL: test29
414 ; KNL: vpcmpgtd
415 ; KNL: vpcmpgtd
416 ; KNL: kxnorw
417 define <16 x i8>@test29(<16 x i32> %x, <16 x i32> %y, <16 x i32> %x1, <16 x i32> %y1) {
418   %x_gt_y = icmp sgt <16 x i32> %x, %y
419   %x1_gt_y1 = icmp sgt <16 x i32> %x1, %y1
420   %res = icmp ne <16 x i1>%x_gt_y, %x1_gt_y1
421   %resse = sext <16 x i1>%res to <16 x i8>
422   ret <16 x i8> %resse
423 }
424
425 define <4 x double> @test30(<4 x double> %x, <4 x double> %y) nounwind {
426 ; SKX-LABEL: test30:
427 ; SKX: vcmpeqpd   %ymm1, %ymm0, %k1 
428 ; SKX: vmovapd    %ymm0, %ymm1 {%k1}
429
430   %mask = fcmp oeq <4 x double> %x, %y
431   %max = select <4 x i1> %mask, <4 x double> %x, <4 x double> %y
432   ret <4 x double> %max
433 }
434
435 define <2 x double> @test31(<2 x double> %x, <2 x double> %x1, <2 x double>* %yp) nounwind {
436 ; SKX-LABEL: test31:     
437 ; SKX: vcmpltpd        (%rdi), %xmm0, %k1 
438 ; SKX: vmovapd %xmm0, %xmm1 {%k1}
439
440   %y = load <2 x double>, <2 x double>* %yp, align 4
441   %mask = fcmp olt <2 x double> %x, %y
442   %max = select <2 x i1> %mask, <2 x double> %x, <2 x double> %x1
443   ret <2 x double> %max
444 }
445
446 define <4 x double> @test32(<4 x double> %x, <4 x double> %x1, <4 x double>* %yp) nounwind {
447 ; SKX-LABEL: test32:
448 ; SKX: vcmpltpd        (%rdi), %ymm0, %k1 
449 ; SKX: vmovapd %ymm0, %ymm1 {%k1}
450
451   %y = load <4 x double>, <4 x double>* %yp, align 4
452   %mask = fcmp ogt <4 x double> %y, %x
453   %max = select <4 x i1> %mask, <4 x double> %x, <4 x double> %x1
454   ret <4 x double> %max
455 }
456
457 define <8 x double> @test33(<8 x double> %x, <8 x double> %x1, <8 x double>* %yp) nounwind {
458 ; SKX-LABEL: test33:     
459 ; SKX: vcmpltpd        (%rdi), %zmm0, %k1 
460 ; SKX: vmovapd %zmm0, %zmm1 {%k1}
461   %y = load <8 x double>, <8 x double>* %yp, align 4
462   %mask = fcmp olt <8 x double> %x, %y
463   %max = select <8 x i1> %mask, <8 x double> %x, <8 x double> %x1
464   ret <8 x double> %max
465 }
466
467 define <4 x float> @test34(<4 x float> %x, <4 x float> %x1, <4 x float>* %yp) nounwind {
468 ; SKX-LABEL: test34:     
469 ; SKX: vcmpltps        (%rdi), %xmm0, %k1 
470 ; SKX: vmovaps %xmm0, %xmm1 {%k1}
471   %y = load <4 x float>, <4 x float>* %yp, align 4
472   %mask = fcmp olt <4 x float> %x, %y
473   %max = select <4 x i1> %mask, <4 x float> %x, <4 x float> %x1
474   ret <4 x float> %max
475 }
476
477 define <8 x float> @test35(<8 x float> %x, <8 x float> %x1, <8 x float>* %yp) nounwind {
478 ; SKX-LABEL: test35:
479 ; SKX: vcmpltps        (%rdi), %ymm0, %k1 
480 ; SKX: vmovaps %ymm0, %ymm1 {%k1}
481
482   %y = load <8 x float>, <8 x float>* %yp, align 4
483   %mask = fcmp ogt <8 x float> %y, %x
484   %max = select <8 x i1> %mask, <8 x float> %x, <8 x float> %x1
485   ret <8 x float> %max
486 }
487
488 define <16 x float> @test36(<16 x float> %x, <16 x float> %x1, <16 x float>* %yp) nounwind {
489 ; SKX-LABEL: test36:     
490 ; SKX: vcmpltps        (%rdi), %zmm0, %k1 
491 ; SKX: vmovaps %zmm0, %zmm1 {%k1}
492   %y = load <16 x float>, <16 x float>* %yp, align 4
493   %mask = fcmp olt <16 x float> %x, %y
494   %max = select <16 x i1> %mask, <16 x float> %x, <16 x float> %x1
495   ret <16 x float> %max
496 }
497
498 define <8 x double> @test37(<8 x double> %x, <8 x double> %x1, double* %ptr) nounwind {
499 ; SKX-LABEL: test37:                                
500 ; SKX: vcmpltpd  (%rdi){1to8}, %zmm0, %k1 
501 ; SKX: vmovapd %zmm0, %zmm1 {%k1}
502
503   %a = load double, double* %ptr
504   %v = insertelement <8 x double> undef, double %a, i32 0
505   %shuffle = shufflevector <8 x double> %v, <8 x double> undef, <8 x i32> zeroinitializer
506
507   %mask = fcmp ogt <8 x double> %shuffle, %x
508   %max = select <8 x i1> %mask, <8 x double> %x, <8 x double> %x1
509   ret <8 x double> %max
510 }
511
512 define <4 x double> @test38(<4 x double> %x, <4 x double> %x1, double* %ptr) nounwind {
513 ; SKX-LABEL: test38:                                
514 ; SKX: vcmpltpd  (%rdi){1to4}, %ymm0, %k1 
515 ; SKX: vmovapd %ymm0, %ymm1 {%k1}
516
517   %a = load double, double* %ptr
518   %v = insertelement <4 x double> undef, double %a, i32 0
519   %shuffle = shufflevector <4 x double> %v, <4 x double> undef, <4 x i32> zeroinitializer
520   
521   %mask = fcmp ogt <4 x double> %shuffle, %x
522   %max = select <4 x i1> %mask, <4 x double> %x, <4 x double> %x1
523   ret <4 x double> %max
524 }
525
526 define <2 x double> @test39(<2 x double> %x, <2 x double> %x1, double* %ptr) nounwind {
527 ; SKX-LABEL: test39:                                
528 ; SKX: vcmpltpd  (%rdi){1to2}, %xmm0, %k1 
529 ; SKX: vmovapd %xmm0, %xmm1 {%k1}
530
531   %a = load double, double* %ptr
532   %v = insertelement <2 x double> undef, double %a, i32 0
533   %shuffle = shufflevector <2 x double> %v, <2 x double> undef, <2 x i32> <i32 0, i32 0>
534   
535   %mask = fcmp ogt <2 x double> %shuffle, %x
536   %max = select <2 x i1> %mask, <2 x double> %x, <2 x double> %x1
537   ret <2 x double> %max
538 }
539
540
541 define <16  x float> @test40(<16  x float> %x, <16  x float> %x1, float* %ptr) nounwind {
542 ; SKX-LABEL: test40:                                
543 ; SKX: vcmpltps  (%rdi){1to16}, %zmm0, %k1 
544 ; SKX: vmovaps %zmm0, %zmm1 {%k1}
545
546   %a = load float, float* %ptr
547   %v = insertelement <16  x float> undef, float %a, i32 0
548   %shuffle = shufflevector <16  x float> %v, <16  x float> undef, <16 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
549   
550   %mask = fcmp ogt <16  x float> %shuffle, %x
551   %max = select <16 x i1> %mask, <16  x float> %x, <16  x float> %x1
552   ret <16  x float> %max
553 }
554
555 define <8  x float> @test41(<8  x float> %x, <8  x float> %x1, float* %ptr) nounwind {
556 ; SKX-LABEL: test41:                                
557 ; SKX: vcmpltps  (%rdi){1to8}, %ymm0, %k1 
558 ; SKX: vmovaps %ymm0, %ymm1 {%k1}
559
560   %a = load float, float* %ptr
561   %v = insertelement <8  x float> undef, float %a, i32 0
562   %shuffle = shufflevector <8  x float> %v, <8  x float> undef, <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
563   
564   %mask = fcmp ogt <8  x float> %shuffle, %x
565   %max = select <8 x i1> %mask, <8  x float> %x, <8  x float> %x1
566   ret <8  x float> %max
567 }
568
569 define <4  x float> @test42(<4  x float> %x, <4  x float> %x1, float* %ptr) nounwind {
570 ; SKX-LABEL: test42:                                
571 ; SKX: vcmpltps  (%rdi){1to4}, %xmm0, %k1 
572 ; SKX: vmovaps %xmm0, %xmm1 {%k1}
573   
574   %a = load float, float* %ptr
575   %v = insertelement <4  x float> undef, float %a, i32 0
576   %shuffle = shufflevector <4  x float> %v, <4  x float> undef, <4 x i32> <i32 0, i32 0, i32 0, i32 0>
577   
578   %mask = fcmp ogt <4  x float> %shuffle, %x
579   %max = select <4 x i1> %mask, <4  x float> %x, <4  x float> %x1
580   ret <4  x float> %max
581 }
582
583 define <8 x double> @test43(<8 x double> %x, <8 x double> %x1, double* %ptr,<8 x i1> %mask_in) nounwind {
584 ; SKX-LABEL: test43:                                
585 ; SKX: vpmovw2m  %xmm2, %k1
586 ; SKX: vcmpltpd  (%rdi){1to8}, %zmm0, %k1 {%k1}
587 ; SKX: vmovapd %zmm0, %zmm1 {%k1}
588
589   %a = load double, double* %ptr
590   %v = insertelement <8 x double> undef, double %a, i32 0
591   %shuffle = shufflevector <8 x double> %v, <8 x double> undef, <8 x i32> zeroinitializer
592   
593   %mask_cmp = fcmp ogt <8 x double> %shuffle, %x
594   %mask = and <8 x i1> %mask_cmp, %mask_in
595   %max = select <8 x i1> %mask, <8 x double> %x, <8 x double> %x1
596   ret <8 x double> %max
597 }