[SKX] Enable lowering of integer CMP operations.
[oota-llvm.git] / test / CodeGen / X86 / avx512-vec-cmp.ll
1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl | FileCheck %s
2
3 ; CHECK-LABEL: test1
4 ; CHECK: vcmpleps
5 ; CHECK: vmovaps
6 ; CHECK: ret
7 define <16 x float> @test1(<16 x float> %x, <16 x float> %y) nounwind {
8   %mask = fcmp ole <16 x float> %x, %y
9   %max = select <16 x i1> %mask, <16 x float> %x, <16 x float> %y
10   ret <16 x float> %max
11 }
12
13 ; CHECK-LABEL: test2
14 ; CHECK: vcmplepd
15 ; CHECK: vmovapd
16 ; CHECK: ret
17 define <8 x double> @test2(<8 x double> %x, <8 x double> %y) nounwind {
18   %mask = fcmp ole <8 x double> %x, %y
19   %max = select <8 x i1> %mask, <8 x double> %x, <8 x double> %y
20   ret <8 x double> %max
21 }
22
23 ; CHECK-LABEL: test3
24 ; CHECK: vpcmpeqd  (%rdi)
25 ; CHECK: vmovdqa32
26 ; CHECK: ret
27 define <16 x i32> @test3(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %yp) nounwind {
28   %y = load <16 x i32>* %yp, align 4
29   %mask = icmp eq <16 x i32> %x, %y
30   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
31   ret <16 x i32> %max
32 }
33
34 ; CHECK-LABEL: @test4_unsigned
35 ; CHECK: vpcmpnltud
36 ; CHECK: vmovdqa32
37 ; CHECK: ret
38 define <16 x i32> @test4_unsigned(<16 x i32> %x, <16 x i32> %y) nounwind {
39   %mask = icmp uge <16 x i32> %x, %y
40   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %y
41   ret <16 x i32> %max
42 }
43
44 ; CHECK-LABEL: test5
45 ; CHECK: vpcmpeqq {{.*}}%k1
46 ; CHECK: vmovdqa64 {{.*}}%k1
47 ; CHECK: ret
48 define <8 x i64> @test5(<8 x i64> %x, <8 x i64> %y) nounwind {
49   %mask = icmp eq <8 x i64> %x, %y
50   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %y
51   ret <8 x i64> %max
52 }
53
54 ; CHECK-LABEL: test6_unsigned
55 ; CHECK: vpcmpnleuq {{.*}}%k1
56 ; CHECK: vmovdqa64 {{.*}}%k1
57 ; CHECK: ret
58 define <8 x i64> @test6_unsigned(<8 x i64> %x, <8 x i64> %y) nounwind {
59   %mask = icmp ugt <8 x i64> %x, %y
60   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %y
61   ret <8 x i64> %max
62 }
63
64 ; CHECK-LABEL: test7
65 ; CHECK: xor
66 ; CHECK: vcmpltps
67 ; CHECK: vblendvps
68 ; CHECK: ret
69 define <4 x float> @test7(<4 x float> %a, <4 x float> %b) {
70   %mask = fcmp olt <4 x float> %a, zeroinitializer
71   %c = select <4 x i1>%mask, <4 x float>%a, <4 x float>%b
72   ret <4 x float>%c
73 }
74
75 ; CHECK-LABEL: test8
76 ; CHECK: xor
77 ; CHECK: vcmpltpd
78 ; CHECK: vblendvpd
79 ; CHECK: ret
80 define <2 x double> @test8(<2 x double> %a, <2 x double> %b) {
81   %mask = fcmp olt <2 x double> %a, zeroinitializer
82   %c = select <2 x i1>%mask, <2 x double>%a, <2 x double>%b
83   ret <2 x double>%c
84 }
85
86 ; CHECK-LABEL: test9
87 ; CHECK: vpcmpeqd
88 ; CHECK: vpblendmd
89 ; CHECK: ret
90 define <8 x i32> @test9(<8 x i32> %x, <8 x i32> %y) nounwind {
91   %mask = icmp eq <8 x i32> %x, %y
92   %max = select <8 x i1> %mask, <8 x i32> %x, <8 x i32> %y
93   ret <8 x i32> %max
94 }
95
96 ; CHECK-LABEL: test10
97 ; CHECK: vcmpeqps
98 ; CHECK: vblendmps
99 ; CHECK: ret
100 define <8 x float> @test10(<8 x float> %x, <8 x float> %y) nounwind {
101   %mask = fcmp oeq <8 x float> %x, %y
102   %max = select <8 x i1> %mask, <8 x float> %x, <8 x float> %y
103   ret <8 x float> %max
104 }
105
106 ; CHECK-LABEL: test11_unsigned
107 ; CHECK: vpmaxud
108 ; CHECK: ret
109 define <8 x i32> @test11_unsigned(<8 x i32> %x, <8 x i32> %y) nounwind {
110   %mask = icmp ugt <8 x i32> %x, %y
111   %max = select <8 x i1> %mask, <8 x i32> %x, <8 x i32> %y
112   ret <8 x i32> %max
113 }
114
115 ; CHECK-LABEL: test12
116 ; CHECK: vpcmpeqq        %zmm2, %zmm0, [[LO:%k[0-7]]]
117 ; CHECK: vpcmpeqq        %zmm3, %zmm1, [[HI:%k[0-7]]]
118 ; CHECK: kunpckbw        [[LO]], [[HI]], {{%k[0-7]}}
119
120 define i16 @test12(<16 x i64> %a, <16 x i64> %b) nounwind {
121   %res = icmp eq <16 x i64> %a, %b
122   %res1 = bitcast <16 x i1> %res to i16
123   ret i16 %res1
124 }
125
126 ; CHECK-LABEL: test13
127 ; CHECK: vcmpeqps        %zmm
128 ; CHECK: vpbroadcastd
129 ; CHECK: ret
130 define <16 x i32> @test13(<16 x float>%a, <16 x float>%b)
131 {
132   %cmpvector_i = fcmp oeq <16 x float> %a, %b
133   %conv = zext <16 x i1> %cmpvector_i to <16 x i32>
134   ret <16 x i32> %conv
135 }
136
137 ; CHECK-LABEL: test14
138 ; CHECK: vpcmp
139 ; CHECK-NOT: vpcmp
140 ; CHECK: vmovdqu32 {{.*}}{%k1} {z}
141 ; CHECK: ret
142 define <16 x i32> @test14(<16 x i32>%a, <16 x i32>%b) {
143   %sub_r = sub <16 x i32> %a, %b
144   %cmp.i2.i = icmp sgt <16 x i32> %sub_r, %a
145   %sext.i3.i = sext <16 x i1> %cmp.i2.i to <16 x i32>
146   %mask = icmp eq <16 x i32> %sext.i3.i, zeroinitializer
147   %res = select <16 x i1> %mask, <16 x i32> zeroinitializer, <16 x i32> %sub_r
148   ret <16 x i32>%res
149 }
150
151 ; CHECK-LABEL: test15
152 ; CHECK: vpcmpgtq
153 ; CHECK-NOT: vpcmp
154 ; CHECK: vmovdqu64 {{.*}}{%k1} {z}
155 ; CHECK: ret
156 define <8 x i64> @test15(<8 x i64>%a, <8 x i64>%b) {
157   %sub_r = sub <8 x i64> %a, %b
158   %cmp.i2.i = icmp sgt <8 x i64> %sub_r, %a
159   %sext.i3.i = sext <8 x i1> %cmp.i2.i to <8 x i64>
160   %mask = icmp eq <8 x i64> %sext.i3.i, zeroinitializer
161   %res = select <8 x i1> %mask, <8 x i64> zeroinitializer, <8 x i64> %sub_r
162   ret <8 x i64>%res
163 }
164
165 ; CHECK-LABEL: @test16
166 ; CHECK: vpcmpled
167 ; CHECK: vmovdqa32
168 ; CHECK: ret
169 define <16 x i32> @test16(<16 x i32> %x, <16 x i32> %y) nounwind {
170   %mask = icmp sge <16 x i32> %x, %y
171   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %y
172   ret <16 x i32> %max
173 }
174
175 ; CHECK-LABEL: @test17
176 ; CHECK: vpcmpgtd (%rdi)
177 ; CHECK: vmovdqa32
178 ; CHECK: ret
179 define <16 x i32> @test17(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %y.ptr) nounwind {
180   %y = load <16 x i32>* %y.ptr, align 4
181   %mask = icmp sgt <16 x i32> %x, %y
182   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
183   ret <16 x i32> %max
184 }
185
186 ; CHECK-LABEL: @test18
187 ; CHECK: vpcmpled (%rdi)
188 ; CHECK: vmovdqa32
189 ; CHECK: ret
190 define <16 x i32> @test18(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %y.ptr) nounwind {
191   %y = load <16 x i32>* %y.ptr, align 4
192   %mask = icmp sle <16 x i32> %x, %y
193   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
194   ret <16 x i32> %max
195 }
196
197 ; CHECK-LABEL: @test19
198 ; CHECK: vpcmpleud (%rdi)
199 ; CHECK: vmovdqa32
200 ; CHECK: ret
201 define <16 x i32> @test19(<16 x i32> %x, <16 x i32> %x1, <16 x i32>* %y.ptr) nounwind {
202   %y = load <16 x i32>* %y.ptr, align 4
203   %mask = icmp ule <16 x i32> %x, %y
204   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
205   ret <16 x i32> %max
206 }
207
208 ; CHECK-LABEL: @test20
209 ; CHECK: vpcmpeqd %zmm{{.*{%k[1-7]}}}
210 ; CHECK: vmovdqa32
211 ; CHECK: ret
212 define <16 x i32> @test20(<16 x i32> %x, <16 x i32> %y, <16 x i32> %x1, <16 x i32> %y1) nounwind {
213   %mask1 = icmp eq <16 x i32> %x1, %y1
214   %mask0 = icmp eq <16 x i32> %x, %y
215   %mask = select <16 x i1> %mask0, <16 x i1> %mask1, <16 x i1> zeroinitializer
216   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %y
217   ret <16 x i32> %max
218 }
219
220 ; CHECK-LABEL: @test21
221 ; CHECK: vpcmpleq %zmm{{.*{%k[1-7]}}}
222 ; CHECK: vmovdqa64
223 ; CHECK: ret
224 define <8 x i64> @test21(<8 x i64> %x, <8 x i64> %y, <8 x i64> %x1, <8 x i64> %y1) nounwind {
225   %mask1 = icmp sge <8 x i64> %x1, %y1
226   %mask0 = icmp sle <8 x i64> %x, %y
227   %mask = select <8 x i1> %mask0, <8 x i1> %mask1, <8 x i1> zeroinitializer
228   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
229   ret <8 x i64> %max
230 }
231
232 ; CHECK-LABEL: @test22
233 ; CHECK: vpcmpgtq (%rdi){{.*{%k[1-7]}}}
234 ; CHECK: vmovdqa64
235 ; CHECK: ret
236 define <8 x i64> @test22(<8 x i64> %x, <8 x i64>* %y.ptr, <8 x i64> %x1, <8 x i64> %y1) nounwind {
237   %mask1 = icmp sgt <8 x i64> %x1, %y1
238   %y = load <8 x i64>* %y.ptr, align 4
239   %mask0 = icmp sgt <8 x i64> %x, %y
240   %mask = select <8 x i1> %mask0, <8 x i1> %mask1, <8 x i1> zeroinitializer
241   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
242   ret <8 x i64> %max
243 }
244
245 ; CHECK-LABEL: @test23
246 ; CHECK: vpcmpleud (%rdi){{.*{%k[1-7]}}}
247 ; CHECK: vmovdqa32
248 ; CHECK: ret
249 define <16 x i32> @test23(<16 x i32> %x, <16 x i32>* %y.ptr, <16 x i32> %x1, <16 x i32> %y1) nounwind {
250   %mask1 = icmp sge <16 x i32> %x1, %y1
251   %y = load <16 x i32>* %y.ptr, align 4
252   %mask0 = icmp ule <16 x i32> %x, %y
253   %mask = select <16 x i1> %mask0, <16 x i1> %mask1, <16 x i1> zeroinitializer
254   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
255   ret <16 x i32> %max
256 }
257
258 ; CHECK-LABEL: test24
259 ; CHECK: vpcmpeqq (%rdi){1to8}
260 ; CHECK: vmovdqa64
261 ; CHECK: ret
262 define <8 x i64> @test24(<8 x i64> %x, <8 x i64> %x1, i64* %yb.ptr) nounwind {
263   %yb = load i64* %yb.ptr, align 4
264   %y.0 = insertelement <8 x i64> undef, i64 %yb, i32 0
265   %y = shufflevector <8 x i64> %y.0, <8 x i64> undef, <8 x i32> zeroinitializer
266   %mask = icmp eq <8 x i64> %x, %y
267   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
268   ret <8 x i64> %max
269 }
270
271 ; CHECK-LABEL: test25
272 ; CHECK: vpcmpled (%rdi){1to16}
273 ; CHECK: vmovdqa32
274 ; CHECK: ret
275 define <16 x i32> @test25(<16 x i32> %x, i32* %yb.ptr, <16 x i32> %x1) nounwind {
276   %yb = load i32* %yb.ptr, align 4
277   %y.0 = insertelement <16 x i32> undef, i32 %yb, i32 0
278   %y = shufflevector <16 x i32> %y.0, <16 x i32> undef, <16 x i32> zeroinitializer
279   %mask = icmp sle <16 x i32> %x, %y
280   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
281   ret <16 x i32> %max
282 }
283
284 ; CHECK-LABEL: test26
285 ; CHECK: vpcmpgtd (%rdi){1to16}{{.*{%k[1-7]}}}
286 ; CHECK: vmovdqa32
287 ; CHECK: ret
288 define <16 x i32> @test26(<16 x i32> %x, i32* %yb.ptr, <16 x i32> %x1, <16 x i32> %y1) nounwind {
289   %mask1 = icmp sge <16 x i32> %x1, %y1
290   %yb = load i32* %yb.ptr, align 4
291   %y.0 = insertelement <16 x i32> undef, i32 %yb, i32 0
292   %y = shufflevector <16 x i32> %y.0, <16 x i32> undef, <16 x i32> zeroinitializer
293   %mask0 = icmp sgt <16 x i32> %x, %y
294   %mask = select <16 x i1> %mask0, <16 x i1> %mask1, <16 x i1> zeroinitializer
295   %max = select <16 x i1> %mask, <16 x i32> %x, <16 x i32> %x1
296   ret <16 x i32> %max
297 }
298
299 ; CHECK-LABEL: test27
300 ; CHECK: vpcmpleq (%rdi){1to8}{{.*{%k[1-7]}}}
301 ; CHECK: vmovdqa64
302 ; CHECK: ret
303 define <8 x i64> @test27(<8 x i64> %x, i64* %yb.ptr, <8 x i64> %x1, <8 x i64> %y1) nounwind {
304   %mask1 = icmp sge <8 x i64> %x1, %y1
305   %yb = load i64* %yb.ptr, align 4
306   %y.0 = insertelement <8 x i64> undef, i64 %yb, i32 0
307   %y = shufflevector <8 x i64> %y.0, <8 x i64> undef, <8 x i32> zeroinitializer
308   %mask0 = icmp sle <8 x i64> %x, %y
309   %mask = select <8 x i1> %mask0, <8 x i1> %mask1, <8 x i1> zeroinitializer
310   %max = select <8 x i1> %mask, <8 x i64> %x, <8 x i64> %x1
311   ret <8 x i64> %max
312 }