Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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.

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.
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label May 20, 2025
@llvmbot
Copy link
Member

llvmbot commented May 20, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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;

@kazutakahirata kazutakahirata merged commit ba52b56 into llvm:main May 20, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_insert_std_make_pair_Analysis branch May 20, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants