[llvm] [Utils] Avoid repeated hash lookups (NFC) (PR #127959)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 21:21:24 PST 2025


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

None

>From 3c5b41c1af5626456bf1d504ff42d1d24b35c41d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 19 Feb 2025 08:28:51 -0800
Subject: [PATCH] [Utils] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
index 2d9a3d1f8a110..78b9c7d06e183 100644
--- a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
+++ b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
@@ -178,11 +178,9 @@ struct AssumeBuilderState {
     if (tryToPreserveWithoutAddingAssume(RK))
       return;
     MapKey Key{RK.WasOn, RK.AttrKind};
-    auto Lookup = AssumedKnowledgeMap.find(Key);
-    if (Lookup == AssumedKnowledgeMap.end()) {
-      AssumedKnowledgeMap[Key] = RK.ArgValue;
+    auto [Lookup, Inserted] = AssumedKnowledgeMap.try_emplace(Key, RK.ArgValue);
+    if (Inserted)
       return;
-    }
     assert(((Lookup->second == 0 && RK.ArgValue == 0) ||
             (Lookup->second != 0 && RK.ArgValue != 0)) &&
            "inconsistent argument value");



More information about the llvm-commits mailing list