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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 28 13:29: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.lshrInPlace(1);
+    if (N1Known.getMaxValue().sle(Max))
----------------
topperc wrote:

For integers, LLVM uses "overflow" to refer to both directions.

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


More information about the llvm-commits mailing list