[llvm] [IPO] Avoid repeated hash lookups (NFC) (PR #112821)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 20:26:00 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/112821.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/IPO/GlobalDCE.cpp (+4-9) 


``````````diff
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
index eca36fb31cea0e..9a7447797e723a 100644
--- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
@@ -67,16 +67,11 @@ void GlobalDCEPass::ComputeDependencies(Value *V,
     Deps.insert(GV);
   } else if (auto *CE = dyn_cast<Constant>(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<GlobalValue *> &LocalDeps = ConstantDependenciesCache[CE];
+    auto [It, Inserted] = ConstantDependenciesCache.try_emplace(CE);
+    if (Inserted)
       for (User *CEUser : CE->users())
-        ComputeDependencies(CEUser, LocalDeps);
-      Deps.insert(LocalDeps.begin(), LocalDeps.end());
-    }
+        ComputeDependencies(CEUser, It->second);
+    Deps.insert(It->second.begin(), It->second.end());
   }
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/112821


More information about the llvm-commits mailing list