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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 1 21:13:41 PST 2025


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

None

>From 9f266a70ff24d1b8015fb20b021444a664fa029e Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 1 Feb 2025 20:14:26 -0800
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)

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

diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp
index cfd247e7c3caf6..302dd37ff3d67b 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -1532,10 +1532,12 @@ void HoistSpillHelper::runHoistSpills(
     MachineBasicBlock *Block = (*RIt)->getBlock();
 
     // If Block contains an original spill, simply continue.
-    if (SpillsToKeep.contains(*RIt) && !SpillsToKeep[*RIt]) {
-      SpillsInSubTreeMap[*RIt].first.insert(*RIt);
-      // SpillsInSubTreeMap[*RIt].second contains the cost of spill.
-      SpillsInSubTreeMap[*RIt].second = MBFI.getBlockFreq(Block);
+    if (auto It = SpillsToKeep.find(*RIt);
+        It != SpillsToKeep.end() && !It->second) {
+      auto &SIt = SpillsInSubTreeMap[*RIt];
+      SIt.first.insert(*RIt);
+      // Sit.second contains the cost of spill.
+      SIt.second = MBFI.getBlockFreq(Block);
       continue;
     }
 



More information about the llvm-commits mailing list