1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefixes=SSE,SSE41
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.2 | FileCheck %s --check-prefixes=SSE,SSE42
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefixes=AVX
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=AVX
8 ; testz(~X,Y) -> testc(X,Y)
11 define i32 @ptestz_128_invert0(<2 x i64> %c, <2 x i64> %d, i32 %a, i32 %b) {
12 ; SSE-LABEL: ptestz_128_invert0:
14 ; SSE-NEXT: movl %edi, %eax
15 ; SSE-NEXT: ptest %xmm1, %xmm0
16 ; SSE-NEXT: cmovael %esi, %eax
19 ; AVX-LABEL: ptestz_128_invert0:
21 ; AVX-NEXT: movl %edi, %eax
22 ; AVX-NEXT: vptest %xmm1, %xmm0
23 ; AVX-NEXT: cmovael %esi, %eax
25 %t1 = xor <2 x i64> %c, <i64 -1, i64 -1>
26 %t2 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %t1, <2 x i64> %d)
27 %t3 = icmp ne i32 %t2, 0
28 %t4 = select i1 %t3, i32 %a, i32 %b
33 ; testz(X,~Y) -> testc(Y,X)
36 define i32 @ptestz_128_invert1(<2 x i64> %c, <2 x i64> %d, i32 %a, i32 %b) {
37 ; SSE-LABEL: ptestz_128_invert1:
39 ; SSE-NEXT: movl %edi, %eax
40 ; SSE-NEXT: ptest %xmm0, %xmm1
41 ; SSE-NEXT: cmovael %esi, %eax
44 ; AVX-LABEL: ptestz_128_invert1:
46 ; AVX-NEXT: movl %edi, %eax
47 ; AVX-NEXT: vptest %xmm0, %xmm1
48 ; AVX-NEXT: cmovael %esi, %eax
50 %t1 = xor <2 x i64> %d, <i64 -1, i64 -1>
51 %t2 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %c, <2 x i64> %t1)
52 %t3 = icmp ne i32 %t2, 0
53 %t4 = select i1 %t3, i32 %a, i32 %b
58 ; testc(~X,Y) -> testz(X,Y)
61 define i32 @ptestc_128_invert0(<2 x i64> %c, <2 x i64> %d, i32 %a, i32 %b) {
62 ; SSE-LABEL: ptestc_128_invert0:
64 ; SSE-NEXT: movl %edi, %eax
65 ; SSE-NEXT: ptest %xmm1, %xmm0
66 ; SSE-NEXT: cmovnel %esi, %eax
69 ; AVX-LABEL: ptestc_128_invert0:
71 ; AVX-NEXT: movl %edi, %eax
72 ; AVX-NEXT: vptest %xmm1, %xmm0
73 ; AVX-NEXT: cmovnel %esi, %eax
75 %t1 = xor <2 x i64> %c, <i64 -1, i64 -1>
76 %t2 = call i32 @llvm.x86.sse41.ptestc(<2 x i64> %t1, <2 x i64> %d)
77 %t3 = icmp ne i32 %t2, 0
78 %t4 = select i1 %t3, i32 %a, i32 %b
83 ; testnzc(~X,Y) -> testnzc(X,Y)
86 define i32 @ptestnzc_128_invert0(<2 x i64> %c, <2 x i64> %d, i32 %a, i32 %b) {
87 ; SSE-LABEL: ptestnzc_128_invert0:
89 ; SSE-NEXT: movl %edi, %eax
90 ; SSE-NEXT: ptest %xmm1, %xmm0
91 ; SSE-NEXT: cmovnel %esi, %eax
94 ; AVX-LABEL: ptestnzc_128_invert0:
96 ; AVX-NEXT: movl %edi, %eax
97 ; AVX-NEXT: vptest %xmm1, %xmm0
98 ; AVX-NEXT: cmovnel %esi, %eax
100 %t1 = xor <2 x i64> %c, <i64 -1, i64 -1>
101 %t2 = call i32 @llvm.x86.sse41.ptestc(<2 x i64> %t1, <2 x i64> %d)
102 %t3 = icmp ne i32 %t2, 0
103 %t4 = select i1 %t3, i32 %a, i32 %b
108 ; testc(X,~X) -> testc(X,-1)
111 define i32 @ptestc_128_not(<2 x i64> %c, <2 x i64> %d, i32 %a, i32 %b) {
112 ; SSE-LABEL: ptestc_128_not:
114 ; SSE-NEXT: movl %edi, %eax
115 ; SSE-NEXT: pcmpeqd %xmm1, %xmm1
116 ; SSE-NEXT: ptest %xmm1, %xmm0
117 ; SSE-NEXT: cmovael %esi, %eax
120 ; AVX-LABEL: ptestc_128_not:
122 ; AVX-NEXT: movl %edi, %eax
123 ; AVX-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
124 ; AVX-NEXT: vptest %xmm1, %xmm0
125 ; AVX-NEXT: cmovael %esi, %eax
127 %t1 = xor <2 x i64> %c, <i64 -1, i64 -1>
128 %t2 = call i32 @llvm.x86.sse41.ptestc(<2 x i64> %c, <2 x i64> %t1)
129 %t3 = icmp ne i32 %t2, 0
130 %t4 = select i1 %t3, i32 %a, i32 %b
135 ; testz(AND(X,Y),AND(X,Y)) -> testz(X,Y)
138 define i32 @ptestz_128_and(<2 x i64> %c, <2 x i64> %d, i32 %a, i32 %b) {
139 ; SSE-LABEL: ptestz_128_and:
141 ; SSE-NEXT: movl %edi, %eax
142 ; SSE-NEXT: ptest %xmm1, %xmm0
143 ; SSE-NEXT: cmovnel %esi, %eax
146 ; AVX-LABEL: ptestz_128_and:
148 ; AVX-NEXT: movl %edi, %eax
149 ; AVX-NEXT: vptest %xmm1, %xmm0
150 ; AVX-NEXT: cmovnel %esi, %eax
152 %t1 = and <2 x i64> %c, %d
153 %t2 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %t1, <2 x i64> %t1)
154 %t3 = icmp ne i32 %t2, 0
155 %t4 = select i1 %t3, i32 %a, i32 %b
160 ; testz(AND(~X,Y),AND(~X,Y)) -> testc(X,Y)
163 define i32 @ptestz_128_andc(<2 x i64> %c, <2 x i64> %d, i32 %a, i32 %b) {
164 ; SSE-LABEL: ptestz_128_andc:
166 ; SSE-NEXT: movl %edi, %eax
167 ; SSE-NEXT: ptest %xmm1, %xmm0
168 ; SSE-NEXT: cmovael %esi, %eax
171 ; AVX-LABEL: ptestz_128_andc:
173 ; AVX-NEXT: movl %edi, %eax
174 ; AVX-NEXT: vptest %xmm1, %xmm0
175 ; AVX-NEXT: cmovael %esi, %eax
177 %t1 = xor <2 x i64> %c, <i64 -1, i64 -1>
178 %t2 = and <2 x i64> %t1, %d
179 %t3 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %t2, <2 x i64> %t2)
180 %t4 = icmp ne i32 %t3, 0
181 %t5 = select i1 %t4, i32 %a, i32 %b
186 ; testz(-1,X) -> testz(X,X)
189 define i32 @ptestz_128_allones0(<2 x i64> %c, i32 %a, i32 %b) {
190 ; SSE-LABEL: ptestz_128_allones0:
192 ; SSE-NEXT: movl %edi, %eax
193 ; SSE-NEXT: ptest %xmm0, %xmm0
194 ; SSE-NEXT: cmovnel %esi, %eax
197 ; AVX-LABEL: ptestz_128_allones0:
199 ; AVX-NEXT: movl %edi, %eax
200 ; AVX-NEXT: vptest %xmm0, %xmm0
201 ; AVX-NEXT: cmovnel %esi, %eax
203 %t1 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> <i64 -1, i64 -1>, <2 x i64> %c)
204 %t2 = icmp ne i32 %t1, 0
205 %t3 = select i1 %t2, i32 %a, i32 %b
210 ; testz(X,-1) -> testz(X,X)
213 define i32 @ptestz_128_allones1(<2 x i64> %c, i32 %a, i32 %b) {
214 ; SSE-LABEL: ptestz_128_allones1:
216 ; SSE-NEXT: movl %edi, %eax
217 ; SSE-NEXT: ptest %xmm0, %xmm0
218 ; SSE-NEXT: cmovnel %esi, %eax
221 ; AVX-LABEL: ptestz_128_allones1:
223 ; AVX-NEXT: movl %edi, %eax
224 ; AVX-NEXT: vptest %xmm0, %xmm0
225 ; AVX-NEXT: cmovnel %esi, %eax
227 %t1 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %c, <2 x i64> <i64 -1, i64 -1>)
228 %t2 = icmp ne i32 %t1, 0
229 %t3 = select i1 %t2, i32 %a, i32 %b
233 define zeroext i1 @PR38522(ptr %x, ptr %y) {
234 ; SSE-LABEL: PR38522:
235 ; SSE: # %bb.0: # %start
236 ; SSE-NEXT: movdqa (%rdi), %xmm0
237 ; SSE-NEXT: pcmpgtb (%rsi), %xmm0
238 ; SSE-NEXT: ptest %xmm0, %xmm0
242 ; AVX-LABEL: PR38522:
243 ; AVX: # %bb.0: # %start
244 ; AVX-NEXT: vmovdqa (%rdi), %xmm0
245 ; AVX-NEXT: vpcmpgtb (%rsi), %xmm0, %xmm0
246 ; AVX-NEXT: vptest %xmm0, %xmm0
250 %0 = load <16 x i8>, ptr %x, align 16
251 %1 = load <16 x i8>, ptr %y, align 16
252 %2 = icmp sle <16 x i8> %0, %1
253 %3 = sext <16 x i1> %2 to <16 x i8>
254 %4 = bitcast <16 x i8> %3 to <2 x i64>
255 %5 = tail call i32 @llvm.x86.sse41.ptestc(<2 x i64> %4, <2 x i64> <i64 -1, i64 -1>)
256 %6 = icmp eq i32 %5, 1
261 ; testz(ashr(X,bw-1),-1) -> testpd/testps/movmskpd/movmskps/pmovmskb(X)
264 define i32 @ptestz_v2i64_signbits(<2 x i64> %c, i32 %a, i32 %b) {
265 ; SSE41-LABEL: ptestz_v2i64_signbits:
267 ; SSE41-NEXT: movl %edi, %eax
268 ; SSE41-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,1,3,3]
269 ; SSE41-NEXT: movmskps %xmm0, %ecx
270 ; SSE41-NEXT: testl %ecx, %ecx
271 ; SSE41-NEXT: cmovnel %esi, %eax
274 ; SSE42-LABEL: ptestz_v2i64_signbits:
276 ; SSE42-NEXT: movl %edi, %eax
277 ; SSE42-NEXT: movmskpd %xmm0, %ecx
278 ; SSE42-NEXT: testl %ecx, %ecx
279 ; SSE42-NEXT: cmovnel %esi, %eax
282 ; AVX-LABEL: ptestz_v2i64_signbits:
284 ; AVX-NEXT: movl %edi, %eax
285 ; AVX-NEXT: vtestpd %xmm0, %xmm0
286 ; AVX-NEXT: cmovnel %esi, %eax
288 %t1 = ashr <2 x i64> %c, <i64 63, i64 63>
289 %t2 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %t1, <2 x i64> <i64 -1, i64 -1>)
290 %t3 = icmp ne i32 %t2, 0
291 %t4 = select i1 %t3, i32 %a, i32 %b
295 define i32 @ptestz_v4i32_signbits(<4 x i32> %c, i32 %a, i32 %b) {
296 ; SSE-LABEL: ptestz_v4i32_signbits:
298 ; SSE-NEXT: movl %edi, %eax
299 ; SSE-NEXT: movmskps %xmm0, %ecx
300 ; SSE-NEXT: testl %ecx, %ecx
301 ; SSE-NEXT: cmovnel %esi, %eax
304 ; AVX-LABEL: ptestz_v4i32_signbits:
306 ; AVX-NEXT: movl %edi, %eax
307 ; AVX-NEXT: vtestps %xmm0, %xmm0
308 ; AVX-NEXT: cmovnel %esi, %eax
310 %t1 = ashr <4 x i32> %c, <i32 31, i32 31, i32 31, i32 31>
311 %t2 = bitcast <4 x i32> %t1 to <2 x i64>
312 %t3 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %t2, <2 x i64> <i64 -1, i64 -1>)
313 %t4 = icmp ne i32 %t3, 0
314 %t5 = select i1 %t4, i32 %a, i32 %b
318 define i32 @ptestz_v8i16_signbits(<8 x i16> %c, i32 %a, i32 %b) {
319 ; SSE-LABEL: ptestz_v8i16_signbits:
321 ; SSE-NEXT: movl %edi, %eax
322 ; SSE-NEXT: pmovmskb %xmm0, %ecx
323 ; SSE-NEXT: testl $43690, %ecx # imm = 0xAAAA
324 ; SSE-NEXT: cmovnel %esi, %eax
327 ; AVX-LABEL: ptestz_v8i16_signbits:
329 ; AVX-NEXT: movl %edi, %eax
330 ; AVX-NEXT: vpmovmskb %xmm0, %ecx
331 ; AVX-NEXT: testl $43690, %ecx # imm = 0xAAAA
332 ; AVX-NEXT: cmovnel %esi, %eax
334 %t1 = ashr <8 x i16> %c, <i16 15, i16 15, i16 15, i16 15, i16 15, i16 15, i16 15, i16 15>
335 %t2 = bitcast <8 x i16> %t1 to <2 x i64>
336 %t3 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %t2, <2 x i64> <i64 -1, i64 -1>)
337 %t4 = icmp ne i32 %t3, 0
338 %t5 = select i1 %t4, i32 %a, i32 %b
343 ; testz(or(extract_lo(X),extract_hi(X),or(extract_lo(Y),extract_hi(Y)) -> testz(X,Y)
346 define i32 @ptestz_v2i64_concat(<4 x i64> %c, <4 x i64> %d, i32 %a, i32 %b) {
347 ; SSE-LABEL: ptestz_v2i64_concat:
349 ; SSE-NEXT: movl %edi, %eax
350 ; SSE-NEXT: por %xmm1, %xmm0
351 ; SSE-NEXT: por %xmm3, %xmm2
352 ; SSE-NEXT: ptest %xmm2, %xmm0
353 ; SSE-NEXT: cmovnel %esi, %eax
356 ; AVX-LABEL: ptestz_v2i64_concat:
358 ; AVX-NEXT: movl %edi, %eax
359 ; AVX-NEXT: vptest %ymm1, %ymm0
360 ; AVX-NEXT: cmovnel %esi, %eax
361 ; AVX-NEXT: vzeroupper
363 %t1 = shufflevector <4 x i64> %c, <4 x i64> undef, <2 x i32> <i32 0, i32 1>
364 %t2 = shufflevector <4 x i64> %c, <4 x i64> undef, <2 x i32> <i32 2, i32 3>
365 %t3 = shufflevector <4 x i64> %d, <4 x i64> undef, <2 x i32> <i32 0, i32 1>
366 %t4 = shufflevector <4 x i64> %d, <4 x i64> undef, <2 x i32> <i32 2, i32 3>
367 %t5 = or <2 x i64> %t1, %t2
368 %t6 = or <2 x i64> %t4, %t3
369 %t7 = call i32 @llvm.x86.sse41.ptestz(<2 x i64> %t5, <2 x i64> %t6)
370 %t8 = icmp ne i32 %t7, 0
371 %t9 = select i1 %t8, i32 %a, i32 %b
375 ; FIXME: Foldable to ptest(xor(%0,%1),xor(%0,%1))
376 define i1 @PR38788(<4 x i32> %0, <4 x i32> %1) {
377 ; SSE-LABEL: PR38788:
379 ; SSE-NEXT: pcmpeqd %xmm1, %xmm0
380 ; SSE-NEXT: pcmpeqd %xmm1, %xmm1
381 ; SSE-NEXT: ptest %xmm1, %xmm0
385 ; AVX-LABEL: PR38788:
387 ; AVX-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
388 ; AVX-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
389 ; AVX-NEXT: vptest %xmm1, %xmm0
392 %3 = icmp eq <4 x i32> %0, %1
393 %4 = sext <4 x i1> %3 to <4 x i32>
394 %5 = bitcast <4 x i32> %4 to <2 x i64>
395 %6 = tail call i32 @llvm.x86.sse41.ptestc(<2 x i64> %5, <2 x i64> <i64 -1, i64 -1>)
396 %7 = icmp eq i32 %6, 1
400 declare i32 @llvm.x86.sse41.ptestz(<2 x i64>, <2 x i64>) nounwind readnone
401 declare i32 @llvm.x86.sse41.ptestc(<2 x i64>, <2 x i64>) nounwind readnone
402 declare i32 @llvm.x86.sse41.ptestnzc(<2 x i64>, <2 x i64>) nounwind readnone