[llvm] [Analysis] Avoid repeated hash lookups (NFC) (PR #123159)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 20:50:02 PST 2025


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

None

>From b533bd56bd5dd9ffc16093f766395e97444c068c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 15 Jan 2025 09:15:36 -0800
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Analysis/InstructionPrecedenceTracking.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp b/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp
index fba5859b74cef3..9555e2c8dd5dd7 100644
--- a/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp
+++ b/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp
@@ -115,8 +115,9 @@ void InstructionPrecedenceTracking::insertInstructionTo(const Instruction *Inst,
 void InstructionPrecedenceTracking::removeInstruction(const Instruction *Inst) {
   auto *BB = Inst->getParent();
   assert(BB && "must be called before instruction is actually removed");
-  if (FirstSpecialInsts.count(BB) && FirstSpecialInsts[BB] == Inst)
-    FirstSpecialInsts.erase(BB);
+  auto It = FirstSpecialInsts.find(BB);
+  if (It != FirstSpecialInsts.end() && It->second == Inst)
+    FirstSpecialInsts.erase(It);
 }
 
 void InstructionPrecedenceTracking::removeUsersOf(const Instruction *Inst) {



More information about the llvm-commits mailing list