[llvm] [ValueTracking] Add a special overflow check on multiplied by power-of-two values (PR #212594)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 29 07:39:08 PDT 2026


================
@@ -7542,6 +7542,23 @@ OverflowResult llvm::computeOverflowForSignedMul(const Value *LHS,
     if (LHSKnown.isNonNegative() || RHSKnown.isNonNegative())
       return OverflowResult::NeverOverflows;
   }
+
+  // Special case when we're multiplying a power-of-two value. In this case,
+  // we will never overflow as long as the shift amount is less than the number
+  // of sign bits.
+  if (isKnownToBeAPowerOfTwo(RHS, /*OrZero=*/false, SQ)) {
+    KnownBits LHSKnown = computeKnownBits(LHS, SQ);
----------------
dtcxzyw wrote:

Not sure if it affects compile time. If so, we may switch to `WithCache<const Value *>`.


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


More information about the llvm-commits mailing list