[llvm] [SPIRV] Avoid repeated hash lookups (NFC) (PR #132515)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 21 21:05:12 PDT 2025


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

None

>From 59e3653b83c4b5b33f5dae31319d478f1c50cbcc Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 21 Mar 2025 08:36:55 -0700
Subject: [PATCH] [SPIRV] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
index 2632e0ad546ef..a956fad5487c1 100644
--- a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
@@ -197,7 +197,8 @@ void SPIRVRegularizer::visitCallScalToVec(CallInst *CI, StringRef MangledName,
 
   auto *OldF = CI->getCalledFunction();
   Function *NewF = nullptr;
-  if (!Old2NewFuncs.count(OldF)) {
+  auto [It, Inserted] = Old2NewFuncs.try_emplace(OldF);
+  if (Inserted) {
     AttributeList Attrs = CI->getCalledFunction()->getAttributes();
     SmallVector<Type *, 2> ArgTypes = {OldF->getArg(0)->getType(), Arg0Ty};
     auto *NewFTy =
@@ -215,9 +216,9 @@ void SPIRVRegularizer::visitCallScalToVec(CallInst *CI, StringRef MangledName,
     CloneFunctionInto(NewF, OldF, VMap,
                       CloneFunctionChangeType::LocalChangesOnly, Returns);
     NewF->setAttributes(Attrs);
-    Old2NewFuncs[OldF] = NewF;
+    It->second = NewF;
   } else {
-    NewF = Old2NewFuncs[OldF];
+    NewF = It->second;
   }
   assert(NewF);
 



More information about the llvm-commits mailing list