[llvm] [polly] [AST] Don't merge memory locations in AliasSetTracker (PR #65731)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 01:53:20 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;
----------------
nikic wrote:

Yes, exactly. I doubt this really matters in practice, but I think keeping the MustAlias here should be safe (and very marginally simpler...)

https://github.com/llvm/llvm-project/pull/65731


More information about the llvm-commits mailing list