@@ -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))
@@ -901,6 +904,8 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
901904 VPBlockUtils::insertBlockAfter (MiddleVPBB, TopRegion);
902905
903906 VPBasicBlock *ScalarPH = new VPBasicBlock (" scalar.ph" );
907+ VPBasicBlock *ScalarHeader = createVPIRBasicBlockFor (TheLoop->getHeader ());
908+ VPBlockUtils::connectBlocks (ScalarPH, ScalarHeader);
904909 if (!RequiresScalarEpilogueCheck) {
905910 VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
906911 return Plan;
@@ -1050,6 +1055,8 @@ void VPlan::execute(VPTransformState *State) {
10501055 BrInst->insertBefore (MiddleBB->getTerminator ());
10511056 MiddleBB->getTerminator ()->eraseFromParent ();
10521057 State->CFG .DTU .applyUpdates ({{DominatorTree::Delete, MiddleBB, ScalarPh}});
1058+ State->CFG .DTU .applyUpdates (
1059+ {{DominatorTree::Delete, ScalarPh, ScalarPh->getSingleSuccessor ()}});
10531060
10541061 // Generate code in the loop pre-header and body.
10551062 for (VPBlockBase *Block : vp_depth_first_shallow (Entry))
@@ -1168,12 +1175,6 @@ void VPlan::print(raw_ostream &O) const {
11681175 Block->print (O, " " , SlotTracker);
11691176 }
11701177
1171- if (!LiveOuts.empty ())
1172- O << " \n " ;
1173- for (const auto &KV : LiveOuts) {
1174- KV.second ->print (O, SlotTracker);
1175- }
1176-
11771178 O << " }\n " ;
11781179}
11791180
@@ -1210,11 +1211,6 @@ LLVM_DUMP_METHOD
12101211void VPlan::dump () const { print (dbgs ()); }
12111212#endif
12121213
1213- void VPlan::addLiveOut (PHINode *PN, VPValue *V) {
1214- assert (LiveOuts.count (PN) == 0 && " an exit value for PN already exists" );
1215- LiveOuts.insert ({PN, new VPLiveOut (PN, V)});
1216- }
1217-
12181214static void remapOperands (VPBlockBase *Entry, VPBlockBase *NewEntry,
12191215 DenseMap<VPValue *, VPValue *> &Old2NewVPValues) {
12201216 // Update the operands of all cloned recipes starting at NewEntry. This
@@ -1282,10 +1278,6 @@ VPlan *VPlan::duplicate() {
12821278 remapOperands (Preheader, NewPreheader, Old2NewVPValues);
12831279 remapOperands (Entry, NewEntry, Old2NewVPValues);
12841280
1285- // Clone live-outs.
1286- for (const auto &[_, LO] : LiveOuts)
1287- NewPlan->addLiveOut (LO->getPhi (), Old2NewVPValues[LO->getOperand (0 )]);
1288-
12891281 // Initialize remaining fields of cloned VPlan.
12901282 NewPlan->VFs = VFs;
12911283 NewPlan->UFs = UFs;
0 commit comments