[llvm] [IPO] Avoid repeated hash lookups (NFC) (PR #112821)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 20:25:26 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/112821
None
>From f32f70575b8c3e0826368300eeeed599e0c78173 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 17 Oct 2024 07:55:51 -0700
Subject: [PATCH] [IPO] Avoid repeated hash lookups (NFC)
---
llvm/lib/Transforms/IPO/GlobalDCE.cpp | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
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());
}
}
More information about the llvm-commits
mailing list