[llvm] [LV] Use SCEV to compute final value of complex induction variables (PR #195059)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 10 02:51:58 PDT 2026


================
@@ -1148,8 +1148,43 @@ optimizeLatchExitInductionUser(VPlan &Plan, VPValue *Op,
   return nullptr;
 }
 
+static VPValue *optimizeLatchExitIVUserViaSCEV(VPlan &Plan, VPValue *Op,
+                                               PredicatedScalarEvolution &PSE,
+                                               VPValue *ResumeTC,
+                                               const Loop *L) {
+  VPValue *Incoming;
+  if (!match(Op, m_ExtractLastLaneOfLastPart(m_VPValue(Incoming))))
+    return nullptr;
+
+  const SCEV *IncomingSCEV = vputils::getSCEVExprForVPValue(Incoming, PSE, L);
+  const SCEV *Start, *Step;
+  if (!match(IncomingSCEV, m_scev_AffineAddRec(m_SCEV(Start), m_SCEV(Step),
+                                               m_SpecificLoop(L))))
+    return nullptr;
+
+  // TODO: Start value can be defined be a VPExpandSCEVRecipe after
+  // VPDerivedIVRecipe supports a general VPValue as the start value.
+  VPIRValue *StartIRV = vputils::getVPIRValueForSCEVExpr(Plan, Start);
----------------
Mel-Chen wrote:

df75d573475c3054e3607dd93fab467a5f4de630
Updated the comment, and try to use VPSCEVExpander to gen Step VPValue.

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


More information about the llvm-commits mailing list