Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
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.
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
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.
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