[llvm] [SCEV] Preserve divisibility info when creating UMax/SMax expressions. (PR #160012)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 8 07:59:21 PDT 2025


================
@@ -15746,6 +15746,11 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
     // DividesBy.
     std::function<bool(const SCEV *, const SCEV *&)> HasDivisibiltyInfo =
         [&](const SCEV *Expr, const SCEV *&DividesBy) {
+          const APInt &Multiple = SE.getConstantMultiple(Expr);
+          if (!Multiple.isOne()) {
+            DividesBy = SE.getConstant(Multiple);
+            return true;
+          }
----------------
nikic wrote:

Do we still need the code below this? I'd expect getConstantMultiple to be able to handle the `(A /u B) * B` case (assuming we infer nuw on that `*`).

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


More information about the llvm-commits mailing list