[llvm] Add more cases for computeOverflowForSignedAdd (PR #99900)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 13:36:17 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:
Neither SMUL_LOHI or MULHS are supported in ComputeNumSignBits. Seems like we should start there before adding a special case to `computeOverflowForSignedAdd`.
https://github.com/llvm/llvm-project/pull/99900
More information about the llvm-commits
mailing list