[llvm] f76375d - [SPIRV] Avoid repeated hash lookups (NFC) (#109517)

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 09:11:47 PDT 2024


Author: Kazu Hirata
Date: 2024-09-21T09:11:44-07:00
New Revision: f76375d9d47894de6665a662811471614b9c5b8b

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

LOG: [SPIRV] Avoid repeated hash lookups (NFC) (#109517)

Added: 
    

Modified: 
    llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 4175f766ac69ad..795ddf47c40dab 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -412,9 +412,8 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
     return KnownTy;
 
   // maybe a cycle
-  if (Visited.find(I) != Visited.end())
+  if (!Visited.insert(I).second)
     return nullptr;
-  Visited.insert(I);
 
   // fallback value in case when we fail to deduce a type
   Type *Ty = nullptr;
@@ -512,9 +511,8 @@ Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(
     return KnownTy;
 
   // maybe a cycle
-  if (Visited.find(U) != Visited.end())
+  if (!Visited.insert(U).second)
     return OrigTy;
-  Visited.insert(U);
 
   if (dyn_cast<StructType>(OrigTy)) {
     SmallVector<Type *> Tys;
@@ -1553,9 +1551,8 @@ Type *SPIRVEmitIntrinsics::deduceFunParamElementType(Function *F,
 Type *SPIRVEmitIntrinsics::deduceFunParamElementType(
     Function *F, unsigned OpIdx, std::unordered_set<Function *> &FVisited) {
   // maybe a cycle
-  if (FVisited.find(F) != FVisited.end())
+  if (!FVisited.insert(F).second)
     return nullptr;
-  FVisited.insert(F);
 
   std::unordered_set<Value *> Visited;
   SmallVector<std::pair<Function *, unsigned>> Lookup;


        


More information about the llvm-commits mailing list