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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 18 22:20:00 PST 2025


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

None

>From a653e8b6801bc6342ce96539897fb0d71a02000a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 18 Jan 2025 10:05:44 -0800
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)

---
 llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
index 0ebe845e473fd63..edb85d212a4d480 100644
--- a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
+++ b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
@@ -190,7 +190,8 @@ class RegReloadCache {
   // Does basic block MBB contains reload of Reg from FI?
   bool hasReload(Register Reg, int FI, const MachineBasicBlock *MBB) {
     RegSlotPair RSP(Reg, FI);
-    return Reloads.count(MBB) && Reloads[MBB].count(RSP);
+    auto It = Reloads.find(MBB);
+    return It != Reloads.end() && It->second.count(RSP);
   }
 };
 
@@ -242,9 +243,10 @@ class FrameIndexesCache {
       It.second.Index = 0;
 
     ReservedSlots.clear();
-    if (EHPad && GlobalIndices.count(EHPad))
-      for (auto &RSP : GlobalIndices[EHPad])
-        ReservedSlots.insert(RSP.second);
+    if (EHPad)
+      if (auto It = GlobalIndices.find(EHPad); It != GlobalIndices.end())
+        for (auto &RSP : It->second)
+          ReservedSlots.insert(RSP.second);
   }
 
   // Get frame index to spill the register.



More information about the llvm-commits mailing list