@@ -457,10 +457,17 @@ void VPIRBasicBlock::execute(VPTransformState *State) {
457457 State->Builder .SetInsertPoint (getIRBasicBlock ()->getTerminator ());
458458 executeRecipes (State, getIRBasicBlock ());
459459 if (getSingleSuccessor ()) {
460- assert (isa<UnreachableInst>(getIRBasicBlock ()->getTerminator ()));
461- auto *Br = State->Builder .CreateBr (getIRBasicBlock ());
462- Br->setOperand (0 , nullptr );
463- getIRBasicBlock ()->getTerminator ()->eraseFromParent ();
460+ auto *SuccVPIRBB = dyn_cast<VPIRBasicBlock>(getSingleSuccessor ());
461+ if (SuccVPIRBB && SuccVPIRBB->getIRBasicBlock () ==
462+ getIRBasicBlock ()->getSingleSuccessor ()) {
463+ cast<BranchInst>(getIRBasicBlock ()->getTerminator ())
464+ ->setOperand (0 , nullptr );
465+ } else {
466+ assert (isa<UnreachableInst>(getIRBasicBlock ()->getTerminator ()));
467+ auto *Br = State->Builder .CreateBr (getIRBasicBlock ());
468+ Br->setOperand (0 , nullptr );
469+ getIRBasicBlock ()->getTerminator ()->eraseFromParent ();
470+ }
464471 }
465472
466473 for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors ()) {
@@ -844,10 +851,6 @@ void VPRegionBlock::print(raw_ostream &O, const Twine &Indent,
844851#endif
845852
846853VPlan::~VPlan () {
847- for (auto &KV : LiveOuts)
848- delete KV.second ;
849- LiveOuts.clear ();
850-
851854 if (Entry) {
852855 VPValue DummyValue;
853856 for (VPBlockBase *Block : vp_depth_first_shallow (Entry))
@@ -902,6 +905,8 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
902905 VPBlockUtils::insertBlockAfter (MiddleVPBB, TopRegion);
903906
904907 VPBasicBlock *ScalarPH = new VPBasicBlock (" scalar.ph" );
908+ VPBasicBlock *ScalarHeader = createVPIRBasicBlockFor (TheLoop->getHeader ());
909+ VPBlockUtils::connectBlocks (ScalarPH, ScalarHeader);
905910 if (!RequiresScalarEpilogueCheck) {
906911 VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
907912 return Plan;
@@ -1051,6 +1056,8 @@ void VPlan::execute(VPTransformState *State) {
10511056 BrInst->insertBefore (MiddleBB->getTerminator ());
10521057 MiddleBB->getTerminator ()->eraseFromParent ();
10531058 State->CFG .DTU .applyUpdates ({{DominatorTree::Delete, MiddleBB, ScalarPh}});
1059+ State->CFG .DTU .applyUpdates (
1060+ {{DominatorTree::Delete, ScalarPh, ScalarPh->getSingleSuccessor ()}});
10541061
10551062 // Generate code in the loop pre-header and body.
10561063 for (VPBlockBase *Block : vp_depth_first_shallow (Entry))
@@ -1169,12 +1176,6 @@ void VPlan::print(raw_ostream &O) const {
11691176 Block->print (O, " " , SlotTracker);
11701177 }
11711178
1172- if (!LiveOuts.empty ())
1173- O << " \n " ;
1174- for (const auto &KV : LiveOuts) {
1175- KV.second ->print (O, SlotTracker);
1176- }
1177-
11781179 O << " }\n " ;
11791180}
11801181
@@ -1211,11 +1212,6 @@ LLVM_DUMP_METHOD
12111212void VPlan::dump () const { print (dbgs ()); }
12121213#endif
12131214
1214- void VPlan::addLiveOut (PHINode *PN, VPValue *V) {
1215- assert (LiveOuts.count (PN) == 0 && " an exit value for PN already exists" );
1216- LiveOuts.insert ({PN, new VPLiveOut (PN, V)});
1217- }
1218-
12191215static void remapOperands (VPBlockBase *Entry, VPBlockBase *NewEntry,
12201216 DenseMap<VPValue *, VPValue *> &Old2NewVPValues) {
12211217 // Update the operands of all cloned recipes starting at NewEntry. This
@@ -1283,10 +1279,6 @@ VPlan *VPlan::duplicate() {
12831279 remapOperands (Preheader, NewPreheader, Old2NewVPValues);
12841280 remapOperands (Entry, NewEntry, Old2NewVPValues);
12851281
1286- // Clone live-outs.
1287- for (const auto &[_, LO] : LiveOuts)
1288- NewPlan->addLiveOut (LO->getPhi (), Old2NewVPValues[LO->getOperand (0 )]);
1289-
12901282 // Initialize remaining fields of cloned VPlan.
12911283 NewPlan->VFs = VFs;
12921284 NewPlan->UFs = UFs;
0 commit comments