Skip to content

Commit 9e9ebcd

Browse files
committed
getAliasSetFor: replace logic for undef values
Simply place them in the earlier alias set that was known for them, although this entails information loss.
1 parent 1ebddcd commit 9e9ebcd

File tree

2 files changed

+27
-64
lines changed

2 files changed

+27
-64
lines changed

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ class AliasSetTracker {
184184
// Map from pointers to their node
185185
PointerMapType PointerMap;
186186

187-
// Collection of alias sets that contain undef pointer values
188-
DenseSet<AliasSet *> UndefPointerSets;
189-
std::vector<AliasSet *> UndefPointerSetsVector;
190-
191187
public:
192188
/// Create an empty collection of AliasSets, and use the specified alias
193189
/// analysis object to disambiguate load and store addresses.

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ AliasSet::PointerVector AliasSet::getPointers() const {
228228

229229
void AliasSetTracker::clear() {
230230
PointerMap.clear();
231-
UndefPointerSets.clear();
232-
UndefPointerSetsVector.clear();
233231
AliasSets.clear();
234232
}
235233

@@ -285,47 +283,16 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
285283
// The alias sets are indexed with a map from the memory locations' pointer
286284
// values. If the memory location is already registered, we can find it in the
287285
// alias set associated with its pointer.
288-
//
289-
// The PointerMap structure requires that all memory locations for the same
290-
// value will be in the same alias set, which does not hold for undef values.
291-
// So we keep UndefValue pointers associated with the nullptr in the pointer
292-
// map, and instead keep a collection with the alias sets that contain memory
293-
// locations with undef pointer values.
294-
auto [It, Inserted] = PointerMap.insert({MemLoc.Ptr, nullptr});
295-
AliasSet *&MapEntry = It->second;
296-
if (!Inserted) {
297-
if (!isa<UndefValue>(MemLoc.Ptr)) {
298-
AliasSet *AS = MapEntry->getForwardedTarget(*this);
299-
if (llvm::find(AS->MemoryLocs, MemLoc) != AS->MemoryLocs.end()) {
300-
if (AS != MapEntry) {
301-
AS->addRef();
302-
MapEntry->dropRef(*this);
303-
MapEntry = AS;
304-
}
305-
return *AS;
286+
AliasSet *&MapEntry = PointerMap[MemLoc.Ptr];
287+
if (MapEntry) {
288+
AliasSet *AS = MapEntry->getForwardedTarget(*this);
289+
if (llvm::is_contained(AS->MemoryLocs, MemLoc)) {
290+
if (AS != MapEntry) {
291+
AS->addRef();
292+
MapEntry->dropRef(*this);
293+
MapEntry = AS;
306294
}
307-
} else {
308-
// Take opportunity to remove refs to forwarding alias sets from UndefPointerSets.
309-
llvm::erase_if(UndefPointerSetsVector, [this](AliasSet *&AS) {
310-
if (AS->Forward) {
311-
AliasSet *NewAS = AS->getForwardedTarget(*this);
312-
UndefPointerSets.erase(AS);
313-
AS->dropRef(*this);
314-
// Replace earlier entry in UndefPointerSetsVector with forwarded
315-
// target, but only if it is new.
316-
if (UndefPointerSets.insert(NewAS).second) {
317-
NewAS->addRef();
318-
AS = NewAS;
319-
return false;
320-
} else
321-
return true;
322-
}
323-
return false;
324-
});
325-
// Scan UndefPointerSets for MemLoc.
326-
for (AliasSet *AS : UndefPointerSetsVector)
327-
if (llvm::find(AS->MemoryLocs, MemLoc) != AS->MemoryLocs.end())
328-
return *AS;
295+
return *AS;
329296
}
330297
}
331298

@@ -342,6 +309,14 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
342309
mergeAliasSetsForPointer(MemLoc, MustAliasAll)) {
343310
// Add it to the alias set it aliases.
344311
AS = AliasAS;
312+
} else if (MapEntry) {
313+
// Although we have an independent memory location, forgo creating a new
314+
// alias set to retain the implementation invariant that all memory
315+
// locations with the same pointer value are in the same alias set.
316+
// (This is only known to occur for undef pointer values, which AA treats as
317+
// noalias.)
318+
AS = MapEntry->getForwardedTarget(*this);
319+
AS->Alias = AliasSet::SetMayAlias;
345320
} else {
346321
// Otherwise create a new alias set to hold the loaded pointer.
347322
AliasSets.push_back(AS = new AliasSet());
@@ -352,26 +327,18 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
352327
AS->addPointer(*this, MemLoc, MustAliasAll);
353328
// Register selected alias set in pointer map (or ensure it is consistent with
354329
// earlier map entry after taking into account new merging).
355-
if (!isa<UndefValue>(MemLoc.Ptr)) {
356-
if (MapEntry) {
357-
if (MapEntry->Forward) {
358-
AliasSet *NewAS = MapEntry->getForwardedTarget(*this);
359-
NewAS->addRef();
360-
MapEntry->dropRef(*this);
361-
MapEntry = NewAS;
362-
}
363-
assert(MapEntry == AS &&
364-
"Memory locations with same pointer value cannot "
365-
"be in different alias sets");
366-
} else {
367-
AS->addRef();
368-
MapEntry = AS;
330+
if (MapEntry) {
331+
if (MapEntry->Forward) {
332+
AliasSet *NewAS = MapEntry->getForwardedTarget(*this);
333+
NewAS->addRef();
334+
MapEntry->dropRef(*this);
335+
MapEntry = NewAS;
369336
}
337+
assert(MapEntry == AS && "Memory locations with same pointer value cannot "
338+
"be in different alias sets");
370339
} else {
371-
if (UndefPointerSets.insert(AS).second) {
372-
UndefPointerSetsVector.push_back(AS);
373-
AS->addRef();
374-
}
340+
AS->addRef();
341+
MapEntry = AS;
375342
}
376343
return *AS;
377344
}

0 commit comments

Comments
 (0)