Skip to content

Commit e66127e

Browse files
committed
[VPlan] Simplify & adjust code as suggested in D123005.
Improve code as suggested in D123005. Applied separately, because the comments where made a diff that has not been rebased to current main.
1 parent f8463da commit e66127e

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -283,32 +283,34 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
283283
LLVM_DEBUG(dbgs() << "LV: draw edge from" << PredBB->getName() << '\n');
284284

285285
auto *TermBr = dyn_cast<BranchInst>(PredBBTerminator);
286-
if (isa<UnreachableInst>(PredBBTerminator) ||
287-
(TermBr && !TermBr->isConditional())) {
286+
if (isa<UnreachableInst>(PredBBTerminator)) {
288287
assert(PredVPSuccessors.size() == 1 &&
289288
"Predecessor ending w/o branch must have single successor.");
290-
if (TermBr) {
291-
TermBr->setSuccessor(0, NewBB);
292-
} else {
293-
DebugLoc DL = PredBBTerminator->getDebugLoc();
294-
PredBBTerminator->eraseFromParent();
295-
auto *Br = BranchInst::Create(NewBB, PredBB);
296-
Br->setDebugLoc(DL);
297-
}
289+
DebugLoc DL = PredBBTerminator->getDebugLoc();
290+
PredBBTerminator->eraseFromParent();
291+
auto *Br = BranchInst::Create(NewBB, PredBB);
292+
Br->setDebugLoc(DL);
293+
} else if (TermBr && !TermBr->isConditional()) {
294+
TermBr->setSuccessor(0, NewBB);
295+
} else if (PredVPSuccessors.size() == 2) {
296+
unsigned idx = PredVPSuccessors.front() == this ? 0 : 1;
297+
assert(!PredBBTerminator->getSuccessor(idx) &&
298+
"Trying to reset an existing successor block.");
299+
PredBBTerminator->setSuccessor(idx, NewBB);
298300
} else {
299-
if (PredVPSuccessors.size() == 2) {
300-
unsigned idx = PredVPSuccessors.front() == this ? 0 : 1;
301-
assert(!PredBBTerminator->getSuccessor(idx) &&
302-
"Trying to reset an existing successor block.");
303-
PredBBTerminator->setSuccessor(idx, NewBB);
304-
} else {
305-
auto *Reg = dyn_cast<VPRegionBlock>(PredVPBB->getParent());
306-
assert(Reg && !Reg->isReplicator());
307-
assert(this == Reg->getSingleSuccessor());
308-
PredBBTerminator->setSuccessor(0, NewBB);
309-
PredBBTerminator->setSuccessor(
310-
1, CFG.VPBB2IRBB[Reg->getEntryBasicBlock()]);
311-
}
301+
// PredVPBB is the exit block of a loop region. Connect its successor
302+
// outside the region.
303+
auto *LoopRegion = cast<VPRegionBlock>(PredVPBB->getParent());
304+
assert(!LoopRegion->isReplicator() &&
305+
"predecessor must be in a loop region");
306+
assert(PredVPSuccessors.empty() &&
307+
LoopRegion->getExitBasicBlock() == PredVPBB &&
308+
"PredVPBB must be the exit block of its parent region");
309+
assert(this == LoopRegion->getSingleSuccessor() &&
310+
"the current block must be the single successor of the region");
311+
PredBBTerminator->setSuccessor(0, NewBB);
312+
PredBBTerminator->setSuccessor(
313+
1, CFG.VPBB2IRBB[LoopRegion->getEntryBasicBlock()]);
312314
}
313315
}
314316
return NewBB;
@@ -320,7 +322,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
320322
VPBlockBase *SingleHPred = nullptr;
321323
BasicBlock *NewBB = State->CFG.PrevBB; // Reuse it if possible.
322324

323-
auto IsNonReplicateR = [](VPBlockBase *BB) {
325+
auto IsLoopRegion = [](VPBlockBase *BB) {
324326
auto *R = dyn_cast<VPRegionBlock>(BB);
325327
return R && !R->isReplicator();
326328
};
@@ -335,7 +337,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
335337
SingleHPred->getExitBasicBlock() == PrevVPBB &&
336338
PrevVPBB->getSingleHierarchicalSuccessor() &&
337339
(SingleHPred->getParent() == getEnclosingLoopRegion() &&
338-
!IsNonReplicateR(SingleHPred))) && /* B */
340+
!IsLoopRegion(SingleHPred))) && /* B */
339341
!(Replica && getPredecessors().empty())) { /* C */
340342
// The last IR basic block is reused, as an optimization, in three cases:
341343
// A. the first VPBB reuses the loop pre-header BB - when PrevVPBB is null;

0 commit comments

Comments
 (0)