@@ -456,10 +456,17 @@ void VPIRBasicBlock::execute(VPTransformState *State) {
456456 State->Builder .SetInsertPoint (getIRBasicBlock ()->getTerminator ());
457457 executeRecipes (State, getIRBasicBlock ());
458458 if (getSingleSuccessor ()) {
459- assert (isa<UnreachableInst>(getIRBasicBlock ()->getTerminator ()));
460- auto *Br = State->Builder .CreateBr (getIRBasicBlock ());
461- Br->setOperand (0 , nullptr );
462- getIRBasicBlock ()->getTerminator ()->eraseFromParent ();
459+ auto *SuccVPIRBB = dyn_cast<VPIRBasicBlock>(getSingleSuccessor ());
460+ if (SuccVPIRBB && SuccVPIRBB->getIRBasicBlock () ==
461+ getIRBasicBlock ()->getSingleSuccessor ()) {
462+ cast<BranchInst>(getIRBasicBlock ()->getTerminator ())
463+ ->setOperand (0 , nullptr );
464+ } else {
465+ assert (isa<UnreachableInst>(getIRBasicBlock ()->getTerminator ()));
466+ auto *Br = State->Builder .CreateBr (getIRBasicBlock ());
467+ Br->setOperand (0 , nullptr );
468+ getIRBasicBlock ()->getTerminator ()->eraseFromParent ();
469+ }
463470 }
464471
465472 for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors ()) {
@@ -843,10 +850,6 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
843850#endif
844851
845852VPlan::~VPlan () {
846- for (auto &KV : LiveOuts)
847- delete KV.second ;
848- LiveOuts.clear ();
849-
850853 if (Entry) {
851854 VPValue DummyValue;
852855 for (VPBlockBase *Block : vp_depth_first_shallow (Entry))
@@ -909,6 +912,9 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
909912 VPBlockUtils::insertBlockAfter (MiddleVPBB, TopRegion);
910913
911914 VPBasicBlock *ScalarPH = new VPBasicBlock (" scalar.ph" );
915+ VPBasicBlock *ScalarHeader =
916+ VPIRBasicBlock::fromBasicBlock (TheLoop->getHeader ());
917+ VPBlockUtils::connectBlocks (ScalarPH, ScalarHeader);
912918 if (!RequiresScalarEpilogueCheck) {
913919 VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
914920 return Plan;
@@ -1058,6 +1064,8 @@ void VPlan::execute(VPTransformState *State) {
10581064 BrInst->insertBefore (MiddleBB->getTerminator ());
10591065 MiddleBB->getTerminator ()->eraseFromParent ();
10601066 State->CFG .DTU .applyUpdates ({{DominatorTree::Delete, MiddleBB, ScalarPh}});
1067+ State->CFG .DTU .applyUpdates (
1068+ {{DominatorTree::Delete, ScalarPh, ScalarPh->getSingleSuccessor ()}});
10611069
10621070 // Generate code in the loop pre-header and body.
10631071 for (VPBlockBase *Block : vp_depth_first_shallow (Entry))
@@ -1176,12 +1184,6 @@ void VPlan::print(raw_ostream &O) const {
11761184 Block->print (O, " " , SlotTracker);
11771185 }
11781186
1179- if (!LiveOuts.empty ())
1180- O << " \n " ;
1181- for (const auto &KV : LiveOuts) {
1182- KV.second ->print (O, SlotTracker);
1183- }
1184-
11851187 O << " }\n " ;
11861188}
11871189
@@ -1218,11 +1220,6 @@ LLVM_DUMP_METHOD
12181220void VPlan::dump () const { print (dbgs ()); }
12191221#endif
12201222
1221- void VPlan::addLiveOut (PHINode *PN, VPValue *V) {
1222- assert (LiveOuts.count (PN) == 0 && " an exit value for PN already exists" );
1223- LiveOuts.insert ({PN, new VPLiveOut (PN, V)});
1224- }
1225-
12261223static void remapOperands (VPBlockBase *Entry, VPBlockBase *NewEntry,
12271224 DenseMap<VPValue *, VPValue *> &Old2NewVPValues) {
12281225 // Update the operands of all cloned recipes starting at NewEntry. This
@@ -1290,10 +1287,6 @@ VPlan *VPlan::duplicate() {
12901287 remapOperands (Preheader, NewPreheader, Old2NewVPValues);
12911288 remapOperands (Entry, NewEntry, Old2NewVPValues);
12921289
1293- // Clone live-outs.
1294- for (const auto &[_, LO] : LiveOuts)
1295- NewPlan->addLiveOut (LO->getPhi (), Old2NewVPValues[LO->getOperand (0 )]);
1296-
12971290 // Initialize remaining fields of cloned VPlan.
12981291 NewPlan->VFs = VFs;
12991292 NewPlan->UFs = UFs;
0 commit comments