[llvm] [SCEV] Look thru more expressions in isKnownMultipleOf (PR #219951)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 01:04:37 PDT 2026
================
@@ -11330,6 +11321,29 @@ bool ScalarEvolution::isKnownMultipleOf(
if (!Predicates)
return false;
+ // Look through Add and AddRec expressions with nuw to improve the
+ // precision of added predicates. S is a multiple of M if S starts with a
+ // multiple of M and at every iteration step S only adds multiples of M.
+ if (isa<SCEVAddExpr, SCEVAddRecExpr>(S) &&
+ cast<SCEVNAryExpr>(S)->hasNoUnsignedWrap() &&
+ all_of(S->operands(),
+ [&](SCEVUse Op) { return isKnownMultipleOf(Op, M, Predicates); }))
+ return true;
+
+ // Similarly, look through Mul with nuw, where any operand being a
+ // known-multiple is sufficient.
+ if (auto *Mul = dyn_cast<SCEVMulExpr>(S))
+ if (Mul->hasNoUnsignedWrap() && any_of(S->operands(), [&](SCEVUse Op) {
+ return isKnownMultipleOf(Op, M, Predicates);
+ }))
+ return true;
+
+ // Similarly, look through UMinMax, with no wrapping arithmetic to consider.
----------------
artagnon wrote:
I found it a bit surprisingly that it does indeed hold, considering that we do urem.
https://github.com/llvm/llvm-project/pull/219951
More information about the llvm-commits
mailing list