@@ -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))
@@ -902,6 +905,9 @@ VPlanPtr VPlan::createInitialVPlan(Type *InductionTy,
902905 VPBlockUtils::insertBlockAfter (MiddleVPBB, TopRegion);
903906
904907 VPBasicBlock *ScalarPH = new VPBasicBlock (" scalar.ph" );
908+ VPBasicBlock *ScalarHeader =
909+ VPIRBasicBlock::fromBasicBlock (TheLoop->getHeader ());
910+ VPBlockUtils::connectBlocks (ScalarPH, ScalarHeader);
905911 if (!RequiresScalarEpilogueCheck) {
906912 VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
907913 return Plan;
@@ -1051,6 +1057,8 @@ void VPlan::execute(VPTransformState *State) {
10511057 BrInst->insertBefore (MiddleBB->getTerminator ());
10521058 MiddleBB->getTerminator ()->eraseFromParent ();
10531059 State->CFG .DTU .applyUpdates ({{DominatorTree::Delete, MiddleBB, ScalarPh}});
1060+ State->CFG .DTU .applyUpdates (
1061+ {{DominatorTree::Delete, ScalarPh, ScalarPh->getSingleSuccessor ()}});
10541062
10551063 // Generate code in the loop pre-header and body.
10561064 for (VPBlockBase *Block : vp_depth_first_shallow (Entry))
@@ -1169,12 +1177,6 @@ void VPlan::print(raw_ostream &O) const {
11691177 Block->print (O, " " , SlotTracker);
11701178 }
11711179
1172- if (!LiveOuts.empty ())
1173- O << " \n " ;
1174- for (const auto &KV : LiveOuts) {
1175- KV.second ->print (O, SlotTracker);
1176- }
1177-
11781180 O << " }\n " ;
11791181}
11801182
@@ -1211,11 +1213,6 @@ LLVM_DUMP_METHOD
12111213void VPlan::dump () const { print (dbgs ()); }
12121214#endif
12131215
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-
12191216static void remapOperands (VPBlockBase *Entry, VPBlockBase *NewEntry,
12201217 DenseMap<VPValue *, VPValue *> &Old2NewVPValues) {
12211218 // Update the operands of all cloned recipes starting at NewEntry. This
@@ -1283,10 +1280,6 @@ VPlan *VPlan::duplicate() {
12831280 remapOperands (Preheader, NewPreheader, Old2NewVPValues);
12841281 remapOperands (Entry, NewEntry, Old2NewVPValues);
12851282
1286- // Clone live-outs.
1287- for (const auto &[_, LO] : LiveOuts)
1288- NewPlan->addLiveOut (LO->getPhi (), Old2NewVPValues[LO->getOperand (0 )]);
1289-
12901283 // Initialize remaining fields of cloned VPlan.
12911284 NewPlan->VFs = VFs;
12921285 NewPlan->UFs = UFs;
0 commit comments