Skip to content

Commit 213fdce

Browse files
artagnonGeorgeARM
authored andcommitted
[LAA] Prefer set-contains over set-count (NFC) (llvm#136749)
Improve code by preferring {SmallSet,SmallPtrSet}::contains() over the count() function, when used in a boolean context.
1 parent 5e9e875 commit 213fdce

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ void RuntimePointerChecking::groupChecks(
513513
for (unsigned I = 0; I < Pointers.size(); ++I) {
514514
// We've seen this pointer before, and therefore already processed
515515
// its equivalence class.
516-
if (Seen.count(I))
516+
if (Seen.contains(I))
517517
continue;
518518

519519
MemoryDepChecker::MemAccessInfo Access(Pointers[I].PointerValue,
@@ -1212,7 +1212,7 @@ bool AccessAnalysis::canCheckPtrAtRT(
12121212
SmallVector<MemAccessInfo, 4> AccessInfos;
12131213
for (const Value *ConstPtr : ASPointers) {
12141214
Value *Ptr = const_cast<Value *>(ConstPtr);
1215-
bool IsWrite = Accesses.count(MemAccessInfo(Ptr, true));
1215+
bool IsWrite = Accesses.contains(MemAccessInfo(Ptr, true));
12161216
if (IsWrite)
12171217
++NumWritePtrChecks;
12181218
else
@@ -1341,9 +1341,10 @@ void AccessAnalysis::processMemAccesses() {
13411341
LLVM_DEBUG({
13421342
for (const auto &[A, _] : Accesses)
13431343
dbgs() << "\t" << *A.getPointer() << " ("
1344-
<< (A.getInt() ? "write"
1345-
: (ReadOnlyPtr.count(A.getPointer()) ? "read-only"
1346-
: "read"))
1344+
<< (A.getInt()
1345+
? "write"
1346+
: (ReadOnlyPtr.contains(A.getPointer()) ? "read-only"
1347+
: "read"))
13471348
<< ")\n";
13481349
});
13491350

@@ -1387,13 +1388,13 @@ void AccessAnalysis::processMemAccesses() {
13871388

13881389
// If we're using the deferred access set, then it contains only
13891390
// reads.
1390-
bool IsReadOnlyPtr = ReadOnlyPtr.count(Ptr) && !IsWrite;
1391+
bool IsReadOnlyPtr = ReadOnlyPtr.contains(Ptr) && !IsWrite;
13911392
if (UseDeferred && !IsReadOnlyPtr)
13921393
continue;
13931394
// Otherwise, the pointer must be in the PtrAccessSet, either as a
13941395
// read or a write.
13951396
assert(((IsReadOnlyPtr && UseDeferred) || IsWrite ||
1396-
S.count(MemAccessInfo(Ptr, false))) &&
1397+
S.contains(MemAccessInfo(Ptr, false))) &&
13971398
"Alias-set pointer not in the access set?");
13981399

13991400
MemAccessInfo Access(Ptr, IsWrite);
@@ -2260,7 +2261,7 @@ bool MemoryDepChecker::areDepsSafe(const DepCandidates &AccessSets,
22602261
MinDepDistBytes = -1;
22612262
SmallPtrSet<MemAccessInfo, 8> Visited;
22622263
for (MemAccessInfo CurAccess : CheckDeps) {
2263-
if (Visited.count(CurAccess))
2264+
if (Visited.contains(CurAccess))
22642265
continue;
22652266

22662267
// Check accesses within this set.
@@ -2605,7 +2606,7 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
26052606

26062607
// See if there is an unsafe dependency between a load to a uniform address and
26072608
// store to the same uniform address.
2608-
if (UniformStores.count(Ptr)) {
2609+
if (UniformStores.contains(Ptr)) {
26092610
LLVM_DEBUG(dbgs() << "LAA: Found an unsafe dependency between a uniform "
26102611
"load and uniform store to the same address!\n");
26112612
HasLoadStoreDependenceInvolvingLoopInvariantAddress = true;

0 commit comments

Comments
 (0)