Skip to content

Commit 376bc39

Browse files
committed
[SelectionDAG] ComputeNumSignBits - Use getValidShiftAmountConstant for shift opcodes
getValidShiftAmountConstant handles out of bounds shift amounts for us, allowing us to remove the local handling.
1 parent 6d1a8fd commit 376bc39

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,25 +3606,18 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
36063606
Tmp = VTBits - SrcVT.getScalarSizeInBits();
36073607
return ComputeNumSignBits(Src, DemandedSrcElts, Depth+1) + Tmp;
36083608
}
3609-
36103609
case ISD::SRA:
3611-
Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1);
3610+
Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
36123611
// SRA X, C -> adds C sign bits.
3613-
if (ConstantSDNode *C =
3614-
isConstOrConstSplat(Op.getOperand(1), DemandedElts)) {
3615-
APInt ShiftVal = C->getAPIntValue();
3616-
ShiftVal += Tmp;
3617-
Tmp = ShiftVal.uge(VTBits) ? VTBits : ShiftVal.getZExtValue();
3618-
}
3612+
if (const APInt *ShAmt = getValidShiftAmountConstant(Op, DemandedElts))
3613+
Tmp = std::min<uint64_t>(Tmp + ShAmt->getZExtValue(), VTBits);
36193614
return Tmp;
36203615
case ISD::SHL:
3621-
if (ConstantSDNode *C =
3622-
isConstOrConstSplat(Op.getOperand(1), DemandedElts)) {
3623-
// shl destroys sign bits.
3624-
Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1);
3625-
if (C->getAPIntValue().uge(VTBits) || // Bad shift.
3626-
C->getAPIntValue().uge(Tmp)) break; // Shifted all sign bits out.
3627-
return Tmp - C->getZExtValue();
3616+
if (const APInt *ShAmt = getValidShiftAmountConstant(Op, DemandedElts)) {
3617+
// shl destroys sign bits, ensure it doesn't shift out all sign bits.
3618+
Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
3619+
if (ShAmt->ult(Tmp))
3620+
return Tmp - ShAmt->getZExtValue();
36283621
}
36293622
break;
36303623
case ISD::AND:

0 commit comments

Comments
 (0)