@@ -501,16 +501,15 @@ void VPBasicBlock::execute(VPTransformState *State) {
501501 UnreachableInst *Terminator = State->Builder .CreateUnreachable ();
502502 // Register NewBB in its loop. In innermost loops its the same for all
503503 // BB's.
504- if (this == State->Plan ->getEarlyExit ()) {
505- // If this is the vector early exit block then it has a single successor,
506- // which is the uncountable early exit block of the original loop. The
507- // parent loop for the exit block may not be the same as the parent loop
508- // of the vectorised loop, so we have to treat this differently.
509- Loop *EEL = State->LI ->getLoopFor (State->CFG .UncountableEarlyExitBB );
510- if (EEL)
511- EEL->addBasicBlockToLoop (NewBB, *State->LI );
512- } else if (State->CurrentParentLoop )
513- State->CurrentParentLoop ->addBasicBlockToLoop (NewBB, *State->LI );
504+ Loop *ParentLoop = State->CurrentParentLoop ;
505+ // If this block has a sole successor that is an exit block then it needs
506+ // adding to the same parent loop as the exit block.
507+ VPBlockBase *SuccVPBB = getSingleSuccessor ();
508+ if (SuccVPBB && State->Plan ->isExitBlock (SuccVPBB))
509+ ParentLoop = State->LI ->getLoopFor (
510+ cast<VPIRBasicBlock>(SuccVPBB)->getIRBasicBlock ());
511+ if (ParentLoop)
512+ ParentLoop->addBasicBlockToLoop (NewBB, *State->LI );
514513 State->Builder .SetInsertPoint (Terminator);
515514
516515 State->CFG .PrevBB = NewBB;
0 commit comments