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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 11 21:26:04 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/130889

None

>From e8876aa12249d69d104c5312b2f18ff461e1ffca Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 11 Mar 2025 09:03:15 -0700
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)

---
 llvm/lib/CodeGen/LiveRangeShrink.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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)) {



More information about the llvm-commits mailing list