[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 17 03:42:43 PDT 2026


================
@@ -1157,8 +1157,44 @@ 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))))
----------------
Mel-Chen wrote:

Yes, the previous version of this patch didn't support tail folding.
4f98125dbfde6c0d7f4e69e584b8868ce31ad96e updates `llvm/test/Transforms/LoopVectorize/iv_outside_user.ll` to produce tail-folded results.
6e42c286b727d4d0ff1a3bce2ee13b90cd98d8e7 adds the actual code to support tail folding.

Please let me know if we should include tail folding support in this PR, or if it would be better to split it into a follow-up patch.

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


More information about the llvm-commits mailing list