[llvm] [SCEV] Fold ((-1 * C1) * D / C1) -> -1 * D. (PR #157555)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 10 02:23:03 PDT 2025
================
@@ -3217,15 +3217,19 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
}
// Try to fold (C1 * D /u C2) -> C1/C2 * D, if C1 and C2 are powers-of-2,
- // D is a multiple of C2, and C1 is a multiple of C1.
+ // D is a multiple of C2, and C1 is a multiple of C2.
const SCEV *D;
+ APInt C1V = LHSC->getAPInt();
+ // (C1 * D /u C2) == -1 * -C1 * D /u C2 when C1 != INT_MIN.
+ if (C1V.isNegative() && !C1V.isMinSignedValue())
----------------
fhahn wrote:
Yeah it's a no-op, we would end up with `(-INT_MIN * D /u C2) == (-1 * -INT_MIN * D /u C2)`. Can change to use `abs()` if you prefer and remove the check?
https://github.com/llvm/llvm-project/pull/157555
More information about the llvm-commits
mailing list