Skip to content

Commit 066773c

Browse files
committed
[X86] computeKnownBitsForTargetNode - add generic handling of PSHUFB
When PSHUFB is used as a LUT (for CTPOP, BITREVERSE etc.), its the source operand that is constant and the index operand the variable. As long as the indices don't set the MSB (which zeros the output element), then the common known bits from the source operand can be used directly, even though the shuffle mask isn't constant. Further helps to improve CTPOP reduction codegen
1 parent 94100bc commit 066773c

File tree

2 files changed

+191
-205
lines changed

2 files changed

+191
-205
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36707,6 +36707,19 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
3670736707
Known = Known.trunc(BitWidth);
3670836708
break;
3670936709
}
36710+
case X86ISD::PSHUFB: {
36711+
SDValue Src = Op.getOperand(0);
36712+
SDValue Idx = Op.getOperand(1);
36713+
36714+
// If the index vector is never negative (MSB is zero), then all elements
36715+
// come from the source vector. This is useful for cases where
36716+
// PSHUFB is being used as a LUT (ctpop etc.) - the target shuffle handling
36717+
// below will handle the more common constant shuffle mask case.
36718+
KnownBits KnownIdx = DAG.computeKnownBits(Idx, DemandedElts, Depth + 1);
36719+
if (KnownIdx.isNonNegative())
36720+
Known = DAG.computeKnownBits(Src, Depth + 1);
36721+
break;
36722+
}
3671036723
case X86ISD::VBROADCAST: {
3671136724
SDValue Src = Op.getOperand(0);
3671236725
if (!Src.getSimpleValueType().isVector()) {

0 commit comments

Comments
 (0)