[llvm] [VPlan] Update scalar induction resume values in VPlan. (PR #110577)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 09:02:10 PST 2024


================
@@ -7987,14 +8010,31 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton(
       Phi->removeIncomingValue(EPI.MemSafetyCheck);
   }
 
-  // Generate a resume induction for the vector epilogue and put it in the
-  // vector epilogue preheader
+  // Try to re-use an existing resume phi if it matches the resume values for
+  // the canonical induction. Otherwise generate a resume phi for the canonical
+  // induction for the vector epilogue and put it in the vector epilogue
+  // preheader.
+  PHINode *EPResumeVal = nullptr;
   Type *IdxTy = Legal->getWidestInductionType();
-  PHINode *EPResumeVal = PHINode::Create(IdxTy, 2, "vec.epilog.resume.val");
-  EPResumeVal->insertBefore(LoopVectorPreHeader->getFirstNonPHIIt());
-  EPResumeVal->addIncoming(EPI.VectorTripCount, VecEpilogueIterationCountCheck);
-  EPResumeVal->addIncoming(ConstantInt::get(IdxTy, 0),
-                           EPI.MainLoopIterationCountCheck);
+  for (PHINode &P : LoopVectorPreHeader->phis()) {
----------------
ayalz wrote:

```suggestion
  auto *Init = ConstantInt::get(IdxTy, 0);
  auto *TC = EPI.VectorTripCount;
  for (PHINode &P : LoopVectorPreHeader->phis()) {
```

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


More information about the llvm-commits mailing list