llvm.org GIT mirror llvm / 4eca4cb
[CodeGen] Teach OR combine of shuffles involving zero vectors to better handle undef indices. Undef indices can now be treated as zeros. Or if its undef ORed with zero, we will keep the undef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274472 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 4 years ago
2 changed file(s) with 12 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
37743774 int M0 = SV0->getMaskElt(i);
37753775 int M1 = SV1->getMaskElt(i);
37763776
3777 // Both shuffle indexes are undef. Propagate Undef.
3778 if (M0 < 0 && M1 < 0) {
3777 // Determine if either index is pointing to a zero vector.
3778 bool M0Zero = M0 < 0 || (ZeroN00 == (M0 < NumElts));
3779 bool M1Zero = M1 < 0 || (ZeroN10 == (M1 < NumElts));
3780
3781 // If one element is zero and the otherside is undef, keep undef.
3782 // This also handles the case that both are undef.
3783 if ((M0Zero && M1 < 0) || (M1Zero && M0 < 0)) {
37793784 Mask[i] = -1;
37803785 continue;
37813786 }
37823787
3783 // Determine if either index is pointing to a zero vector.
3784 bool M0Zero = M0 >= 0 && (ZeroN00 == (M0 < NumElts));
3785 bool M1Zero = M1 >= 0 && (ZeroN10 == (M1 < NumElts));
3788 // Make sure only one of the elements is zero.
37863789 if (M0Zero == M1Zero) {
37873790 CanFold = false;
37883791 break;
37893792 }
3793
3794 assert((M0 >= 0 || M1 >= 0) && "Undef index!");
37903795
37913796 // We have a zero and non-zero element. If the non-zero came from
37923797 // SV0 make the index a LHS index. If it came from SV1, make it
396396 define <4 x i32> @test2e(<4 x i32> %a, <4 x i32> %b) {
397397 ; CHECK-LABEL: test2e:
398398 ; CHECK: # BB#0:
399 ; CHECK-NEXT: pxor %xmm2, %xmm2
400 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm2[2,3],xmm0[4,5,6,7]
401 ; CHECK-NEXT: movq {{.*#+}} xmm1 = xmm1[0],zero
402 ; CHECK-NEXT: por %xmm1, %xmm0
399 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5,6,7]
403400 ; CHECK-NEXT: retq
404401 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> , <4 x i32>
405402 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> , <4 x i32>
410407 define <4 x i32> @test2f(<4 x i32> %a, <4 x i32> %b) {
411408 ; CHECK-LABEL: test2f:
412409 ; CHECK: # BB#0:
413 ; CHECK-NEXT: pshufd {{.*#+}} xmm0 = xmm0[3,1,2,3]
414 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3],xmm0[4,5,6,7]
410 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5,6,7]
415411 ; CHECK-NEXT: retq
416412 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> , <4 x i32>
417413 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> , <4 x i32>