Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 3074f79

Browse files
committed
[SelectionDAG] We can ignore knownbits from an undef shuffle vector index if we don't actually demand that element
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288839 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent feccc03 commit 3074f79

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,16 +2083,16 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
20832083
const ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op);
20842084
assert(NumElts == SVN->getMask().size() && "Unexpected vector size");
20852085
for (unsigned i = 0; i != NumElts; ++i) {
2086+
if (!DemandedElts[i])
2087+
continue;
2088+
20862089
int M = SVN->getMaskElt(i);
20872090
if (M < 0) {
20882091
// For UNDEF elements, we don't know anything about the common state of
20892092
// the shuffle result.
2090-
// FIXME: Is this too pessimistic?
20912093
KnownZero = KnownOne = APInt(BitWidth, 0);
20922094
break;
20932095
}
2094-
if (!DemandedElts[i])
2095-
continue;
20962096

20972097
if ((unsigned)M < NumElts)
20982098
DemandedLHS.setBit((unsigned)M % NumElts);

test/CodeGen/X86/known-bits-vector.ll

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,39 @@ define <4 x i32> @knownbits_mask_shuffle_shuffle_sext(<8 x i16> %a0) nounwind {
7474
; X32-LABEL: knownbits_mask_shuffle_shuffle_sext:
7575
; X32: # BB#0:
7676
; X32-NEXT: vpand {{\.LCPI.*}}, %xmm0, %xmm0
77+
; X32-NEXT: vpxor %xmm1, %xmm1, %xmm1
78+
; X32-NEXT: vpunpckhwd {{.*#+}} xmm0 = xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
79+
; X32-NEXT: retl
80+
;
81+
; X64-LABEL: knownbits_mask_shuffle_shuffle_sext:
82+
; X64: # BB#0:
83+
; X64-NEXT: vpand {{.*}}(%rip), %xmm0, %xmm0
84+
; X64-NEXT: vpxor %xmm1, %xmm1, %xmm1
85+
; X64-NEXT: vpunpckhwd {{.*#+}} xmm0 = xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
86+
; X64-NEXT: retq
87+
%1 = and <8 x i16> %a0, <i16 -1, i16 -1, i16 -1, i16 -1, i16 15, i16 15, i16 15, i16 15>
88+
%2 = shufflevector <8 x i16> %1, <8 x i16> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
89+
%3 = shufflevector <8 x i16> %2, <8 x i16> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
90+
%4 = sext <4 x i16> %3 to <4 x i32>
91+
ret <4 x i32> %4
92+
}
93+
94+
define <4 x i32> @knownbits_mask_shuffle_shuffle_undef_sext(<8 x i16> %a0) nounwind {
95+
; X32-LABEL: knownbits_mask_shuffle_shuffle_undef_sext:
96+
; X32: # BB#0:
97+
; X32-NEXT: vpand {{\.LCPI.*}}, %xmm0, %xmm0
7798
; X32-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,3,0,1]
7899
; X32-NEXT: vpmovsxwd %xmm0, %xmm0
79100
; X32-NEXT: retl
80101
;
81-
; X64-LABEL: knownbits_mask_shuffle_shuffle_sext:
102+
; X64-LABEL: knownbits_mask_shuffle_shuffle_undef_sext:
82103
; X64: # BB#0:
83104
; X64-NEXT: vpand {{.*}}(%rip), %xmm0, %xmm0
84105
; X64-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[2,3,0,1]
85106
; X64-NEXT: vpmovsxwd %xmm0, %xmm0
86107
; X64-NEXT: retq
87108
%1 = and <8 x i16> %a0, <i16 -1, i16 -1, i16 -1, i16 -1, i16 15, i16 15, i16 15, i16 15>
88-
%2 = shufflevector <8 x i16> %1, <8 x i16> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
109+
%2 = shufflevector <8 x i16> %1, <8 x i16> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
89110
%3 = shufflevector <8 x i16> %2, <8 x i16> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
90111
%4 = sext <4 x i16> %3 to <4 x i32>
91112
ret <4 x i32> %4

0 commit comments

Comments
 (0)