[llvm] [SCEV] Look thru more expressions in isKnownMultipleOf (PR #219951)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 00:26:20 PDT 2026
================
@@ -11285,6 +11243,26 @@ bool ScalarEvolution::isKnownMultipleOf(
if (!Predicates)
return false;
+ // Look through AddRec, Add, and Mul expressions 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. This doesn't hold in
+ // wrapping arithmetic.
+ if (isa<SCEVAddRecExpr, SCEVAddExpr, SCEVMulExpr>(S))
+ if (cast<SCEVNAryExpr>(S)->getNoWrapFlags() != SCEV::FlagAnyWrap &&
+ all_of(S->operands(), [&](SCEVUse Op) {
+ return isKnownMultipleOf(Op, M, Predicates);
+ }))
+ return true;
+
+ // Similarly, look through MinMax to improve the precision of added
+ // predicates. There is no wrapping arithmetic to consider, as the operations
+ // just return one of its operands.
+ if (isa<SCEVMinMaxExpr>(S))
+ if (any_of(S->operands(), [&](SCEVUse Op) {
----------------
artagnon wrote:
Yes, it turned out to be more non-trivial than I thought: https://alive2.llvm.org/ce/z/RtFrYz -- it looks like AddRec doesn't require any wrapping flags? Could you kindly verify?
https://github.com/llvm/llvm-project/pull/219951
More information about the llvm-commits
mailing list