[PATCH] D126679: [VPlan] Update vector latch terminator edge to exit block after execution.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 30 14:31:09 PDT 2022


fhahn created this revision.
fhahn added reviewers: Ayal, gilr, rengolin.
Herald added subscribers: tschuett, psnobl, rogfer01, bollu, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
Herald added a project: LLVM.

Instead of setting the successor to the exit using CFG.ExitBB, set it to
nullptr initially. The successor to the exit block is later set either
through createEmptyBasicBlock or after VPlan execution (because at the
moment, no block is created by VPlan for the exit block, the existing
one is reused).

This also enables BranchOnCond to be used as terminator for the exiting
block of the topmost vector region.

Depends on D126618 <https://reviews.llvm.org/D126618>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126679

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


Index: llvm/lib/Transforms/Vectorize/VPlan.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -274,8 +274,6 @@
       assert(this == LoopRegion->getSingleSuccessor() &&
              "the current block must be the single successor of the region");
       PredBBTerminator->setSuccessor(0, NewBB);
-      PredBBTerminator->setSuccessor(
-          1, CFG.VPBB2IRBB[LoopRegion->getEntryBasicBlock()]);
     }
   }
   return NewBB;
@@ -783,11 +781,13 @@
              "empty entry block only expected in VPlanNativePath");
       Header = cast<VPBasicBlock>(Header->getSingleSuccessor());
     }
-    // TODO: Once the exit block is modeled in VPlan, use it instead of going
-    // through State.CFG.ExitBB.
-    BasicBlock *Exit = State.CFG.ExitBB;
 
-    Builder.CreateCondBr(Cond, Exit, State.CFG.VPBB2IRBB[Header]);
+    // Replace the temporary unreachable terminator with a new conditional
+    // branch, hooking it up to backward destination now and to forward
+    // destination(s) later when they are created.
+    BranchInst *CondBr = Builder.CreateCondBr(Cond, Builder.GetInsertBlock(),
+                                              State.CFG.VPBB2IRBB[Header]);
+    CondBr->setSuccessor(0, nullptr);
     Builder.GetInsertBlock()->getTerminator()->eraseFromParent();
     break;
   }
@@ -943,13 +943,15 @@
   for (VPBlockBase *Block : depth_first(Entry))
     Block->execute(State);
 
-  VPRegionBlock *TopRegion= getVectorLoopRegion();
+  VPRegionBlock *TopRegion = getVectorLoopRegion();
   VPBasicBlock *LatchVPBB = TopRegion->getExitingBasicBlock();
 
   // Update terminator in the vector latch to branch to the exit block.
   BasicBlock *VectorLatchBB = State->CFG.VPBB2IRBB[LatchVPBB];
   auto *LatchTerminator = cast<BranchInst>(VectorLatchBB->getTerminator());
-  LatchTerminator->setSuccessor(0, State->CFG.VPBB2IRBB[TopRegion->getSingleSuccessor()->getEntryBasicBlock()]);
+  LatchTerminator->setSuccessor(
+      0, State->CFG
+             .VPBB2IRBB[TopRegion->getSingleSuccessor()->getEntryBasicBlock()]);
 
   // Fix the latch value of canonical, reduction and first-order recurrences
   // phis in the vector loop.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126679.432988.patch
Type: text/x-patch
Size: 2258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220530/962c5eb7/attachment.bin>


More information about the llvm-commits mailing list