Skip to content

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

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 Mar 12, 2025

@llvm/pr-subscribers-llvm-regalloc

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/CodeGen/LiveRangeShrink.cpp (+5-5)
diff --git a/llvm/lib/CodeGen/LiveRangeShrink.cpp b/llvm/lib/CodeGen/LiveRangeShrink.cpp
index bb824566047e1..dae7e14e54aae 100644
--- a/llvm/lib/CodeGen/LiveRangeShrink.cpp
+++ b/llvm/lib/CodeGen/LiveRangeShrink.cpp
@@ -153,13 +153,13 @@ bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
           continue;
         if (MO.isUse())
           UseMap[MO.getReg()] = std::make_pair(CurrentOrder, &MI);
-        else if (MO.isDead() && UseMap.count(MO.getReg()))
+        else if (MO.isDead()) {
           // Barrier is the last instruction where MO get used. MI should not
           // be moved above Barrier.
-          if (Barrier < UseMap[MO.getReg()].first) {
-            Barrier = UseMap[MO.getReg()].first;
-            BarrierMI = UseMap[MO.getReg()].second;
-          }
+          auto It = UseMap.find(MO.getReg());
+          if (It != UseMap.end() && Barrier < It->second.first)
+            std::tie(Barrier, BarrierMI) = It->second;
+        }
       }
 
       if (!MI.isSafeToMove(SawStore)) {

@kazutakahirata kazutakahirata merged commit db3fdbc into llvm:main Mar 12, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_CodeGen branch March 12, 2025 15:47
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
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.

3 participants