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

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 21 21:05:46 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/132515.diff


1 Files Affected:

- (modified) llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp (+4-3) 


``````````diff
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);
 

``````````

</details>


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


More information about the llvm-commits mailing list