[llvm] e8673f2 - [LV] Do not create separate latch block in VPlan::execute.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 30 09:31:56 PDT 2022
Author: Florian Hahn
Date: 2022-03-30T17:31:38+01:00
New Revision: e8673f2f20abc8d28822afdef75253334d17aa12
URL: https://github.com/llvm/llvm-project/commit/e8673f2f20abc8d28822afdef75253334d17aa12
DIFF: https://github.com/llvm/llvm-project/commit/e8673f2f20abc8d28822afdef75253334d17aa12.diff
LOG: [LV] Do not create separate latch block in VPlan::execute.
Now that all dependencies on creating the latch block up-front have been
removed, there is no need to create it early.
Depends on D121618.
Reviewed By: Ayal
Differential Revision: https://reviews.llvm.org/D121619
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index f7038e41bac26..58b214577012c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -252,7 +252,7 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
// Pred stands for Predessor. Prev stands for Previous - last visited/created.
BasicBlock *PrevBB = CFG.PrevBB;
BasicBlock *NewBB = BasicBlock::Create(PrevBB->getContext(), getName(),
- PrevBB->getParent(), CFG.LastBB);
+ PrevBB->getParent(), CFG.ExitBB);
LLVM_DEBUG(dbgs() << "LV: created " << NewBB->getName() << '\n');
// Hook up the new basic block to its predecessors.
@@ -319,7 +319,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
UnreachableInst *Terminator = State->Builder.CreateUnreachable();
State->Builder.SetInsertPoint(Terminator);
// Register NewBB in its loop. In innermost loops its the same for all BB's.
- Loop *L = State->LI->getLoopFor(State->CFG.LastBB);
+ Loop *L = State->LI->getLoopFor(State->CFG.PrevBB);
L->addBasicBlockToLoop(NewBB, *State->LI);
State->CFG.PrevBB = NewBB;
}
@@ -756,9 +756,8 @@ void VPInstruction::generateInstruction(VPTransformState &State,
Header = cast<VPBasicBlock>(Header->getSingleSuccessor());
}
// TODO: Once the exit block is modeled in VPlan, use it instead of going
- // through State.CFG.LastBB.
- BasicBlock *Exit =
- cast<BranchInst>(State.CFG.LastBB->getTerminator())->getSuccessor(0);
+ // through State.CFG.ExitBB.
+ BasicBlock *Exit = State.CFG.ExitBB;
Builder.CreateCondBr(Cond, Exit, State.CFG.VPBB2IRBB[Header]);
Builder.GetInsertBlock()->getTerminator()->eraseFromParent();
@@ -909,11 +908,9 @@ void VPlan::execute(VPTransformState *State) {
BasicBlock *VectorHeaderBB = VectorPreHeaderBB->getSingleSuccessor();
assert(VectorHeaderBB && "Loop preheader does not have a single successor.");
- // 1. Make room to generate basic-blocks inside loop body if needed.
- BasicBlock *VectorLatchBB = VectorHeaderBB->splitBasicBlock(
- VectorHeaderBB->getFirstInsertionPt(), "vector.body.latch");
Loop *L = State->LI->getLoopFor(VectorHeaderBB);
- L->addBasicBlockToLoop(VectorLatchBB, *State->LI);
+ State->CFG.ExitBB = L->getExitBlock();
+
// Remove the edge between Header and Latch to allow other connections.
// Temporarily terminate with unreachable until CFG is rewired.
// Note: this asserts the generated code's assumption that
@@ -923,10 +920,9 @@ void VPlan::execute(VPTransformState *State) {
UnreachableInst *Terminator = State->Builder.CreateUnreachable();
State->Builder.SetInsertPoint(Terminator);
- // 2. Generate code in loop body.
+ // Generate code in loop body.
State->CFG.PrevVPBB = nullptr;
State->CFG.PrevBB = VectorHeaderBB;
- State->CFG.LastBB = VectorLatchBB;
for (VPBlockBase *Block : depth_first(Entry))
Block->execute(State);
@@ -949,28 +945,7 @@ void VPlan::execute(VPTransformState *State) {
}
}
- // 3. Merge the temporary latch created with the last basic-block filled.
- BasicBlock *LastBB = State->CFG.PrevBB;
- assert(isa<BranchInst>(LastBB->getTerminator()) &&
- "Expected VPlan CFG to terminate with branch");
-
- // Move both the branch and check from LastBB to VectorLatchBB.
- auto *LastBranch = cast<BranchInst>(LastBB->getTerminator());
- LastBranch->moveBefore(VectorLatchBB->getTerminator());
- VectorLatchBB->getTerminator()->eraseFromParent();
- // Move condition so it is guaranteed to be next to branch. This is only done
- // to avoid excessive test updates.
- // TODO: Remove special handling once the increments for all inductions are
- // modeled explicitly in VPlan.
- cast<Instruction>(LastBranch->getCondition())->moveBefore(LastBranch);
- // Connect LastBB to VectorLatchBB to facilitate their merge.
- BranchInst::Create(VectorLatchBB, LastBB);
-
- // Merge LastBB with Latch.
- bool Merged = MergeBlockIntoPredecessor(VectorLatchBB, nullptr, State->LI);
- (void)Merged;
- assert(Merged && "Could not merge last basic block with latch.");
- VectorLatchBB = LastBB;
+ BasicBlock *VectorLatchBB = State->CFG.PrevBB;
// Fix the latch value of canonical, reduction and first-order recurrences
// phis in the vector loop.
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 24cb0a7f8d76b..02b0d09bfe91a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -307,9 +307,9 @@ struct VPTransformState {
/// header BasicBlock.
BasicBlock *PrevBB = nullptr;
- /// The last IR BasicBlock in the output IR. Set to the new latch
- /// BasicBlock, used for placing the newly created BasicBlocks.
- BasicBlock *LastBB = nullptr;
+ /// The last IR BasicBlock in the output IR. Set to the exit block of the
+ /// vector loop.
+ BasicBlock *ExitBB = nullptr;
/// The IR BasicBlock that is the preheader of the vector loop in the output
/// IR.
More information about the llvm-commits
mailing list