[llvm] [CodeGen] Avoid repeated hash lookups (NFC) (PR #132513)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 21 20:56:31 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/132513

None

>From 3859b1a50f57114db8b5dbe44676ef2e77c48f07 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 21 Mar 2025 08:32:08 -0700
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)

---
 llvm/lib/CodeGen/GCMetadata.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/GCMetadata.cpp b/llvm/lib/CodeGen/GCMetadata.cpp
index f33008c9e0f23..fa87b14e708e1 100644
--- a/llvm/lib/CodeGen/GCMetadata.cpp
+++ b/llvm/lib/CodeGen/GCMetadata.cpp
@@ -41,8 +41,10 @@ CollectorMetadataAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
   for (auto &F : M) {
     if (F.isDeclaration() || !F.hasGC())
       continue;
-    if (auto GCName = F.getGC(); !Map.contains(GCName))
-      Map[GCName] = getGCStrategy(GCName);
+    auto GCName = F.getGC();
+    auto [It, Inserted] = Map.try_emplace(GCName);
+    if (Inserted)
+      It->second = getGCStrategy(GCName);
   }
   return R;
 }



More information about the llvm-commits mailing list