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()); } }