[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
Thu Jun 2 04:51:17 PDT 2022
fhahn updated this revision to Diff 433716.
fhahn marked 6 inline comments as done.
fhahn added a comment.
Address latest comments, thanks!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126679/new/
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
@@ -240,7 +240,7 @@
// Hook up the new basic block to its predecessors.
for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors()) {
VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock();
- auto &PredVPSuccessors = PredVPBB->getSuccessors();
+ auto &PredVPSuccessors = PredVPBB->getHierarchicalSuccessors();
BasicBlock *PredBB = CFG.VPBB2IRBB[PredVPBB];
assert(PredBB && "Predecessor basic-block not found building successor.");
@@ -257,25 +257,11 @@
Br->setDebugLoc(DL);
} else if (TermBr && !TermBr->isConditional()) {
TermBr->setSuccessor(0, NewBB);
- } else if (PredVPSuccessors.size() == 2) {
+ } else {
unsigned idx = PredVPSuccessors.front() == this ? 0 : 1;
assert(!PredBBTerminator->getSuccessor(idx) &&
"Trying to reset an existing successor block.");
PredBBTerminator->setSuccessor(idx, NewBB);
- } else {
- // PredVPBB is the exiting block of a loop region. Connect its successor
- // outside the region.
- auto *LoopRegion = cast<VPRegionBlock>(PredVPBB->getParent());
- assert(!LoopRegion->isReplicator() &&
- "predecessor must be in a loop region");
- assert(PredVPSuccessors.empty() &&
- LoopRegion->getExitingBasicBlock() == PredVPBB &&
- "PredVPBB must be the exiting block of its parent region");
- 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;
@@ -297,6 +283,14 @@
// ExitBB can be re-used for the exit block of the Plan.
NewBB = State->CFG.ExitBB;
State->CFG.PrevBB = NewBB;
+
+ // Update the branch instruction in the predecessor to branch to ExitBB.
+ VPBlockBase *PredVPB = getSingleHierarchicalPredecessor();
+ VPBasicBlock *ExitingVPBB = PredVPB->getExitingBasicBlock();
+ assert(PredVPB->getSingleSuccessor() == this &&
+ "predecessor must have the current block as only successor");
+ BasicBlock *ExitingBB = State->CFG.VPBB2IRBB[ExitingVPBB];
+ cast<BranchInst>(ExitingBB->getTerminator())->setSuccessor(0, NewBB);
} else if (PrevVPBB && /* A */
!((SingleHPred = getSingleHierarchicalPredecessor()) &&
SingleHPred->getExitingBasicBlock() == PrevVPBB &&
@@ -796,11 +790,13 @@
auto *Plan = getParent()->getPlan();
VPRegionBlock *TopRegion = Plan->getVectorLoopRegion();
VPBasicBlock *Header = TopRegion->getEntry()->getEntryBasicBlock();
- // 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 (the header) now and to the
+ // forward destination (the exit/middle block) later when it is created.
+ BranchInst *CondBr = Builder.CreateCondBr(Cond, Builder.GetInsertBlock(),
+ State.CFG.VPBB2IRBB[Header]);
+ CondBr->setSuccessor(0, nullptr);
Builder.GetInsertBlock()->getTerminator()->eraseFromParent();
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126679.433716.patch
Type: text/x-patch
Size: 3633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220602/7af4fffd/attachment.bin>
More information about the llvm-commits
mailing list