[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #127743)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 18 21:06:21 PST 2025


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

None

>From f5cb989e99ac93f704cdd0ec53c1252a87fb648c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 18 Feb 2025 08:43:56 -0800
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Analysis/AssumeBundleQueries.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Analysis/AssumeBundleQueries.cpp b/llvm/lib/Analysis/AssumeBundleQueries.cpp
index 21530693c5f18..c27bfa6f3cc2c 100644
--- a/llvm/lib/Analysis/AssumeBundleQueries.cpp
+++ b/llvm/lib/Analysis/AssumeBundleQueries.cpp
@@ -85,13 +85,14 @@ void llvm::fillMapFromAssume(AssumeInst &Assume, RetainedKnowledgeMap &Result) {
     if (!CI)
       continue;
     uint64_t Val = CI->getZExtValue();
-    auto Lookup = Result.find(Key);
-    if (Lookup == Result.end() || !Lookup->second.count(&Assume)) {
-      Result[Key][&Assume] = {Val, Val};
+    auto [It, Inserted] = Result[Key].try_emplace(&Assume);
+    if (Inserted) {
+      It->second = {Val, Val};
       continue;
     }
-    Lookup->second[&Assume].Min = std::min(Val, Lookup->second[&Assume].Min);
-    Lookup->second[&Assume].Max = std::max(Val, Lookup->second[&Assume].Max);
+    auto &MinMax = It->second;
+    MinMax.Min = std::min(Val, MinMax.Min);
+    MinMax.Max = std::max(Val, MinMax.Max);
   }
 }
 



More information about the llvm-commits mailing list