Skip to content

Commit 1b42be6

Browse files
[Utils] Avoid repeated hash lookups (NFC) (#131267)
It's safe to use try_emplace instead of operator[] here because: - PhiPredIVs is empty at the beginning of the loop, and - The elements we are inserting into PhiPredIVs are unique.
1 parent 8d333e1 commit 1b42be6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7555,10 +7555,10 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI,
75557555
// SwitchSuccWrapper.
75567556
PhiPredIVs.reserve(Phis.size());
75577557
for (PHINode *Phi : Phis) {
7558-
PhiPredIVs[Phi] =
7559-
SmallDenseMap<BasicBlock *, Value *, 8>(Phi->getNumIncomingValues());
7558+
auto &IVs =
7559+
PhiPredIVs.try_emplace(Phi, Phi->getNumIncomingValues()).first->second;
75607560
for (auto &IV : Phi->incoming_values())
7561-
PhiPredIVs[Phi].insert({Phi->getIncomingBlock(IV), IV.get()});
7561+
IVs.insert({Phi->getIncomingBlock(IV), IV.get()});
75627562
}
75637563

75647564
// Build a set such that if the SwitchSuccWrapper exists in the set and

0 commit comments

Comments
 (0)