[llvm] [SPIRV] Avoid repeated hash lookups (NFC) (PR #109517)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 21 00:09:09 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/109517
None
>From 8bbd11db61c321ac070e269f8c25b60664fa83e6 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 21 Sep 2024 00:04:19 -0700
Subject: [PATCH] [SPIRV] Avoid repeated hash lookups (NFC)
---
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
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