@@ -7451,7 +7451,7 @@ static bool simplifySwitchOfCmpIntrinsic(SwitchInst *SI, IRBuilderBase &Builder,
74517451struct CaseHandleWrapper {
74527452 const SwitchInst::CaseHandle Case;
74537453 DenseMap<PHINode *, DenseMap<BasicBlock *, Value *>> *PhiPredIVs;
7454- SmallVector<Value *> *PhiVals;
7454+ DenseMap<BasicBlock *, SmallVector<Value *> > *PhiVals;
74557455};
74567456
74577457namespace llvm {
@@ -7478,9 +7478,9 @@ template <> struct DenseMapInfo<const CaseHandleWrapper *> {
74787478 // Initially, we tried to just use the successor BB as the hash, but this
74797479 // has better performance.
74807480 BasicBlock *BB = BI->getSuccessor (0 );
7481- return hash_combine (
7482- hash_value (BB),
7483- hash_combine_range (CHW-> PhiVals -> begin (), CHW-> PhiVals -> end ()));
7481+ auto &Vals = (*CHW-> PhiVals )[BB];
7482+ return hash_combine ( hash_value (BB),
7483+ hash_combine_range (Vals. begin (), Vals. end ()));
74847484 }
74857485 static bool isEqual (const CaseHandleWrapper *LHS,
74867486 const CaseHandleWrapper *RHS) {
@@ -7557,14 +7557,16 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
75577557 if (!BI || BI->isConditional ())
75587558 continue ;
75597559
7560- if (Seen.insert (BB).second )
7560+ if (Seen.insert (BB).second ) {
75617561 // Keep track of which PHIs we need as keys in PhiPredIVs.
7562- for (BasicBlock *Succ : BI->successors ())
7563- for (PHINode &Phi : Succ->phis ())
7562+ for (BasicBlock *Succ : BI->successors ()) {
7563+ for (PHINode &Phi : Succ->phis ()) {
75647564 Phis.insert (&Phi);
7565-
7566- PhiVals[BB] = SmallVector<Value *>();
7567- Cases.emplace_back (CaseHandleWrapper{Case, &PhiPredIVs, &PhiVals[BB]});
7565+ PhiVals[BB] = SmallVector<Value *>();
7566+ }
7567+ }
7568+ }
7569+ Cases.emplace_back (CaseHandleWrapper{Case, &PhiPredIVs, &PhiVals});
75687570 }
75697571
75707572 // Precompute the data structures to improve performance of isEqual and
@@ -7578,8 +7580,9 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
75787580 PhiPredIVs[Phi].insert ({BB, IV.get ()});
75797581 // Only need to track PhiVals for BBs we've added as keys in the loop
75807582 // above.
7581- if (PhiVals.contains (BB))
7582- PhiVals[BB].emplace_back (IV.get ());
7583+ auto Res = PhiVals.find (BB);
7584+ if (Res != PhiVals.end ())
7585+ Res->second .emplace_back (IV.get ());
75837586 }
75847587 }
75857588
0 commit comments