[llvm] [SCEV] Fold ((-1 * C1) * D / C1) -> -1 * D. (PR #157555)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 08:32:10 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();
+ // If C1 is negative, try (-1 * abs(C1)) instead.
----------------
preames wrote:
Adjust the comment to something like:
(C1 * D /u C2) == -1 * -C1 * D /u C2 when C1 != INT_MIN
Though maybe that's not quite right because that equality still holds (just not in a useful way) when C1 is INT_MIN.
Basically, we need something here with more of indication of *why* it's correct.
https://github.com/llvm/llvm-project/pull/157555
More information about the llvm-commits
mailing list