Skip to content

Commit dc7d9cd

Browse files
committed
[DAG] ComputeNumSignBits - use computeKnownBits instead of isConstOrConstSplat to detect legalised constants
Helps us detect constants that have been lowered to materialisable nodes
1 parent aea82a7 commit dc7d9cd

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,17 +4946,18 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
49464946
// If we have a clamp pattern, we know that the number of sign bits will be
49474947
// the minimum of the clamp min/max range.
49484948
bool IsMax = (Opcode == ISD::SMAX);
4949-
ConstantSDNode *CstLow = nullptr, *CstHigh = nullptr;
4950-
if ((CstLow = isConstOrConstSplat(Op.getOperand(1), DemandedElts)))
4949+
KnownBits KnownLow, KnownHigh;
4950+
KnownLow = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
4951+
if (KnownLow.isConstant())
49514952
if (Op.getOperand(0).getOpcode() == (IsMax ? ISD::SMIN : ISD::SMAX))
4952-
CstHigh =
4953-
isConstOrConstSplat(Op.getOperand(0).getOperand(1), DemandedElts);
4954-
if (CstLow && CstHigh) {
4953+
KnownHigh = computeKnownBits(Op.getOperand(0).getOperand(1),
4954+
DemandedElts, Depth + 2);
4955+
if (KnownLow.isConstant() && KnownHigh.isConstant()) {
49554956
if (!IsMax)
4956-
std::swap(CstLow, CstHigh);
4957-
if (CstLow->getAPIntValue().sle(CstHigh->getAPIntValue())) {
4958-
Tmp = CstLow->getAPIntValue().getNumSignBits();
4959-
Tmp2 = CstHigh->getAPIntValue().getNumSignBits();
4957+
std::swap(KnownLow, KnownHigh);
4958+
if (KnownLow.getConstant().sle(KnownHigh.getConstant())) {
4959+
Tmp = KnownLow.getConstant().getNumSignBits();
4960+
Tmp2 = KnownHigh.getConstant().getNumSignBits();
49604961
return std::min(Tmp, Tmp2);
49614962
}
49624963
}

0 commit comments

Comments
 (0)