Skip to content

Commit 0dbdc6d

Browse files
committed
[VPlan] Simplify code to re-use existing basic blocks (NFCI).
Restructure and slightly simplify code to re-use existing basic blocks.
1 parent c2ffb42 commit 0dbdc6d

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -478,32 +478,23 @@ void VPIRBasicBlock::execute(VPTransformState *State) {
478478

479479
void VPBasicBlock::execute(VPTransformState *State) {
480480
bool Replica = bool(State->Lane);
481-
VPBasicBlock *PrevVPBB = State->CFG.PrevVPBB;
482-
VPBlockBase *SingleHPred = nullptr;
483481
BasicBlock *NewBB = State->CFG.PrevBB; // Reuse it if possible.
484482

485-
auto IsLoopRegion = [](VPBlockBase *BB) {
486-
auto *R = dyn_cast<VPRegionBlock>(BB);
487-
return R && !R->isReplicator();
483+
auto IsReplicateRegion = [](VPBlockBase *BB) {
484+
auto *R = dyn_cast_or_null<VPRegionBlock>(BB);
485+
return R && R->isReplicator();
488486
};
489487

490488
// 1. Create an IR basic block.
491-
if (PrevVPBB && /* A */
492-
!((SingleHPred = getSingleHierarchicalPredecessor()) &&
493-
SingleHPred->getExitingBasicBlock() == PrevVPBB &&
494-
PrevVPBB->getSingleHierarchicalSuccessor() &&
495-
(SingleHPred->getParent() == getEnclosingLoopRegion() &&
496-
!IsLoopRegion(SingleHPred))) && /* B */
497-
!(Replica && getPredecessors().empty())) { /* C */
498-
// The last IR basic block is reused, as an optimization, in three cases:
499-
// A. the first VPBB reuses the loop pre-header BB - when PrevVPBB is null;
500-
// B. when the current VPBB has a single (hierarchical) predecessor which
501-
// is PrevVPBB and the latter has a single (hierarchical) successor which
502-
// both are in the same non-replicator region; and
503-
// C. when the current VPBB is an entry of a region replica - where PrevVPBB
504-
// is the exiting VPBB of this region from a previous instance, or the
505-
// predecessor of this region.
506-
489+
if (this == getPlan()->getVectorPreheader() ||
490+
(Replica && this == getParent()->getEntry()) ||
491+
IsReplicateRegion(getSingleHierarchicalPredecessor())) {
492+
// Reuse the previous basic block if the current VPBB is either
493+
// * the vector preheader,
494+
// * the entry to a replicate region, or
495+
// * the exit of a replicate region.
496+
State->CFG.VPBB2IRBB[this] = NewBB;
497+
} else {
507498
NewBB = createEmptyBasicBlock(State->CFG);
508499

509500
State->Builder.SetInsertPoint(NewBB);
@@ -518,8 +509,6 @@ void VPBasicBlock::execute(VPTransformState *State) {
518509
State->CFG.PrevBB = NewBB;
519510
State->CFG.VPBB2IRBB[this] = NewBB;
520511
connectToPredecessors(State->CFG);
521-
} else {
522-
State->CFG.VPBB2IRBB[this] = NewBB;
523512
}
524513

525514
// 2. Fill the IR basic block with IR instructions.

0 commit comments

Comments
 (0)