diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -274,8 +274,6 @@ assert(this == LoopRegion->getSingleSuccessor() && "the current block must be the single successor of the region"); PredBBTerminator->setSuccessor(0, NewBB); - PredBBTerminator->setSuccessor( - 1, CFG.VPBB2IRBB[LoopRegion->getEntryBasicBlock()]); } } return NewBB; @@ -783,11 +781,13 @@ "empty entry block only expected in VPlanNativePath"); Header = cast(Header->getSingleSuccessor()); } - // TODO: Once the exit block is modeled in VPlan, use it instead of going - // through State.CFG.ExitBB. - BasicBlock *Exit = State.CFG.ExitBB; - Builder.CreateCondBr(Cond, Exit, State.CFG.VPBB2IRBB[Header]); + // Replace the temporary unreachable terminator with a new conditional + // branch, hooking it up to backward destination now and to forward + // destination(s) later when they are created. + BranchInst *CondBr = Builder.CreateCondBr(Cond, Builder.GetInsertBlock(), + State.CFG.VPBB2IRBB[Header]); + CondBr->setSuccessor(0, nullptr); Builder.GetInsertBlock()->getTerminator()->eraseFromParent(); break; } @@ -943,13 +943,15 @@ for (VPBlockBase *Block : depth_first(Entry)) Block->execute(State); - VPRegionBlock *TopRegion= getVectorLoopRegion(); + VPRegionBlock *TopRegion = getVectorLoopRegion(); VPBasicBlock *LatchVPBB = TopRegion->getExitingBasicBlock(); // Update terminator in the vector latch to branch to the exit block. BasicBlock *VectorLatchBB = State->CFG.VPBB2IRBB[LatchVPBB]; auto *LatchTerminator = cast(VectorLatchBB->getTerminator()); - LatchTerminator->setSuccessor(0, State->CFG.VPBB2IRBB[TopRegion->getSingleSuccessor()->getEntryBasicBlock()]); + LatchTerminator->setSuccessor( + 0, State->CFG + .VPBB2IRBB[TopRegion->getSingleSuccessor()->getEntryBasicBlock()]); // Fix the latch value of canonical, reduction and first-order recurrences // phis in the vector loop.