[llvm] [polly] [AST] Don't merge memory locations in AliasSetTracker (PR #65731)
Bruno De Fraine via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 9 14:59:53 PST 2024
================
@@ -317,62 +262,67 @@ AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
}
AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
+ // The alias sets are indexed with a map from the memory locations' pointer
+ // values. If the memory location is already registered, we can find it in the
+ // alias set associated with its pointer.
+ AliasSet *&MapEntry = PointerMap[MemLoc.Ptr];
+ if (MapEntry) {
+ AliasSet *AS = MapEntry->getForwardedTarget(*this);
+ if (llvm::is_contained(AS->MemoryLocs, MemLoc)) {
+ if (AS != MapEntry) {
+ AS->addRef();
+ MapEntry->dropRef(*this);
+ MapEntry = AS;
+ }
+ return *AS;
+ }
+ }
- Value * const Pointer = const_cast<Value*>(MemLoc.Ptr);
- const LocationSize Size = MemLoc.Size;
- const AAMDNodes &AAInfo = MemLoc.AATags;
-
- AliasSet::PointerRec &Entry = getEntryFor(Pointer);
-
+ AliasSet *AS;
+ bool MustAliasAll = false;
if (AliasAnyAS) {
// At this point, the AST is saturated, so we only have one active alias
// set. That means we already know which alias set we want to return, and
// just need to add the pointer to that set to keep the data structure
// consistent.
// This, of course, means that we will never need a merge here.
- if (Entry.hasAliasSet()) {
- Entry.updateSizeAndAAInfo(Size, AAInfo);
- assert(Entry.getAliasSet(*this) == AliasAnyAS &&
- "Entry in saturated AST must belong to only alias set");
- } else {
- AliasAnyAS->addPointer(*this, Entry, Size, AAInfo);
- }
- return *AliasAnyAS;
+ AS = AliasAnyAS;
+ } else if (AliasSet *AliasAS =
+ mergeAliasSetsForPointer(MemLoc, MustAliasAll)) {
+ // Add it to the alias set it aliases.
+ AS = AliasAS;
+ } else if (MapEntry) {
+ // Although we have an independent memory location, forgo creating a new
+ // alias set to retain the implementation invariant that all memory
+ // locations with the same pointer value are in the same alias set.
+ // (This is only known to occur for undef pointer values, which AA treats as
+ // noalias.)
+ AS = MapEntry->getForwardedTarget(*this);
+ AS->Alias = AliasSet::SetMayAlias;
----------------
brunodf-snps wrote:
At this point, AA has indicated that the new memory location is no-alias with any set, including the set from the map entry. If that set was a must-alias set, it would seem that we have to downgrade to may-alias when adding the new memory location there to be consistent with the no-alias result?
I suppose your reasoning is that any two memory locations with the same pointer value are always must-alias (even if AA indicates they are also no-alias), so we know that the new memory location is also must-alias with the earlier memory location in the set for which map entry was added, and by transitivity with all memory locations in the set?
https://github.com/llvm/llvm-project/pull/65731
More information about the llvm-commits
mailing list