[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);
auto *R = Plan.createVPRegionBlock(HeaderVPB, LatchVPBB, "",
false /*isReplicator*/);
// All VPBB's reachable shallowly from HeaderVPB belong to top level loop,
// because VPlan is expected to end at top level latch disconnected above.
+ SmallPtrSet<VPBlockBase *, 2> ExitBlocks(Plan.getExitBlocks().begin(),
+ Plan.getExitBlocks().end());
for (VPBlockBase *VPBB : vp_depth_first_shallow(HeaderVPB))
- VPBB->setParent(R);
+ if (!ExitBlocks.contains(VPBB))
+ VPBB->setParent(R);
VPBlockUtils::insertBlockAfter(R, PreheaderVPBB);
- if (Succ)
- VPBlockUtils::connectBlocks(R, Succ);
+ R->setOneSuccessor(Succ);
+ Succ->replacePredecessor(LatchVPBB, R);
----------------
ayalz wrote:
```suggestion
VPBlockUtils::insertOnEdge(PlaceHolder, Succ, R);
```
followed by either letting `mergeBlocksIntoPredecessors()` eliminate the empty PlaceHolder by merging it into PreheaderVPBB, or doing so explicitly here by adding:
```
VPBlockUtils::disconnectBlocks(PreheaderVPBB, PlaceHolder);
VPBlockUtils::disconnectBlocks(PlaceHolder, R);
VPBlockUtils::connectBlocks(PreheaderVPBB, R);
```
Note that doing
```
VPBlockUtils::insertOnEdge(PreheaderVPBB, RegionPlaceHolder, R);
```
instead will lose LatchVPBB's position in Succ's predecessors, suggesting that mergeBlocksIntoPredecessors() needs to be improved to retain this position (TODO). Should we have a `removeOnEdge()` which takes care of removing a Block on an edge from From to To, making sure From will appear as the predecessor of To in place of Block, and To will appear as the successor of From in place of Block? Analogous to `insertOnEdge()`, which utilizes connectBlocks(From, To, PredIx, SuccIdx), to ensure such positions are retained.
https://github.com/llvm/llvm-project/pull/137709
More information about the llvm-commits
mailing list