[llvm] [SCEVExpander] Reuse unscaled recurrence when expanding scaled one. (PR #223850)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 02:30:59 PDT 2026


================
@@ -1334,6 +1335,57 @@ Value *SCEVExpander::tryToReuseLCSSAPhi(SCEVUseT<const SCEVAddRecExpr *> S) {
   return nullptr;
 }
 
+/// Try to re-use an existing AddRec when expanding S, if
+/// AddRec * Scale + Offset == S for constant Scale and Offset.
+Value *SCEVExpander::tryToReuseScaledAddRec(const SCEVAddRecExpr *S) {
+  const APInt *Step;
+  if (!S->getType()->isIntegerTy() ||
----------------
fhahn wrote:

It's needed because SCEVDivison::divide below only works for integers.

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


More information about the llvm-commits mailing list