Skip to content

[LAA] Prefer set-contains over set-count (NFC) #136749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void RuntimePointerChecking::groupChecks(
for (unsigned I = 0; I < Pointers.size(); ++I) {
// We've seen this pointer before, and therefore already processed
// its equivalence class.
if (Seen.count(I))
if (Seen.contains(I))
continue;

MemoryDepChecker::MemAccessInfo Access(Pointers[I].PointerValue,
Expand Down Expand Up @@ -1212,7 +1212,7 @@ bool AccessAnalysis::canCheckPtrAtRT(
SmallVector<MemAccessInfo, 4> AccessInfos;
for (const Value *ConstPtr : ASPointers) {
Value *Ptr = const_cast<Value *>(ConstPtr);
bool IsWrite = Accesses.count(MemAccessInfo(Ptr, true));
bool IsWrite = Accesses.contains(MemAccessInfo(Ptr, true));
if (IsWrite)
++NumWritePtrChecks;
else
Expand Down Expand Up @@ -1341,9 +1341,10 @@ void AccessAnalysis::processMemAccesses() {
LLVM_DEBUG({
for (const auto &[A, _] : Accesses)
dbgs() << "\t" << *A.getPointer() << " ("
<< (A.getInt() ? "write"
: (ReadOnlyPtr.count(A.getPointer()) ? "read-only"
: "read"))
<< (A.getInt()
? "write"
: (ReadOnlyPtr.contains(A.getPointer()) ? "read-only"
: "read"))
<< ")\n";
});

Expand Down Expand Up @@ -1387,13 +1388,13 @@ void AccessAnalysis::processMemAccesses() {

// If we're using the deferred access set, then it contains only
// reads.
bool IsReadOnlyPtr = ReadOnlyPtr.count(Ptr) && !IsWrite;
bool IsReadOnlyPtr = ReadOnlyPtr.contains(Ptr) && !IsWrite;
if (UseDeferred && !IsReadOnlyPtr)
continue;
// Otherwise, the pointer must be in the PtrAccessSet, either as a
// read or a write.
assert(((IsReadOnlyPtr && UseDeferred) || IsWrite ||
S.count(MemAccessInfo(Ptr, false))) &&
S.contains(MemAccessInfo(Ptr, false))) &&
"Alias-set pointer not in the access set?");

MemAccessInfo Access(Ptr, IsWrite);
Expand Down Expand Up @@ -2260,7 +2261,7 @@ bool MemoryDepChecker::areDepsSafe(const DepCandidates &AccessSets,
MinDepDistBytes = -1;
SmallPtrSet<MemAccessInfo, 8> Visited;
for (MemAccessInfo CurAccess : CheckDeps) {
if (Visited.count(CurAccess))
if (Visited.contains(CurAccess))
continue;

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

// See if there is an unsafe dependency between a load to a uniform address and
// store to the same uniform address.
if (UniformStores.count(Ptr)) {
if (UniformStores.contains(Ptr)) {
LLVM_DEBUG(dbgs() << "LAA: Found an unsafe dependency between a uniform "
"load and uniform store to the same address!\n");
HasLoadStoreDependenceInvolvingLoopInvariantAddress = true;
Expand Down
Loading