1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefixes=SSE,SSE2
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefixes=SSE,SSE41
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefixes=AVX,AVX1
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=AVX,AVX2
7 ; PR66101 - Fold select (sext m), (add X, C), X --> (add X, (and C, (sext m))))
8 define <4 x i32> @masked_select_const(<4 x i32> %a, <4 x i32> %x, <4 x i32> %y) {
9 ; SSE-LABEL: masked_select_const:
11 ; SSE-NEXT: pcmpgtd %xmm2, %xmm1
12 ; SSE-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1
13 ; SSE-NEXT: paddd %xmm1, %xmm0
16 ; AVX1-LABEL: masked_select_const:
18 ; AVX1-NEXT: vpcmpgtd %xmm2, %xmm1, %xmm1
19 ; AVX1-NEXT: vpand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1, %xmm1
20 ; AVX1-NEXT: vpaddd %xmm1, %xmm0, %xmm0
23 ; AVX2-LABEL: masked_select_const:
25 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm3 = [4294967272,4294967272,4294967272,4294967272]
26 ; AVX2-NEXT: vpcmpgtd %xmm2, %xmm1, %xmm1
27 ; AVX2-NEXT: vpand %xmm3, %xmm1, %xmm1
28 ; AVX2-NEXT: vpaddd %xmm1, %xmm0, %xmm0
30 %sub.i = add <4 x i32> %a, <i32 -24, i32 -24, i32 -24, i32 -24>
31 %cmp.i = icmp sgt <4 x i32> %x, %y
32 %sel = select <4 x i1> %cmp.i, <4 x i32> %sub.i, <4 x i32> %a
36 ; Verify that we don't emit packed vector shifts instructions if the
37 ; condition used by the vector select is a vector of constants.
39 define <4 x float> @test1(<4 x float> %a, <4 x float> %b) {
42 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,2],xmm1[1,3]
43 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,2,1,3]
48 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2],xmm1[3]
53 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2],xmm1[3]
55 %1 = select <4 x i1> <i1 true, i1 false, i1 true, i1 false>, <4 x float> %a, <4 x float> %b
59 define <4 x float> @test2(<4 x float> %a, <4 x float> %b) {
62 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
67 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
72 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
74 %1 = select <4 x i1> <i1 true, i1 true, i1 false, i1 false>, <4 x float> %a, <4 x float> %b
78 define <4 x float> @test3(<4 x float> %a, <4 x float> %b) {
81 ; SSE2-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1]
86 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
91 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
93 %1 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %a, <4 x float> %b
97 define <4 x float> @test4(<4 x float> %a, <4 x float> %b) {
100 ; SSE-NEXT: movaps %xmm1, %xmm0
105 ; AVX-NEXT: vmovaps %xmm1, %xmm0
107 %1 = select <4 x i1> <i1 false, i1 false, i1 false, i1 false>, <4 x float> %a, <4 x float> %b
111 define <4 x float> @test5(<4 x float> %a, <4 x float> %b) {
119 %1 = select <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x float> %a, <4 x float> %b
123 define <8 x i16> @test6(<8 x i16> %a, <8 x i16> %b) {
131 %1 = select <8 x i1> <i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false>, <8 x i16> %a, <8 x i16> %a
135 define <8 x i16> @test7(<8 x i16> %a, <8 x i16> %b) {
138 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
141 ; SSE41-LABEL: test7:
143 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
148 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
150 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false>, <8 x i16> %a, <8 x i16> %b
154 define <8 x i16> @test8(<8 x i16> %a, <8 x i16> %b) {
157 ; SSE2-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1]
160 ; SSE41-LABEL: test8:
162 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
167 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
169 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>, <8 x i16> %a, <8 x i16> %b
173 define <8 x i16> @test9(<8 x i16> %a, <8 x i16> %b) {
176 ; SSE-NEXT: movaps %xmm1, %xmm0
181 ; AVX-NEXT: vmovaps %xmm1, %xmm0
183 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <8 x i16> %a, <8 x i16> %b
187 define <8 x i16> @test10(<8 x i16> %a, <8 x i16> %b) {
195 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i16> %a, <8 x i16> %b
199 define <8 x i16> @test11(<8 x i16> %a, <8 x i16> %b) {
200 ; SSE2-LABEL: test11:
202 ; SSE2-NEXT: movaps {{.*#+}} xmm2 = [0,65535,65535,0,0,65535,65535,0]
203 ; SSE2-NEXT: andps %xmm2, %xmm0
204 ; SSE2-NEXT: andnps %xmm1, %xmm2
205 ; SSE2-NEXT: orps %xmm2, %xmm0
208 ; SSE41-LABEL: test11:
210 ; SSE41-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0],xmm0[1,2],xmm1[3,4],xmm0[5,6],xmm1[7]
215 ; AVX-NEXT: vpblendw {{.*#+}} xmm0 = xmm1[0],xmm0[1,2],xmm1[3,4],xmm0[5,6],xmm1[7]
217 %1 = select <8 x i1> <i1 false, i1 true, i1 true, i1 false, i1 undef, i1 true, i1 true, i1 undef>, <8 x i16> %a, <8 x i16> %b
221 define <8 x i16> @test12(<8 x i16> %a, <8 x i16> %b) {
224 ; SSE-NEXT: movaps %xmm1, %xmm0
229 ; AVX-NEXT: vmovaps %xmm1, %xmm0
231 %1 = select <8 x i1> <i1 false, i1 false, i1 undef, i1 false, i1 false, i1 false, i1 false, i1 undef>, <8 x i16> %a, <8 x i16> %b
235 define <8 x i16> @test13(<8 x i16> %a, <8 x i16> %b) {
238 ; SSE-NEXT: movaps %xmm1, %xmm0
243 ; AVX-NEXT: vmovaps %xmm1, %xmm0
245 %1 = select <8 x i1> <i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef>, <8 x i16> %a, <8 x i16> %b
249 ; Fold (vselect (build_vector AllOnes), N1, N2) -> N1
250 define <4 x float> @test14(<4 x float> %a, <4 x float> %b) {
258 %1 = select <4 x i1> <i1 true, i1 undef, i1 true, i1 undef>, <4 x float> %a, <4 x float> %b
262 define <8 x i16> @test15(<8 x i16> %a, <8 x i16> %b) {
270 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 undef, i1 undef, i1 true, i1 true, i1 undef>, <8 x i16> %a, <8 x i16> %b
274 ; Fold (vselect (build_vector AllZeros), N1, N2) -> N2
275 define <4 x float> @test16(<4 x float> %a, <4 x float> %b) {
278 ; SSE-NEXT: movaps %xmm1, %xmm0
283 ; AVX-NEXT: vmovaps %xmm1, %xmm0
285 %1 = select <4 x i1> <i1 false, i1 undef, i1 false, i1 undef>, <4 x float> %a, <4 x float> %b
289 define <8 x i16> @test17(<8 x i16> %a, <8 x i16> %b) {
292 ; SSE-NEXT: movaps %xmm1, %xmm0
297 ; AVX-NEXT: vmovaps %xmm1, %xmm0
299 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 undef, i1 undef, i1 false, i1 false, i1 undef>, <8 x i16> %a, <8 x i16> %b
303 define <4 x float> @test18(<4 x float> %a, <4 x float> %b) {
304 ; SSE2-LABEL: test18:
306 ; SSE2-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
309 ; SSE41-LABEL: test18:
311 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
316 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
318 %1 = select <4 x i1> <i1 false, i1 true, i1 true, i1 true>, <4 x float> %a, <4 x float> %b
322 define <4 x i32> @test19(<4 x i32> %a, <4 x i32> %b) {
323 ; SSE2-LABEL: test19:
325 ; SSE2-NEXT: movss {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
328 ; SSE41-LABEL: test19:
330 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
335 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
337 %1 = select <4 x i1> <i1 false, i1 true, i1 true, i1 true>, <4 x i32> %a, <4 x i32> %b
341 define <2 x double> @test20(<2 x double> %a, <2 x double> %b) {
342 ; SSE2-LABEL: test20:
344 ; SSE2-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1]
347 ; SSE41-LABEL: test20:
349 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
354 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
356 %1 = select <2 x i1> <i1 false, i1 true>, <2 x double> %a, <2 x double> %b
360 define <2 x i64> @test21(<2 x i64> %a, <2 x i64> %b) {
361 ; SSE2-LABEL: test21:
363 ; SSE2-NEXT: movsd {{.*#+}} xmm0 = xmm1[0],xmm0[1]
366 ; SSE41-LABEL: test21:
368 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
373 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
375 %1 = select <2 x i1> <i1 false, i1 true>, <2 x i64> %a, <2 x i64> %b
379 define <4 x float> @test22(<4 x float> %a, <4 x float> %b) {
380 ; SSE2-LABEL: test22:
382 ; SSE2-NEXT: movss {{.*#+}} xmm1 = xmm0[0],xmm1[1,2,3]
383 ; SSE2-NEXT: movaps %xmm1, %xmm0
386 ; SSE41-LABEL: test22:
388 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
393 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
395 %1 = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x float> %a, <4 x float> %b
399 define <4 x i32> @test23(<4 x i32> %a, <4 x i32> %b) {
400 ; SSE2-LABEL: test23:
402 ; SSE2-NEXT: movss {{.*#+}} xmm1 = xmm0[0],xmm1[1,2,3]
403 ; SSE2-NEXT: movaps %xmm1, %xmm0
406 ; SSE41-LABEL: test23:
408 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
413 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
415 %1 = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x i32> %a, <4 x i32> %b
419 define <2 x double> @test24(<2 x double> %a, <2 x double> %b) {
420 ; SSE2-LABEL: test24:
422 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
425 ; SSE41-LABEL: test24:
427 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
432 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
434 %1 = select <2 x i1> <i1 true, i1 false>, <2 x double> %a, <2 x double> %b
438 define <2 x i64> @test25(<2 x i64> %a, <2 x i64> %b) {
439 ; SSE2-LABEL: test25:
441 ; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
444 ; SSE41-LABEL: test25:
446 ; SSE41-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
451 ; AVX-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
453 %1 = select <2 x i1> <i1 true, i1 false>, <2 x i64> %a, <2 x i64> %b
457 define <16 x i8> @test26(<16 x i8> %a, <16 x i8> %b) {
458 ; SSE2-LABEL: test26:
460 ; SSE2-NEXT: movaps {{.*#+}} xmm2 = [255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0]
461 ; SSE2-NEXT: andps %xmm2, %xmm1
462 ; SSE2-NEXT: andnps %xmm0, %xmm2
463 ; SSE2-NEXT: orps %xmm1, %xmm2
464 ; SSE2-NEXT: movaps %xmm2, %xmm0
467 ; SSE41-LABEL: test26:
469 ; SSE41-NEXT: movdqa %xmm0, %xmm2
470 ; SSE41-NEXT: movaps {{.*#+}} xmm0 = [255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0]
471 ; SSE41-NEXT: pblendvb %xmm0, %xmm1, %xmm2
472 ; SSE41-NEXT: movdqa %xmm2, %xmm0
475 ; AVX1-LABEL: test26:
477 ; AVX1-NEXT: vbroadcastss {{.*#+}} xmm2 = [255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0]
478 ; AVX1-NEXT: vpblendvb %xmm2, %xmm1, %xmm0, %xmm0
481 ; AVX2-LABEL: test26:
483 ; AVX2-NEXT: vpbroadcastw {{.*#+}} xmm2 = [255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0]
484 ; AVX2-NEXT: vpblendvb %xmm2, %xmm1, %xmm0, %xmm0
486 %1 = select <16 x i1> <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, i1 true>, <16 x i8> %a, <16 x i8> %b
490 define <32 x i8> @test27(<32 x i8> %a, <32 x i8> %b) {
491 ; SSE2-LABEL: test27:
493 ; SSE2-NEXT: movaps {{.*#+}} xmm4 = [255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255]
494 ; SSE2-NEXT: movaps %xmm4, %xmm5
495 ; SSE2-NEXT: andnps %xmm2, %xmm5
496 ; SSE2-NEXT: andps %xmm4, %xmm0
497 ; SSE2-NEXT: orps %xmm5, %xmm0
498 ; SSE2-NEXT: andps %xmm4, %xmm1
499 ; SSE2-NEXT: andnps %xmm3, %xmm4
500 ; SSE2-NEXT: orps %xmm4, %xmm1
503 ; SSE41-LABEL: test27:
505 ; SSE41-NEXT: movdqa %xmm0, %xmm4
506 ; SSE41-NEXT: movaps {{.*#+}} xmm0 = [255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255]
507 ; SSE41-NEXT: pblendvb %xmm0, %xmm4, %xmm2
508 ; SSE41-NEXT: pblendvb %xmm0, %xmm1, %xmm3
509 ; SSE41-NEXT: movdqa %xmm2, %xmm0
510 ; SSE41-NEXT: movdqa %xmm3, %xmm1
513 ; AVX1-LABEL: test27:
515 ; AVX1-NEXT: vbroadcastss {{.*#+}} ymm2 = [255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255]
516 ; AVX1-NEXT: vandnps %ymm1, %ymm2, %ymm1
517 ; AVX1-NEXT: vandps %ymm2, %ymm0, %ymm0
518 ; AVX1-NEXT: vorps %ymm1, %ymm0, %ymm0
521 ; AVX2-LABEL: test27:
523 ; AVX2-NEXT: vpbroadcastd {{.*#+}} ymm2 = [255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0,0,255]
524 ; AVX2-NEXT: vpblendvb %ymm2, %ymm0, %ymm1, %ymm0
526 %1 = select <32 x i1> <i1 true, i1 false, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true, i1 true, i1 false, i1 false, i1 true>, <32 x i8> %a, <32 x i8> %b
530 define <4 x float> @select_of_shuffles_0(<2 x float> %a0, <2 x float> %b0, <2 x float> %a1, <2 x float> %b1) {
531 ; SSE-LABEL: select_of_shuffles_0:
533 ; SSE-NEXT: movlhps {{.*#+}} xmm0 = xmm0[0],xmm2[0]
534 ; SSE-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0],xmm3[0]
535 ; SSE-NEXT: subps %xmm1, %xmm0
538 ; AVX-LABEL: select_of_shuffles_0:
540 ; AVX-NEXT: vmovlhps {{.*#+}} xmm0 = xmm0[0],xmm2[0]
541 ; AVX-NEXT: vmovlhps {{.*#+}} xmm1 = xmm1[0],xmm3[0]
542 ; AVX-NEXT: vsubps %xmm1, %xmm0, %xmm0
544 %1 = shufflevector <2 x float> %a0, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
545 %2 = shufflevector <2 x float> %a1, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
546 %3 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %2, <4 x float> %1
547 %4 = shufflevector <2 x float> %b0, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
548 %5 = shufflevector <2 x float> %b1, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
549 %6 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %5, <4 x float> %4
550 %7 = fsub <4 x float> %3, %6
555 define <16 x double> @select_illegal(<16 x double> %a, <16 x double> %b) {
556 ; SSE-LABEL: select_illegal:
558 ; SSE-NEXT: movq %rdi, %rax
559 ; SSE-NEXT: movaps {{[0-9]+}}(%rsp), %xmm4
560 ; SSE-NEXT: movaps {{[0-9]+}}(%rsp), %xmm5
561 ; SSE-NEXT: movaps {{[0-9]+}}(%rsp), %xmm6
562 ; SSE-NEXT: movaps {{[0-9]+}}(%rsp), %xmm7
563 ; SSE-NEXT: movaps %xmm7, 112(%rdi)
564 ; SSE-NEXT: movaps %xmm6, 96(%rdi)
565 ; SSE-NEXT: movaps %xmm5, 80(%rdi)
566 ; SSE-NEXT: movaps %xmm4, 64(%rdi)
567 ; SSE-NEXT: movaps %xmm3, 48(%rdi)
568 ; SSE-NEXT: movaps %xmm2, 32(%rdi)
569 ; SSE-NEXT: movaps %xmm1, 16(%rdi)
570 ; SSE-NEXT: movaps %xmm0, (%rdi)
573 ; AVX-LABEL: select_illegal:
575 ; AVX-NEXT: vmovaps %ymm7, %ymm3
576 ; AVX-NEXT: vmovaps %ymm6, %ymm2
578 %sel = select <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <16 x double> %a, <16 x double> %b
579 ret <16 x double> %sel
582 ; Make sure we can optimize the condition MSB when it is used by 2 selects.
583 ; The v2i1 here will be passed as v2i64 and we will emit a sign_extend_inreg to fill the upper bits.
584 ; We should be able to remove the sra from the sign_extend_inreg to leave only shl.
585 define <2 x i64> @shrunkblend_2uses(<2 x i1> %cond, <2 x i64> %a, <2 x i64> %b, <2 x i64> %c, <2 x i64> %d) {
586 ; SSE2-LABEL: shrunkblend_2uses:
588 ; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,0,2,2]
589 ; SSE2-NEXT: pslld $31, %xmm0
590 ; SSE2-NEXT: psrad $31, %xmm0
591 ; SSE2-NEXT: movdqa %xmm0, %xmm5
592 ; SSE2-NEXT: pandn %xmm2, %xmm5
593 ; SSE2-NEXT: pand %xmm0, %xmm1
594 ; SSE2-NEXT: por %xmm1, %xmm5
595 ; SSE2-NEXT: pand %xmm0, %xmm3
596 ; SSE2-NEXT: pandn %xmm4, %xmm0
597 ; SSE2-NEXT: por %xmm3, %xmm0
598 ; SSE2-NEXT: paddq %xmm5, %xmm0
601 ; SSE41-LABEL: shrunkblend_2uses:
603 ; SSE41-NEXT: psllq $63, %xmm0
604 ; SSE41-NEXT: blendvpd %xmm0, %xmm1, %xmm2
605 ; SSE41-NEXT: blendvpd %xmm0, %xmm3, %xmm4
606 ; SSE41-NEXT: paddq %xmm2, %xmm4
607 ; SSE41-NEXT: movdqa %xmm4, %xmm0
610 ; AVX-LABEL: shrunkblend_2uses:
612 ; AVX-NEXT: vpsllq $63, %xmm0, %xmm0
613 ; AVX-NEXT: vblendvpd %xmm0, %xmm1, %xmm2, %xmm1
614 ; AVX-NEXT: vblendvpd %xmm0, %xmm3, %xmm4, %xmm0
615 ; AVX-NEXT: vpaddq %xmm0, %xmm1, %xmm0
617 %x = select <2 x i1> %cond, <2 x i64> %a, <2 x i64> %b
618 %y = select <2 x i1> %cond, <2 x i64> %c, <2 x i64> %d
619 %z = add <2 x i64> %x, %y
623 ; Similar to above, but condition has a use that isn't a condition of a vselect so we can't optimize.
624 define <2 x i64> @shrunkblend_nonvselectuse(<2 x i1> %cond, <2 x i64> %a, <2 x i64> %b, <2 x i64> %c, <2 x i64> %d) {
625 ; SSE2-LABEL: shrunkblend_nonvselectuse:
627 ; SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[0,0,2,2]
628 ; SSE2-NEXT: pslld $31, %xmm3
629 ; SSE2-NEXT: psrad $31, %xmm3
630 ; SSE2-NEXT: movdqa %xmm3, %xmm0
631 ; SSE2-NEXT: pandn %xmm2, %xmm0
632 ; SSE2-NEXT: pand %xmm3, %xmm1
633 ; SSE2-NEXT: por %xmm1, %xmm0
634 ; SSE2-NEXT: paddq %xmm3, %xmm0
637 ; SSE41-LABEL: shrunkblend_nonvselectuse:
639 ; SSE41-NEXT: psllq $63, %xmm0
640 ; SSE41-NEXT: blendvpd %xmm0, %xmm1, %xmm2
641 ; SSE41-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,1,3,3]
642 ; SSE41-NEXT: psrad $31, %xmm0
643 ; SSE41-NEXT: paddq %xmm2, %xmm0
646 ; AVX-LABEL: shrunkblend_nonvselectuse:
648 ; AVX-NEXT: vpsllq $63, %xmm0, %xmm0
649 ; AVX-NEXT: vblendvpd %xmm0, %xmm1, %xmm2, %xmm1
650 ; AVX-NEXT: vxorpd %xmm2, %xmm2, %xmm2
651 ; AVX-NEXT: vpcmpgtq %xmm0, %xmm2, %xmm0
652 ; AVX-NEXT: vpaddq %xmm0, %xmm1, %xmm0
654 %x = select <2 x i1> %cond, <2 x i64> %a, <2 x i64> %b
655 %y = sext <2 x i1> %cond to <2 x i64>
656 %z = add <2 x i64> %x, %y
660 ; This turns into a SHRUNKBLEND with SSE4 or later, and via
661 ; late shuffle magic, both sides of the blend are the same
662 ; value. If that is not simplified before isel, it can fail
665 define <2 x i32> @simplify_select(i32 %x, <2 x i1> %z) {
666 ; SSE2-LABEL: simplify_select:
668 ; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
669 ; SSE2-NEXT: pslld $31, %xmm0
670 ; SSE2-NEXT: psrad $31, %xmm0
671 ; SSE2-NEXT: movd %edi, %xmm1
672 ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm1[1,0,1,1]
673 ; SSE2-NEXT: por %xmm1, %xmm2
674 ; SSE2-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0,0]
675 ; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[2,0],xmm2[1,1]
676 ; SSE2-NEXT: pand %xmm0, %xmm2
677 ; SSE2-NEXT: pandn %xmm1, %xmm0
678 ; SSE2-NEXT: por %xmm2, %xmm0
681 ; SSE41-LABEL: simplify_select:
683 ; SSE41-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
684 ; SSE41-NEXT: pslld $31, %xmm0
685 ; SSE41-NEXT: movd %edi, %xmm1
686 ; SSE41-NEXT: pshufd {{.*#+}} xmm2 = xmm1[1,0,1,1]
687 ; SSE41-NEXT: por %xmm1, %xmm2
688 ; SSE41-NEXT: pshufd {{.*#+}} xmm1 = xmm2[1,1,1,1]
689 ; SSE41-NEXT: pinsrd $1, %edi, %xmm1
690 ; SSE41-NEXT: blendvps %xmm0, %xmm2, %xmm1
691 ; SSE41-NEXT: movaps %xmm1, %xmm0
694 ; AVX-LABEL: simplify_select:
696 ; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
697 ; AVX-NEXT: vpslld $31, %xmm0, %xmm0
698 ; AVX-NEXT: vmovd %edi, %xmm1
699 ; AVX-NEXT: vpshufd {{.*#+}} xmm2 = xmm1[1,0,1,1]
700 ; AVX-NEXT: vpor %xmm1, %xmm2, %xmm1
701 ; AVX-NEXT: vpshufd {{.*#+}} xmm2 = xmm1[1,1,1,1]
702 ; AVX-NEXT: vpinsrd $1, %edi, %xmm2, %xmm2
703 ; AVX-NEXT: vblendvps %xmm0, %xmm1, %xmm2, %xmm0
705 %a = insertelement <2 x i32> <i32 0, i32 undef>, i32 %x, i32 1
706 %b = insertelement <2 x i32> <i32 undef, i32 0>, i32 %x, i32 0
707 %y = or <2 x i32> %a, %b
708 %p16 = extractelement <2 x i32> %y, i32 1
709 %p17 = insertelement <2 x i32> undef, i32 %p16, i32 0
710 %p18 = insertelement <2 x i32> %p17, i32 %x, i32 1
711 %r = select <2 x i1> %z, <2 x i32> %y, <2 x i32> %p18
715 ; Test to make sure we don't try to insert a new setcc to swap the operands
716 ; of select with all zeros LHS if the setcc has additional users.
717 define void @vselect_allzeros_LHS_multiple_use_setcc(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z, ptr %p1, ptr %p2) {
718 ; SSE2-LABEL: vselect_allzeros_LHS_multiple_use_setcc:
720 ; SSE2-NEXT: movdqa {{.*#+}} xmm3 = [1,2,4,8]
721 ; SSE2-NEXT: pand %xmm3, %xmm0
722 ; SSE2-NEXT: pcmpeqd %xmm3, %xmm0
723 ; SSE2-NEXT: movdqa %xmm0, %xmm3
724 ; SSE2-NEXT: pandn %xmm1, %xmm3
725 ; SSE2-NEXT: pand %xmm2, %xmm0
726 ; SSE2-NEXT: movdqa %xmm3, (%rdi)
727 ; SSE2-NEXT: movdqa %xmm0, (%rsi)
730 ; SSE41-LABEL: vselect_allzeros_LHS_multiple_use_setcc:
732 ; SSE41-NEXT: pmovsxbd {{.*#+}} xmm3 = [1,2,4,8]
733 ; SSE41-NEXT: pand %xmm3, %xmm0
734 ; SSE41-NEXT: pcmpeqd %xmm3, %xmm0
735 ; SSE41-NEXT: movdqa %xmm0, %xmm3
736 ; SSE41-NEXT: pandn %xmm1, %xmm3
737 ; SSE41-NEXT: pand %xmm2, %xmm0
738 ; SSE41-NEXT: movdqa %xmm3, (%rdi)
739 ; SSE41-NEXT: movdqa %xmm0, (%rsi)
742 ; AVX-LABEL: vselect_allzeros_LHS_multiple_use_setcc:
744 ; AVX-NEXT: vpmovsxbd {{.*#+}} xmm3 = [1,2,4,8]
745 ; AVX-NEXT: vpand %xmm3, %xmm0, %xmm0
746 ; AVX-NEXT: vpcmpeqd %xmm3, %xmm0, %xmm0
747 ; AVX-NEXT: vpandn %xmm1, %xmm0, %xmm1
748 ; AVX-NEXT: vpand %xmm2, %xmm0, %xmm0
749 ; AVX-NEXT: vmovdqa %xmm1, (%rdi)
750 ; AVX-NEXT: vmovdqa %xmm0, (%rsi)
752 %and = and <4 x i32> %x, <i32 1, i32 2, i32 4, i32 8>
753 %cond = icmp ne <4 x i32> %and, zeroinitializer
754 %sel1 = select <4 x i1> %cond, <4 x i32> zeroinitializer, <4 x i32> %y
755 %sel2 = select <4 x i1> %cond, <4 x i32> %z, <4 x i32> zeroinitializer
756 store <4 x i32> %sel1, ptr %p1
757 store <4 x i32> %sel2, ptr %p2
761 ; This test case previously crashed after r363802, r363850, and r363856 due
762 ; any_extend_vector_inreg not being handled by the X86 backend.
763 define i64 @vselect_any_extend_vector_inreg_crash(ptr %x) {
764 ; SSE-LABEL: vselect_any_extend_vector_inreg_crash:
766 ; SSE-NEXT: movq {{.*#+}} xmm0 = mem[0],zero
767 ; SSE-NEXT: pcmpeqb {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
768 ; SSE-NEXT: movd %xmm0, %eax
769 ; SSE-NEXT: andl $1, %eax
770 ; SSE-NEXT: shll $15, %eax
773 ; AVX1-LABEL: vselect_any_extend_vector_inreg_crash:
775 ; AVX1-NEXT: vmovq {{.*#+}} xmm0 = mem[0],zero
776 ; AVX1-NEXT: vpcmpeqb {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
777 ; AVX1-NEXT: vmovd %xmm0, %eax
778 ; AVX1-NEXT: andl $1, %eax
779 ; AVX1-NEXT: shll $15, %eax
782 ; AVX2-LABEL: vselect_any_extend_vector_inreg_crash:
784 ; AVX2-NEXT: vmovq {{.*#+}} xmm0 = mem[0],zero
785 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [49,49,49,49]
786 ; AVX2-NEXT: vpcmpeqb %xmm1, %xmm0, %xmm0
787 ; AVX2-NEXT: vmovd %xmm0, %eax
788 ; AVX2-NEXT: andl $1, %eax
789 ; AVX2-NEXT: shll $15, %eax
792 %1 = load <8 x i8>, ptr %x
793 %2 = icmp eq <8 x i8> %1, <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
794 %3 = select <8 x i1> %2, <8 x i64> <i64 32768, i64 16384, i64 8192, i64 4096, i64 2048, i64 1024, i64 512, i64 256>, <8 x i64> zeroinitializer
795 %4 = extractelement <8 x i64> %3, i32 0