Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4940,17 +4940,18 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
// If we have a clamp pattern, we know that the number of sign bits will be
// the minimum of the clamp min/max range.
bool IsMax = (Opcode == ISD::SMAX);
ConstantSDNode *CstLow = nullptr, *CstHigh = nullptr;
if ((CstLow = isConstOrConstSplat(Op.getOperand(1), DemandedElts)))
KnownBits KnownLow, KnownHigh;
KnownLow = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
if (KnownLow.isConstant())
if (Op.getOperand(0).getOpcode() == (IsMax ? ISD::SMIN : ISD::SMAX))
CstHigh =
isConstOrConstSplat(Op.getOperand(0).getOperand(1), DemandedElts);
if (CstLow && CstHigh) {
KnownHigh = computeKnownBits(Op.getOperand(0).getOperand(1),
DemandedElts, Depth + 2);
if (KnownLow.isConstant() && KnownHigh.isConstant()) {
if (!IsMax)
std::swap(CstLow, CstHigh);
if (CstLow->getAPIntValue().sle(CstHigh->getAPIntValue())) {
Tmp = CstLow->getAPIntValue().getNumSignBits();
Tmp2 = CstHigh->getAPIntValue().getNumSignBits();
std::swap(KnownLow, KnownHigh);
if (KnownLow.getConstant().sle(KnownHigh.getConstant())) {
Tmp = KnownLow.getConstant().getNumSignBits();
Tmp2 = KnownHigh.getConstant().getNumSignBits();
return std::min(Tmp, Tmp2);
}
}
Expand Down