@@ -432,6 +432,19 @@ BasicBlock *VPBasicBlock::createEmptyBasicBlock(VPTransformState &State) {
432
432
void VPBasicBlock::connectToPredecessors (VPTransformState &State) {
433
433
auto &CFG = State.CFG ;
434
434
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
+
435
448
// Hook up the new basic block to its predecessors.
436
449
for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors ()) {
437
450
VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock ();
@@ -517,17 +530,6 @@ void VPBasicBlock::execute(VPTransformState *State) {
517
530
State->Builder .SetInsertPoint (NewBB);
518
531
// Temporarily terminate with unreachable until CFG is rewired.
519
532
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 );
531
533
State->Builder .SetInsertPoint (Terminator);
532
534
533
535
State->CFG .PrevBB = NewBB;
0 commit comments