@@ -7493,7 +7493,7 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI,
74937493 SmallPtrSet<PHINode *, 8 > Phis;
74947494 SmallPtrSet<BasicBlock *, 8 > Seen;
74957495 DenseMap<PHINode *, SmallDenseMap<BasicBlock *, Value *, 8 >> PhiPredIVs;
7496- DenseMap<BasicBlock *, SmallVector<unsigned , 4 >> BBToSuccessorIndexes;
7496+ DenseMap<BasicBlock *, SmallVector<unsigned , 32 >> BBToSuccessorIndexes;
74977497 SmallVector<SwitchSuccWrapper> Cases;
74987498 Cases.reserve (SI->getNumSuccessors ());
74997499
@@ -7505,27 +7505,31 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI,
75057505 if (BB->size () != 1 )
75067506 continue ;
75077507
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-
75147508 // FIXME: Relax that the terminator is a BranchInst by checking for equality
75157509 // on other kinds of terminators. We decide to only support unconditional
75167510 // branches for now for compile time reasons.
75177511 auto *BI = dyn_cast<BranchInst>(BB->getTerminator ());
75187512 if (!BI || BI->isConditional ())
75197513 continue ;
75207514
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 ;
75277520 }
75287521
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});
75297533 BBToSuccessorIndexes[BB].emplace_back (I);
75307534 }
75317535
0 commit comments