Skip to content

Commit f76375d

Browse files
[SPIRV] Avoid repeated hash lookups (NFC) (#109517)
1 parent 22486e0 commit f76375d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,8 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
412412
return KnownTy;
413413

414414
// maybe a cycle
415-
if (Visited.find(I) != Visited.end())
415+
if (!Visited.insert(I).second)
416416
return nullptr;
417-
Visited.insert(I);
418417

419418
// fallback value in case when we fail to deduce a type
420419
Type *Ty = nullptr;
@@ -512,9 +511,8 @@ Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(
512511
return KnownTy;
513512

514513
// maybe a cycle
515-
if (Visited.find(U) != Visited.end())
514+
if (!Visited.insert(U).second)
516515
return OrigTy;
517-
Visited.insert(U);
518516

519517
if (dyn_cast<StructType>(OrigTy)) {
520518
SmallVector<Type *> Tys;
@@ -1553,9 +1551,8 @@ Type *SPIRVEmitIntrinsics::deduceFunParamElementType(Function *F,
15531551
Type *SPIRVEmitIntrinsics::deduceFunParamElementType(
15541552
Function *F, unsigned OpIdx, std::unordered_set<Function *> &FVisited) {
15551553
// maybe a cycle
1556-
if (FVisited.find(F) != FVisited.end())
1554+
if (!FVisited.insert(F).second)
15571555
return nullptr;
1558-
FVisited.insert(F);
15591556

15601557
std::unordered_set<Value *> Visited;
15611558
SmallVector<std::pair<Function *, unsigned>> Lookup;

0 commit comments

Comments
 (0)