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

via llvm-commits llvm-commits at lists.llvm.org
Tue May 20 00:40:44 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

With this patch, we always update Inserted.  That's OK because we only
read Inserted as shown in this patch.  Without this patch, it's a
write-only variable.


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


1 Files Affected:

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


``````````diff
diff --git a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
index ffb684d284a94..930b2068b3b0f 100644
--- a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
+++ b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
@@ -1306,12 +1306,11 @@ static void findCandidateStructures(
        CandIt != CandEndIt; CandIt++) {
 
     // Determine if it has an assigned structural group already.
-    CandToGroupIt = CandToGroup.find(&*CandIt);
-    if (CandToGroupIt == CandToGroup.end()) {
-      // If not, we assign it one, and add it to our mapping.
-      std::tie(CandToGroupIt, Inserted) =
-          CandToGroup.insert(std::make_pair(&*CandIt, CurrentGroupNum++));
-    }
+    // If not, we assign it one, and add it to our mapping.
+    std::tie(CandToGroupIt, Inserted) =
+        CandToGroup.try_emplace(&*CandIt, CurrentGroupNum);
+    if (Inserted)
+      ++CurrentGroupNum;
 
     // Get the structural group number from the iterator.
     OuterGroupNum = CandToGroupIt->second;

``````````

</details>


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


More information about the llvm-commits mailing list