[llvm] [IR] Avoid repeated hash lookups (NFC) (PR #120848)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 21 10:16:50 PST 2024


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

None

>From 786b218229369529bb360b38e883661252e47020 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 21 Dec 2024 09:36:56 -0800
Subject: [PATCH] [IR] Avoid repeated hash lookups (NFC)

---
 llvm/include/llvm/IR/ModuleSummaryIndex.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 2a05c2ac0758c0..3c586a1dd21d82 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1711,10 +1711,9 @@ class ModuleSummaryIndex {
                        GlobalValue::GUID OrigGUID) {
     if (OrigGUID == 0 || ValueGUID == OrigGUID)
       return;
-    if (OidGuidMap.count(OrigGUID) && OidGuidMap[OrigGUID] != ValueGUID)
-      OidGuidMap[OrigGUID] = 0;
-    else
-      OidGuidMap[OrigGUID] = ValueGUID;
+    auto [It, Inserted] = OidGuidMap.try_emplace(OrigGUID, ValueGUID);
+    if (!Inserted && It->second != ValueGUID)
+      It->second = 0;
   }
 
   /// Find the summary for ValueInfo \p VI in module \p ModuleId, or nullptr if



More information about the llvm-commits mailing list