@@ -7493,7 +7493,7 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI,
7493
7493
SmallPtrSet<PHINode *, 8 > Phis;
7494
7494
SmallPtrSet<BasicBlock *, 8 > Seen;
7495
7495
DenseMap<PHINode *, SmallDenseMap<BasicBlock *, Value *, 8 >> PhiPredIVs;
7496
- DenseMap<BasicBlock *, SmallVector<unsigned , 4 >> BBToSuccessorIndexes;
7496
+ DenseMap<BasicBlock *, SmallVector<unsigned , 32 >> BBToSuccessorIndexes;
7497
7497
SmallVector<SwitchSuccWrapper> Cases;
7498
7498
Cases.reserve (SI->getNumSuccessors ());
7499
7499
@@ -7505,27 +7505,31 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI,
7505
7505
if (BB->size () != 1 )
7506
7506
continue ;
7507
7507
7508
- // FIXME: This case needs some extra care because the terminators other than
7509
- // SI need to be updated. For now, consider only backedges to the SI.
7510
- if (BB->hasNPredecessorsOrMore (4 ) ||
7511
- BB->getUniquePredecessor () != SI->getParent ())
7512
- continue ;
7513
-
7514
7508
// FIXME: Relax that the terminator is a BranchInst by checking for equality
7515
7509
// on other kinds of terminators. We decide to only support unconditional
7516
7510
// branches for now for compile time reasons.
7517
7511
auto *BI = dyn_cast<BranchInst>(BB->getTerminator ());
7518
7512
if (!BI || BI->isConditional ())
7519
7513
continue ;
7520
7514
7521
- if (Seen.insert (BB).second ) {
7522
- // Keep track of which PHIs we need as keys in PhiPredIVs below.
7523
- for (BasicBlock *Succ : BI->successors ())
7524
- Phis.insert_range (llvm::make_pointer_range (Succ->phis ()));
7525
- // Add the successor only if not previously visited.
7526
- Cases.emplace_back (SwitchSuccWrapper{BB, &PhiPredIVs});
7515
+ if (!Seen.insert (BB).second ) {
7516
+ auto It = BBToSuccessorIndexes.find (BB);
7517
+ if (It != BBToSuccessorIndexes.end ())
7518
+ It->second .emplace_back (I);
7519
+ continue ;
7527
7520
}
7528
7521
7522
+ // FIXME: This case needs some extra care because the terminators other than
7523
+ // SI need to be updated. For now, consider only backedges to the SI.
7524
+ if (BB->getUniquePredecessor () != SI->getParent ())
7525
+ continue ;
7526
+
7527
+ // Keep track of which PHIs we need as keys in PhiPredIVs below.
7528
+ for (BasicBlock *Succ : BI->successors ())
7529
+ Phis.insert_range (llvm::make_pointer_range (Succ->phis ()));
7530
+
7531
+ // Add the successor only if not previously visited.
7532
+ Cases.emplace_back (SwitchSuccWrapper{BB, &PhiPredIVs});
7529
7533
BBToSuccessorIndexes[BB].emplace_back (I);
7530
7534
}
7531
7535
0 commit comments