@@ -178,7 +178,8 @@ VPBasicBlock *PlainCFGBuilder::getOrCreateVPBB(BasicBlock *BB) {
178178 VPBasicBlock *VPBB = Plan.createVPBasicBlock (Name);
179179 BB2VPBB[BB] = VPBB;
180180
181- // Get or create a region for the loop containing BB.
181+ // Get or create a region for the loop containing BB, except for the top
182+ // region of TheLoop which is created later.
182183 Loop *LoopOfBB = LI->getLoopFor (BB);
183184 if (!LoopOfBB || LoopOfBB == TheLoop || !doesContainLoop (LoopOfBB, TheLoop))
184185 return VPBB;
@@ -194,12 +195,8 @@ VPBasicBlock *PlainCFGBuilder::getOrCreateVPBB(BasicBlock *BB) {
194195 assert (!RegionOfVPBB &&
195196 " First visit of a header basic block expects to register its region." );
196197 // Handle a header - take care of its Region.
197- if (LoopOfBB == TheLoop) {
198- RegionOfVPBB = Plan.getVectorLoopRegion ();
199- } else {
200- RegionOfVPBB = Plan.createVPRegionBlock (Name.str (), false /* isReplicator*/ );
201- RegionOfVPBB->setParent (Loop2Region[LoopOfBB->getParentLoop ()]);
202- }
198+ RegionOfVPBB = Plan.createVPRegionBlock (Name.str (), false /* isReplicator*/ );
199+ RegionOfVPBB->setParent (Loop2Region[LoopOfBB->getParentLoop ()]);
203200 RegionOfVPBB->setEntry (VPBB);
204201 Loop2Region[LoopOfBB] = RegionOfVPBB;
205202 return VPBB;
@@ -383,11 +380,10 @@ void PlainCFGBuilder::buildPlainCFG(
383380 // Set VPBB predecessors in the same order as they are in the incoming BB.
384381 if (!isHeaderBB (BB, LoopForBB)) {
385382 setVPBBPredsFromBB (VPBB, BB);
386- } else {
387- // BB is a loop header, set the predecessor for the region, except for the
388- // top region, whose predecessor was set when creating VPlan's skeleton.
389- if (LoopForBB != TheLoop)
390- setRegionPredsFromBB (Region, BB);
383+ } else if (Region) {
384+ // BB is a loop header and there's a corresponding region , set the
385+ // predecessor for it.
386+ setRegionPredsFromBB (Region, BB);
391387 }
392388
393389 // Create VPInstructions for BB.
@@ -427,22 +423,15 @@ void PlainCFGBuilder::buildPlainCFG(
427423 VPBasicBlock *Successor0 = getOrCreateVPBB (IRSucc0);
428424 VPBasicBlock *Successor1 = getOrCreateVPBB (IRSucc1);
429425 if (BB == LoopForBB->getLoopLatch ()) {
430- // For a latch we need to set the successor of the region rather
431- // than that
432- // of VPBB and it should be set to the exit, i.e., non-header
433- // successor,
434- // except for the top region, whose successor was set when creating
435- // VPlan's skeleton.
426+ // For a latch we need to set the successor of the region rather than that
427+ // of VPBB and it should be set to the exit, i.e., non-header successor,
428+ // except for the top region, which is handled elsewhere.
436429 assert (LoopForBB != TheLoop &&
437430 " Latch of the top region should have been handled earlier" );
438431 Region->setOneSuccessor (isHeaderVPBB (Successor0) ? Successor1
439432 : Successor0);
440433 Region->setExiting (VPBB);
441434 continue ;
442-
443- VPBasicBlock *HeaderVPBB = getOrCreateVPBB (LoopForBB->getHeader ());
444- VPBlockUtils::connectBlocks (VPBB, HeaderVPBB);
445- continue ;
446435 }
447436
448437 // Don't connect any blocks outside the current loop except the latch for
0 commit comments