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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 20 20:51:42 PDT 2025


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

None

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

---
 llvm/lib/CodeGen/StackColoring.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index 552dfdfe16ce4..0f93822d9792b 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -1178,8 +1178,11 @@ void StackColoring::expungeSlotMap(DenseMap<int, int> &SlotRemap,
     if (auto It = SlotRemap.find(i); It != SlotRemap.end()) {
       int Target = It->second;
       // As long as our target is mapped to something else, follow it.
-      while (SlotRemap.count(Target)) {
-        Target = SlotRemap[Target];
+      while (true) {
+        auto It = SlotRemap.find(Target);
+        if (It == SlotRemap.end())
+          break;
+        Target = It->second;
         SlotRemap[i] = Target;
       }
     }



More information about the llvm-commits mailing list