[llvm] [VPlan] Retain exit conditions and edges in initial VPlan (NFC). (PR #137709)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 6 07:46:57 PDT 2025
================
@@ -447,19 +424,21 @@ static void createLoopRegion(VPlan &Plan, VPBlockBase *HeaderVPB) {
VPBlockBase *Succ = LatchVPBB->getSingleSuccessor();
assert(LatchVPBB->getNumSuccessors() <= 1 &&
"Latch has more than one successor");
- if (Succ)
- VPBlockUtils::disconnectBlocks(LatchVPBB, Succ);
+ LatchVPBB->removeSuccessor(Succ);
----------------
ayalz wrote:
The constructor of VPRegionBlock will assert that LatchVPBB is free of successors (and HeaderVPB free of predecessors), yet we want to retain LatchVPBB's place in Succ's predecessors - to be replaced by R, the region itself. One possible way to achieve this using current public API may by using an auxiliary temporary place holder VPBB:
```suggestion
auto *PlaceHolder = Plan.createVPBasicBlock ("Region place holder");
VPBlockUtils::insertOnEdge(LatchVPBB, Succ, PlaceHolder);
VPBlockUtils::disconnectBlocks(LatchVPBB, PlaceHolder);
VPBlockUtils::connectBlocks(PreheaderVPBB, PlaceHolder);
```
Note that disconnecting LatchVPBB from PlaceHolder and connecting PreheaderVPBB to PlaceHolder instead retains the position in PlaceHolder's predecessors, as PlaceHolder has but one predecessor (unlike Succ). Plus PreheaderVPBB has but one successor. More on this later.
It is also conceivable to have a(nother) constructor of VPRegionBlock which accepts a Header and Latch that are connected to a Preheader and Exit/Succ, respectively, and takes care of hooking them up with the newly created region block instead.
https://github.com/llvm/llvm-project/pull/137709
More information about the llvm-commits
mailing list