[llvm] [SCEV] Preserve nuw on scaled recurrence start values. (PR #227458)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 00:52:00 PDT 2026


================
@@ -3344,6 +3348,10 @@ SCEVUse ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVUse> &Ops,
       }
 
       const SCEV *NewRec = getAddRecExpr(NewOps, AddRec->getLoop(), Flags);
+      // Flags also hold for the canonical recurrence in the same loop.
+      if (auto *CanonicalRec = dyn_cast<SCEVAddRecExpr>(NewRec->getCanonical());
+          CanonicalRec && CanonicalRec->getLoop() == AddRec->getLoop())
+        setNoWrapFlags(const_cast<SCEVAddRecExpr *>(CanonicalRec), Flags);
----------------
nikic wrote:

Hm, I'm not entirely sure if this is always safe in this form (maybe the canonical addrec happens to fold in some different way?)

Where do we end up needing this?

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


More information about the llvm-commits mailing list