[llvm] [X86] Avoid repeated hash lookups (NFC) (PR #127579)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 17 22:57:17 PST 2025


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

None

>From 6dbbd5fb8b773e026bb3fab18523a03cf6024668 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 17 Feb 2025 02:09:02 -0800
Subject: [PATCH] [X86] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp b/llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp
index 31a93f9c2a6ef..c9e495c1eba1f 100644
--- a/llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp
+++ b/llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp
@@ -339,10 +339,10 @@ X86LoadValueInjectionLoadHardeningPass::getGadgetGraph(
   DenseMap<MachineInstr *, GraphIter> NodeMap;
   int FenceCount = 0, GadgetCount = 0;
   auto MaybeAddNode = [&NodeMap, &Builder](MachineInstr *MI) {
-    auto Ref = NodeMap.find(MI);
-    if (Ref == NodeMap.end()) {
+    auto [Ref, Inserted] = NodeMap.try_emplace(MI);
+    if (Inserted) {
       auto I = Builder.addVertex(MI);
-      NodeMap[MI] = I;
+      Ref->second = I;
       return std::pair<GraphIter, bool>{I, true};
     }
     return std::pair<GraphIter, bool>{Ref->getSecond(), false};



More information about the llvm-commits mailing list