[llvm] [SCEV] Look thru more expressions in isKnownMultipleOf (PR #219951)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 00:02: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) {
----------------
nikic wrote:
(Should probably add alive2 proofs...)
https://github.com/llvm/llvm-project/pull/219951
More information about the llvm-commits
mailing list