Skip to content

Commit bf04e34

Browse files
committed
[DAG] computeKnownBits - Replace ISD::SREM handling with KnownBits::srem to reduce code duplication
1 parent 7fe7c6d commit bf04e34

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3249,30 +3249,12 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
32493249
Known = KnownBits::computeForAddCarry(Known, Known2, Carry);
32503250
break;
32513251
}
3252-
case ISD::SREM:
3253-
if (ConstantSDNode *Rem = isConstOrConstSplat(Op.getOperand(1))) {
3254-
const APInt &RA = Rem->getAPIntValue().abs();
3255-
if (RA.isPowerOf2()) {
3256-
APInt LowBits = RA - 1;
3257-
Known2 = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
3258-
3259-
// The low bits of the first operand are unchanged by the srem.
3260-
Known.Zero = Known2.Zero & LowBits;
3261-
Known.One = Known2.One & LowBits;
3262-
3263-
// If the first operand is non-negative or has all low bits zero, then
3264-
// the upper bits are all zero.
3265-
if (Known2.isNonNegative() || LowBits.isSubsetOf(Known2.Zero))
3266-
Known.Zero |= ~LowBits;
3267-
3268-
// If the first operand is negative and not all low bits are zero, then
3269-
// the upper bits are all one.
3270-
if (Known2.isNegative() && LowBits.intersects(Known2.One))
3271-
Known.One |= ~LowBits;
3272-
assert((Known.Zero & Known.One) == 0&&"Bits known to be one AND zero?");
3273-
}
3274-
}
3252+
case ISD::SREM: {
3253+
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
3254+
Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
3255+
Known = KnownBits::srem(Known, Known2);
32753256
break;
3257+
}
32763258
case ISD::UREM: {
32773259
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
32783260
Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);

0 commit comments

Comments
 (0)