Skip to content

Commit 283a78a

Browse files
committed
Reapply "[LV] Don't add blocks to loop in GeneratedRTChecks (NFC)."
This reverts commit 46a2f41. Recommits 2fd6f8f with corresponding VPlan change to ensure LoopInfo is updated for all blocks during VPlan execution if needed.
1 parent 3e08dcd commit 283a78a

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,9 +2082,6 @@ class GeneratedRTChecks {
20822082

20832083
auto *Pred = LoopVectorPreHeader->getSinglePredecessor();
20842084
BranchInst::Create(LoopVectorPreHeader, SCEVCheckBlock);
2085-
// Create new preheader for vector loop.
2086-
if (OuterLoop)
2087-
OuterLoop->addBasicBlockToLoop(SCEVCheckBlock, *LI);
20882085

20892086
SCEVCheckBlock->getTerminator()->eraseFromParent();
20902087
SCEVCheckBlock->moveBefore(LoopVectorPreHeader);
@@ -2122,9 +2119,6 @@ class GeneratedRTChecks {
21222119
DT->changeImmediateDominator(LoopVectorPreHeader, MemCheckBlock);
21232120
MemCheckBlock->moveBefore(LoopVectorPreHeader);
21242121

2125-
if (OuterLoop)
2126-
OuterLoop->addBasicBlockToLoop(MemCheckBlock, *LI);
2127-
21282122
BranchInst &BI =
21292123
*BranchInst::Create(Bypass, LoopVectorPreHeader, MemRuntimeCheckCond);
21302124
if (AddBranchWeights) {

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,19 @@ BasicBlock *VPBasicBlock::createEmptyBasicBlock(VPTransformState &State) {
432432
void VPBasicBlock::connectToPredecessors(VPTransformState &State) {
433433
auto &CFG = State.CFG;
434434
BasicBlock *NewBB = CFG.VPBB2IRBB[this];
435+
436+
// Register NewBB in its loop. In innermost loops its the same for all
437+
// BB's.
438+
Loop *ParentLoop = State.CurrentParentLoop;
439+
// If this block has a sole successor that is an exit block then it needs
440+
// adding to the same parent loop as the exit block.
441+
VPBlockBase *SuccVPBB = getSingleSuccessor();
442+
if (SuccVPBB && State.Plan->isExitBlock(SuccVPBB))
443+
ParentLoop =
444+
State.LI->getLoopFor(cast<VPIRBasicBlock>(SuccVPBB)->getIRBasicBlock());
445+
if (ParentLoop && !State.LI->getLoopFor(NewBB))
446+
ParentLoop->addBasicBlockToLoop(NewBB, *State.LI);
447+
435448
// Hook up the new basic block to its predecessors.
436449
for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors()) {
437450
VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock();
@@ -517,17 +530,6 @@ void VPBasicBlock::execute(VPTransformState *State) {
517530
State->Builder.SetInsertPoint(NewBB);
518531
// Temporarily terminate with unreachable until CFG is rewired.
519532
UnreachableInst *Terminator = State->Builder.CreateUnreachable();
520-
// Register NewBB in its loop. In innermost loops its the same for all
521-
// BB's.
522-
Loop *ParentLoop = State->CurrentParentLoop;
523-
// If this block has a sole successor that is an exit block then it needs
524-
// adding to the same parent loop as the exit block.
525-
VPBlockBase *SuccVPBB = getSingleSuccessor();
526-
if (SuccVPBB && State->Plan->isExitBlock(SuccVPBB))
527-
ParentLoop = State->LI->getLoopFor(
528-
cast<VPIRBasicBlock>(SuccVPBB)->getIRBasicBlock());
529-
if (ParentLoop)
530-
ParentLoop->addBasicBlockToLoop(NewBB, *State->LI);
531533
State->Builder.SetInsertPoint(Terminator);
532534

533535
State->CFG.PrevBB = NewBB;

0 commit comments

Comments
 (0)