@@ -283,32 +283,34 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
283
283
LLVM_DEBUG (dbgs () << " LV: draw edge from" << PredBB->getName () << ' \n ' );
284
284
285
285
auto *TermBr = dyn_cast<BranchInst>(PredBBTerminator);
286
- if (isa<UnreachableInst>(PredBBTerminator) ||
287
- (TermBr && !TermBr->isConditional ())) {
286
+ if (isa<UnreachableInst>(PredBBTerminator)) {
288
287
assert (PredVPSuccessors.size () == 1 &&
289
288
" Predecessor ending w/o branch must have single successor." );
290
- if (TermBr) {
291
- TermBr->setSuccessor (0 , NewBB);
292
- } else {
293
- DebugLoc DL = PredBBTerminator->getDebugLoc ();
294
- PredBBTerminator->eraseFromParent ();
295
- auto *Br = BranchInst::Create (NewBB, PredBB);
296
- Br->setDebugLoc (DL);
297
- }
289
+ DebugLoc DL = PredBBTerminator->getDebugLoc ();
290
+ PredBBTerminator->eraseFromParent ();
291
+ auto *Br = BranchInst::Create (NewBB, PredBB);
292
+ Br->setDebugLoc (DL);
293
+ } else if (TermBr && !TermBr->isConditional ()) {
294
+ TermBr->setSuccessor (0 , NewBB);
295
+ } else if (PredVPSuccessors.size () == 2 ) {
296
+ unsigned idx = PredVPSuccessors.front () == this ? 0 : 1 ;
297
+ assert (!PredBBTerminator->getSuccessor (idx) &&
298
+ " Trying to reset an existing successor block." );
299
+ PredBBTerminator->setSuccessor (idx, NewBB);
298
300
} else {
299
- if (PredVPSuccessors. size () == 2 ) {
300
- unsigned idx = PredVPSuccessors. front () == this ? 0 : 1 ;
301
- assert (!PredBBTerminator-> getSuccessor (idx) &&
302
- " Trying to reset an existing successor block. " );
303
- PredBBTerminator-> setSuccessor (idx, NewBB );
304
- } else {
305
- auto *Reg = dyn_cast<VPRegionBlock>(PredVPBB-> getParent ());
306
- assert (Reg && !Reg-> isReplicator () );
307
- assert (this == Reg ->getSingleSuccessor ());
308
- PredBBTerminator-> setSuccessor ( 0 , NewBB );
309
- PredBBTerminator->setSuccessor (
310
- 1 , CFG. VPBB2IRBB [Reg-> getEntryBasicBlock ()]);
311
- }
301
+ // PredVPBB is the exit block of a loop region. Connect its successor
302
+ // outside the region.
303
+ auto *LoopRegion = cast<VPRegionBlock>(PredVPBB-> getParent ());
304
+ assert (!LoopRegion-> isReplicator () &&
305
+ " predecessor must be in a loop region " );
306
+ assert (PredVPSuccessors. empty () &&
307
+ LoopRegion-> getExitBasicBlock () == PredVPBB &&
308
+ " PredVPBB must be the exit block of its parent region " );
309
+ assert (this == LoopRegion ->getSingleSuccessor () &&
310
+ " the current block must be the single successor of the region " );
311
+ PredBBTerminator->setSuccessor (0 , NewBB);
312
+ PredBBTerminator-> setSuccessor (
313
+ 1 , CFG. VPBB2IRBB [LoopRegion-> getEntryBasicBlock ()]);
312
314
}
313
315
}
314
316
return NewBB;
@@ -320,7 +322,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
320
322
VPBlockBase *SingleHPred = nullptr ;
321
323
BasicBlock *NewBB = State->CFG .PrevBB ; // Reuse it if possible.
322
324
323
- auto IsNonReplicateR = [](VPBlockBase *BB) {
325
+ auto IsLoopRegion = [](VPBlockBase *BB) {
324
326
auto *R = dyn_cast<VPRegionBlock>(BB);
325
327
return R && !R->isReplicator ();
326
328
};
@@ -335,7 +337,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
335
337
SingleHPred->getExitBasicBlock () == PrevVPBB &&
336
338
PrevVPBB->getSingleHierarchicalSuccessor () &&
337
339
(SingleHPred->getParent () == getEnclosingLoopRegion () &&
338
- !IsNonReplicateR (SingleHPred))) && /* B */
340
+ !IsLoopRegion (SingleHPred))) && /* B */
339
341
!(Replica && getPredecessors ().empty ())) { /* C */
340
342
// The last IR basic block is reused, as an optimization, in three cases:
341
343
// A. the first VPBB reuses the loop pre-header BB - when PrevVPBB is null;
0 commit comments