[llvm] Add more cases for computeOverflowForSignedAdd (PR #99900)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 12:56:51 PDT 2024
================
@@ -4243,8 +4243,27 @@ SelectionDAG::computeOverflowForSignedAdd(SDValue N0, SDValue N1) const {
if (ComputeNumSignBits(N0) > 1 && ComputeNumSignBits(N1) > 1)
return OFK_Never;
- // TODO: Add ConstantRange::signedAddMayOverflow handling.
- return OFK_Sometime;
+ // smulhi + any value less than half of signed max
+ KnownBits N1Known = computeKnownBits(N1);
+ if (N0.getOpcode() == ISD::SMUL_LOHI && N0.getResNo() == 1) {
+ APInt Max = APInt::getSignedMaxValue(N1.getScalarValueSizeInBits());
+ Max.lshrInPlace(1);
+ if (N1Known.getMaxValue().sle(Max))
----------------
topperc wrote:
If N1Known.getMaxValue() has bit 31 is will be considered negative number and it will be less than `Max` so you'll say it doesn't overflow. But if the result of the smulhi is negative, adding a negative number may overflow.
https://github.com/llvm/llvm-project/pull/99900
More information about the llvm-commits
mailing list