@@ -122,6 +122,9 @@ VPBasicBlock *PlainCFGBuilder::getOrCreateVPBB(BasicBlock *BB) {
122
122
return VPBB;
123
123
}
124
124
125
+ if (!TheLoop->contains (BB))
126
+ return Plan.getExitBlock (BB);
127
+
125
128
// Create new VPBB.
126
129
StringRef Name = isHeaderBB (BB, TheLoop) ? " vector.body" : BB->getName ();
127
130
LLVM_DEBUG (dbgs () << " Creating VPBasicBlock for " << Name << " \n " );
@@ -155,14 +158,6 @@ bool PlainCFGBuilder::isExternalDef(Value *Val) {
155
158
// Instruction definition is in outermost loop PH.
156
159
return false ;
157
160
158
- // Check whether Instruction definition is in a loop exit.
159
- SmallVector<BasicBlock *> ExitBlocks;
160
- TheLoop->getExitBlocks (ExitBlocks);
161
- if (is_contained (ExitBlocks, InstParent)) {
162
- // Instruction definition is in outermost loop exit.
163
- return false ;
164
- }
165
-
166
161
// Check whether Instruction definition is in loop body.
167
162
return !TheLoop->contains (Inst);
168
163
}
@@ -211,11 +206,8 @@ void PlainCFGBuilder::createVPInstructionsForVPBB(VPBasicBlock *VPBB,
211
206
" Instruction shouldn't have been visited." );
212
207
213
208
if (auto *Br = dyn_cast<BranchInst>(Inst)) {
214
- if (TheLoop->getLoopLatch () == BB ||
215
- any_of (successors (BB),
216
- [this ](BasicBlock *Succ) { return !TheLoop->contains (Succ); }))
209
+ if (TheLoop->getLoopLatch () == BB)
217
210
continue ;
218
-
219
211
// Conditional branch instruction are represented using BranchOnCond
220
212
// recipes.
221
213
if (Br->isConditional ()) {
@@ -305,7 +297,6 @@ void PlainCFGBuilder::buildPlainCFG(
305
297
for (BasicBlock *BB : RPO) {
306
298
// Create or retrieve the VPBasicBlock for this BB.
307
299
VPBasicBlock *VPBB = getOrCreateVPBB (BB);
308
- Loop *LoopForBB = LI.getLoopFor (BB);
309
300
// Set VPBB predecessors in the same order as they are in the incoming BB.
310
301
setVPBBPredsFromBB (VPBB, BB);
311
302
@@ -339,24 +330,12 @@ void PlainCFGBuilder::buildPlainCFG(
339
330
BasicBlock *IRSucc1 = BI->getSuccessor (1 );
340
331
VPBasicBlock *Successor0 = getOrCreateVPBB (IRSucc0);
341
332
VPBasicBlock *Successor1 = getOrCreateVPBB (IRSucc1);
342
-
343
- // Don't connect any blocks outside the current loop except the latch, which
344
- // is handled below.
345
- if (LoopForBB &&
346
- (LoopForBB == TheLoop || BB != LoopForBB->getLoopLatch ())) {
347
- if (!LoopForBB->contains (IRSucc0)) {
348
- VPBB->setOneSuccessor (Successor1);
349
- continue ;
350
- }
351
- if (!LoopForBB->contains (IRSucc1)) {
352
- VPBB->setOneSuccessor (Successor0);
353
- continue ;
354
- }
355
- }
356
-
357
333
VPBB->setTwoSuccessors (Successor0, Successor1);
358
334
}
359
335
336
+ for (auto *EB : Plan.getExitBlocks ()) {
337
+ setVPBBPredsFromBB (EB, EB->getIRBasicBlock ());
338
+ }
360
339
// 2. The whole CFG has been built at this point so all the input Values must
361
340
// have a VPlan counterpart. Fix VPlan header phi by adding their
362
341
// corresponding VPlan operands.
@@ -413,10 +392,15 @@ static VPRegionBlock *introduceRegion(VPlan &Plan, VPBasicBlock *PreheaderVPBB,
413
392
auto *R = Plan.createVPRegionBlock (HeaderVPBB, LatchVPBB, " " ,
414
393
false /* isReplicator*/ );
415
394
R->setParent (HeaderVPBB->getParent ());
395
+
416
396
// All VPBB's reachable shallowly from HeaderVPBB belong to top level loop,
417
397
// because VPlan is expected to end at top level latch disconnected above.
418
- for (VPBlockBase *VPBB : vp_depth_first_shallow (HeaderVPBB))
419
- VPBB->setParent (R);
398
+ SmallPtrSet<VPBlockBase *, 2 > ExitBlocks (Plan.getExitBlocks ().begin (),
399
+ Plan.getExitBlocks ().end ());
400
+ for (VPBlockBase *VPBB : vp_depth_first_shallow (HeaderVPBB)) {
401
+ if (!ExitBlocks.contains (VPBB))
402
+ VPBB->setParent (R);
403
+ }
420
404
421
405
VPBlockUtils::insertBlockAfter (R, PreheaderVPBB);
422
406
if (Succ)
@@ -466,7 +450,11 @@ void VPlanTransforms::introduceRegions(VPlan &Plan, Type *InductionTy,
466
450
467
451
VPBasicBlock *ScalarPH = Plan.createVPBasicBlock (" scalar.ph" );
468
452
VPBlockUtils::connectBlocks (ScalarPH, Plan.getScalarHeader ());
453
+ BasicBlock *IRExitBlock = TheLoop->getUniqueLatchExitBlock ();
454
+ auto *VPExitBlock = IRExitBlock ? Plan.getExitBlock (IRExitBlock) : nullptr ;
469
455
if (!RequiresScalarEpilogueCheck) {
456
+ if (VPExitBlock)
457
+ VPBlockUtils::disconnectBlocks (MiddleVPBB, VPExitBlock);
470
458
VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
471
459
for (auto *EB : Plan.getExitBlocks ()) {
472
460
for (VPRecipeBase &R : *EB)
@@ -484,10 +472,7 @@ void VPlanTransforms::introduceRegions(VPlan &Plan, Type *InductionTy,
484
472
// 2) If we require a scalar epilogue, there is no conditional branch as
485
473
// we unconditionally branch to the scalar preheader. Do nothing.
486
474
// 3) Otherwise, construct a runtime check.
487
- BasicBlock *IRExitBlock = TheLoop->getUniqueLatchExitBlock ();
488
- auto *VPExitBlock = Plan.getExitBlock (IRExitBlock);
489
475
// The connection order corresponds to the operands of the conditional branch.
490
- VPBlockUtils::insertBlockAfter (VPExitBlock, MiddleVPBB);
491
476
VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
492
477
493
478
auto *ScalarLatchTerm = TheLoop->getLoopLatch ()->getTerminator ();
0 commit comments