[llvm] [SCEV] Look thru more expressions in isKnownMultipleOf (PR #219951)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 01:00:08 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.
----------------
nikic wrote:

Why is this limited to just umin/umax now? Doesn't it hold for smin/smax as well?

https://github.com/llvm/llvm-project/pull/219951


More information about the llvm-commits mailing list