[llvm] 695a007 - [X86] Avoid repeated hash lookups (NFC) (#131725)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 18 07:55:38 PDT 2025


Author: Kazu Hirata
Date: 2025-03-18T07:55:35-07:00
New Revision: 695a007310c7552f74488c5b498470708661e705

URL: https://github.com/llvm/llvm-project/commit/695a007310c7552f74488c5b498470708661e705
DIFF: https://github.com/llvm/llvm-project/commit/695a007310c7552f74488c5b498470708661e705.diff

LOG: [X86] Avoid repeated hash lookups (NFC) (#131725)

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86PadShortFunction.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86PadShortFunction.cpp b/llvm/lib/Target/X86/X86PadShortFunction.cpp
index 2859195c6c26e..e4cc4fdcb3ab0 100644
--- a/llvm/lib/Target/X86/X86PadShortFunction.cpp
+++ b/llvm/lib/Target/X86/X86PadShortFunction.cpp
@@ -181,10 +181,9 @@ void PadShortFunc::findReturns(MachineBasicBlock *MBB, unsigned int Cycles) {
 bool PadShortFunc::cyclesUntilReturn(MachineBasicBlock *MBB,
                                      unsigned int &Cycles) {
   // Return cached result if BB was previously visited
-  DenseMap<MachineBasicBlock*, VisitedBBInfo>::iterator it
-    = VisitedBBs.find(MBB);
-  if (it != VisitedBBs.end()) {
-    VisitedBBInfo BBInfo = it->second;
+  auto [It, Inserted] = VisitedBBs.try_emplace(MBB);
+  if (!Inserted) {
+    VisitedBBInfo BBInfo = It->second;
     Cycles += BBInfo.Cycles;
     return BBInfo.HasReturn;
   }
@@ -196,7 +195,7 @@ bool PadShortFunc::cyclesUntilReturn(MachineBasicBlock *MBB,
     // functions do not count because the called function will be padded,
     // if necessary.
     if (MI.isReturn() && !MI.isCall()) {
-      VisitedBBs[MBB] = VisitedBBInfo(true, CyclesToEnd);
+      It->second = VisitedBBInfo(true, CyclesToEnd);
       Cycles += CyclesToEnd;
       return true;
     }
@@ -204,7 +203,7 @@ bool PadShortFunc::cyclesUntilReturn(MachineBasicBlock *MBB,
     CyclesToEnd += TSM.computeInstrLatency(&MI);
   }
 
-  VisitedBBs[MBB] = VisitedBBInfo(false, CyclesToEnd);
+  It->second = VisitedBBInfo(false, CyclesToEnd);
   Cycles += CyclesToEnd;
   return false;
 }


        


More information about the llvm-commits mailing list