[llvm] [IndVars] Improve code; use SCEVPatternMatch (NFC) (PR #139533)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu May 22 09:08:24 PDT 2025


================
@@ -806,12 +807,9 @@ static bool isLoopCounter(PHINode* Phi, Loop *L,
   if (!SE->isSCEVable(Phi->getType()))
     return false;
 
-  const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(Phi));
-  if (!AR || AR->getLoop() != L || !AR->isAffine())
-    return false;
-
-  const SCEV *Step = dyn_cast<SCEVConstant>(AR->getStepRecurrence(*SE));
-  if (!Step || !Step->isOne())
+  const SCEV *S = SE->getSCEV(Phi);
+  if (!match(S, m_scev_AffineAddRec(m_SCEV(), m_scev_One())) ||
+      cast<SCEVAddRecExpr>(S)->getLoop() != L)
----------------
fhahn wrote:

Yeah I had some code for that lying around somewhere, let me see if I can find it again

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


More information about the llvm-commits mailing list