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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 22:31:15 PST 2025


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

None

>From f3479c1feccc4b1d9bcf134c4062e79b222c41aa Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 22 Jan 2025 00:49:13 -0800
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)

---
 llvm/lib/CodeGen/MachineLoopUtils.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineLoopUtils.cpp b/llvm/lib/CodeGen/MachineLoopUtils.cpp
index 0e8335d4974d72..e869eed2ea1b16 100644
--- a/llvm/lib/CodeGen/MachineLoopUtils.cpp
+++ b/llvm/lib/CodeGen/MachineLoopUtils.cpp
@@ -76,8 +76,9 @@ MachineBasicBlock *llvm::PeelSingleBlockLoop(LoopPeelDirection Direction,
 
   for (auto I = NewBB->getFirstNonPHI(); I != NewBB->end(); ++I)
     for (MachineOperand &MO : I->uses())
-      if (MO.isReg() && Remaps.count(MO.getReg()))
-        MO.setReg(Remaps[MO.getReg()]);
+      if (MO.isReg())
+        if (auto It = Remaps.find(MO.getReg()); It != Remaps.end())
+          MO.setReg(It->second);
 
   for (auto I = NewBB->begin(); I->isPHI(); ++I) {
     MachineInstr &MI = *I;
@@ -90,8 +91,8 @@ MachineBasicBlock *llvm::PeelSingleBlockLoop(LoopPeelDirection Direction,
       // When peeling front, we are only left with the initial value from the
       // preheader.
       Register R = MI.getOperand(LoopRegIdx).getReg();
-      if (Remaps.count(R))
-        R = Remaps[R];
+      if (auto It = Remaps.find(R); It != Remaps.end())
+        R = It->second;
       OrigPhi.getOperand(InitRegIdx).setReg(R);
       MI.removeOperand(LoopRegIdx + 1);
       MI.removeOperand(LoopRegIdx + 0);



More information about the llvm-commits mailing list