From 7a9718a5f6ad18e4bf3d5328ddeb9b8e56c25aef Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 7 Mar 2025 01:06:38 -0800 Subject: [PATCH] [IPO] Avoid repeated hash lookups (NFC) --- llvm/lib/Transforms/IPO/GlobalDCE.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp index eca36fb31cea0..250c0443cb4af 100644 --- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp +++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp @@ -67,16 +67,13 @@ void GlobalDCEPass::ComputeDependencies(Value *V, Deps.insert(GV); } else if (auto *CE = dyn_cast(V)) { // Avoid walking the whole tree of a big ConstantExprs multiple times. - auto Where = ConstantDependenciesCache.find(CE); - if (Where != ConstantDependenciesCache.end()) { - auto const &K = Where->second; - Deps.insert(K.begin(), K.end()); - } else { - SmallPtrSetImpl &LocalDeps = ConstantDependenciesCache[CE]; + auto [Where, Inserted] = ConstantDependenciesCache.try_emplace(CE); + SmallPtrSetImpl &LocalDeps = Where->second; + if (Inserted) { for (User *CEUser : CE->users()) ComputeDependencies(CEUser, LocalDeps); - Deps.insert(LocalDeps.begin(), LocalDeps.end()); } + Deps.insert(LocalDeps.begin(), LocalDeps.end()); } }