[llvm] Add more cases for computeOverflowForSignedAdd (PR #99900)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 27 18:01:57 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 <<= 1;
----------------
topperc wrote:

This isn't "half of signed max", it's 2x signed max.

https://github.com/llvm/llvm-project/pull/99900


More information about the llvm-commits mailing list