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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/127743.diff


1 Files Affected:

- (modified) llvm/lib/Analysis/AssumeBundleQueries.cpp (+6-5) 


``````````diff
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);
   }
 }
 

``````````

</details>


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


More information about the llvm-commits mailing list