Skip to content

Commit 9f83914

Browse files
[IPO] Avoid repeated hash lookups (NFC) (#130389)
1 parent 474238b commit 9f83914

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llvm/lib/Transforms/IPO/GlobalDCE.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ void GlobalDCEPass::ComputeDependencies(Value *V,
6767
Deps.insert(GV);
6868
} else if (auto *CE = dyn_cast<Constant>(V)) {
6969
// Avoid walking the whole tree of a big ConstantExprs multiple times.
70-
auto Where = ConstantDependenciesCache.find(CE);
71-
if (Where != ConstantDependenciesCache.end()) {
72-
auto const &K = Where->second;
73-
Deps.insert(K.begin(), K.end());
74-
} else {
75-
SmallPtrSetImpl<GlobalValue *> &LocalDeps = ConstantDependenciesCache[CE];
70+
auto [Where, Inserted] = ConstantDependenciesCache.try_emplace(CE);
71+
SmallPtrSetImpl<GlobalValue *> &LocalDeps = Where->second;
72+
if (Inserted) {
7673
for (User *CEUser : CE->users())
7774
ComputeDependencies(CEUser, LocalDeps);
78-
Deps.insert(LocalDeps.begin(), LocalDeps.end());
7975
}
76+
Deps.insert(LocalDeps.begin(), LocalDeps.end());
8077
}
8178
}
8279

0 commit comments

Comments
 (0)