[PATCH] D111301: [VPlan] Set builder insert point instead of moving recipes. (NFC)

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 27 04:24:08 PDT 2021


fhahn updated this revision to Diff 382602.
fhahn added a comment.

Restore code to set insert point for phi-like recipes.

Relevant test is something like `trunc_with_first_order_recurrence` in 
test/Transforms/LoopVectorize/induction.ll


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111301/new/

https://reviews.llvm.org/D111301

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp


Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9454,16 +9454,21 @@
     if (!RecurPhi)
       continue;
 
+    VPRecipeBase *PrevRecipe = RecurPhi->getBackedgeRecipe();
+    if (auto *Region = GetReplicateRegion(PrevRecipe)) {
+      VPBasicBlock *Succ = cast<VPBasicBlock>(Region->getSingleSuccessor());
+      Builder.setInsertPoint(Succ, Succ->getFirstNonPhi());
+    } else if (PrevRecipe->isPhi())
+      Builder.setInsertPoint(PrevRecipe->getParent(),
+                             PrevRecipe->getParent()->getFirstNonPhi());
+    else
+      Builder.setInsertPoint(PrevRecipe->getParent(),
+                             std::next(PrevRecipe->getIterator()));
+
     auto *RecurSplice = cast<VPInstruction>(
         Builder.createNaryOp(VPInstruction::FirstOrderRecurrenceSplice,
                              {RecurPhi, RecurPhi->getBackedgeValue()}));
 
-    VPRecipeBase *PrevRecipe = RecurPhi->getBackedgeRecipe();
-    if (auto *Region = GetReplicateRegion(PrevRecipe)) {
-      VPBasicBlock *Succ = cast<VPBasicBlock>(Region->getSingleSuccessor());
-      RecurSplice->moveBefore(*Succ, Succ->getFirstNonPhi());
-    } else
-      RecurSplice->moveAfter(PrevRecipe);
     RecurPhi->replaceAllUsesWith(RecurSplice);
     // Set the first operand of RecurSplice to RecurPhi again, after replacing
     // all users.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111301.382602.patch
Type: text/x-patch
Size: 1511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211027/f0fdc206/attachment.bin>


More information about the llvm-commits mailing list