[llvm] [IVDesc] Use SCEVPatternMatch to improve code (NFC) (PR #168397)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 25 04:00:35 PST 2025


================
@@ -719,11 +721,12 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
     if (!SE.isSCEVable(Ty))
       return std::nullopt;
 
-    auto *AR = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(V));
-    if (!AR || AR->getLoop() != TheLoop)
+    auto *AR = SE.getSCEV(V);
+    const SCEV *Step;
+    if (!match(AR, m_scev_AffineAddRec(m_SCEV(), m_SCEV(Step),
+                                       m_SpecificLoop(TheLoop))))
       return std::nullopt;
 
-    const SCEV *Step = AR->getStepRecurrence(SE);
----------------
fhahn wrote:

That should be fine, we still need to check the induction separately which should be required to be affine

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


More information about the llvm-commits mailing list