Skip to content

[CodeGen] Avoid repeated hash lookups (NFC) #123557

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

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jan 20, 2025

@llvm/pr-subscribers-llvm-regalloc

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/CodeGen/MachineCopyPropagation.cpp (+4-4)
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 0afd73d8ecdccb..d44b064dcb4b2e 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -127,11 +127,11 @@ class CopyTracker {
   BitVector &getPreservedRegUnits(const MachineOperand &RegMaskOp,
                                   const TargetRegisterInfo &TRI) {
     const uint32_t *RegMask = RegMaskOp.getRegMask();
-    auto Existing = RegMaskToPreservedRegUnits.find(RegMask);
-    if (Existing != RegMaskToPreservedRegUnits.end()) {
-      return Existing->second;
+    auto [It, Inserted] = RegMaskToPreservedRegUnits.try_emplace(RegMask);
+    if (!Inserted) {
+      return It->second;
     } else {
-      BitVector &PreservedRegUnits = RegMaskToPreservedRegUnits[RegMask];
+      BitVector &PreservedRegUnits = It->second;
 
       PreservedRegUnits.resize(TRI.getNumRegUnits());
       for (unsigned SafeReg = 0, E = TRI.getNumRegs(); SafeReg < E; ++SafeReg)

@kazutakahirata kazutakahirata merged commit bc1e699 into llvm:main Jan 20, 2025
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_CodeGen branch January 20, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants