[llvm] 6d8f14f - [Attributor][FIX] Ensure unknown accesses are honored

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 16:22:20 PDT 2023


Author: Johannes Doerfert
Date: 2023-06-13T16:21:56-07:00
New Revision: 6d8f14f001042bfc28f94ac976c4b6ad61c4c07a

URL: https://github.com/llvm/llvm-project/commit/6d8f14f001042bfc28f94ac976c4b6ad61c4c07a
DIFF: https://github.com/llvm/llvm-project/commit/6d8f14f001042bfc28f94ac976c4b6ad61c4c07a.diff

LOG: [Attributor][FIX] Ensure unknown accesses are honored

If we had an unknown access but already some prior knowledge (known), we
could have ended up ignoring the unknown access all together. The
problem is that we track unknown not as all locations but separately.
This patch bridges the gap and expands the unknown bits to "all bits"
when we add an access.

Fixes: https://github.com/llvm/llvm-project/issues/63291

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp
    llvm/test/Transforms/Attributor/memory_locations.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 2a7dcf883ea01..75ddda689dfeb 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -8747,6 +8747,8 @@ struct AAMemoryLocationImpl : public AAMemoryLocation {
     if (!Accesses)
       Accesses = new (Allocator) AccessSet();
     Changed |= Accesses->insert(AccessInfo{I, Ptr, AK}).second;
+    if (MLK == NO_UNKOWN_MEM)
+      MLK = NO_LOCATIONS;
     State.removeAssumedBits(MLK);
   }
 
@@ -8822,7 +8824,7 @@ void AAMemoryLocationImpl::categorizePtrValue(
     assert(MLK != NO_LOCATIONS && "No location specified!");
     LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Ptr value can be categorized: "
                       << Obj << " -> " << getMemoryLocationsAsStr(MLK) << "\n");
-    updateStateAndAccessesMap(getState(), MLK, &I, &Obj, Changed,
+    updateStateAndAccessesMap(State, MLK, &I, &Obj, Changed,
                               getAccessKindFromInst(&I));
 
     return true;

diff  --git a/llvm/test/Transforms/Attributor/memory_locations.ll b/llvm/test/Transforms/Attributor/memory_locations.ll
index 69054758ab97b..394f2ba3a116d 100644
--- a/llvm/test/Transforms/Attributor/memory_locations.ll
+++ b/llvm/test/Transforms/Attributor/memory_locations.ll
@@ -712,7 +712,7 @@ define void @argmemonky_caller() {
 declare ptr @no_mem_unknown_ptr(ptr %arg) memory(none)
 
 define void @argmem_and_unknown(i1 %c, ptr %arg) memory(argmem: readwrite) {
-; TUNIT: Function Attrs: nosync memory(none)
+; TUNIT: Function Attrs: nosync memory(argmem: write)
 ; TUNIT-LABEL: define {{[^@]+}}@argmem_and_unknown
 ; TUNIT-SAME: (i1 noundef [[C:%.*]], ptr writeonly [[ARG:%.*]]) #[[ATTR10:[0-9]+]] {
 ; TUNIT-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
@@ -723,7 +723,7 @@ define void @argmem_and_unknown(i1 %c, ptr %arg) memory(argmem: readwrite) {
 ; TUNIT:       f:
 ; TUNIT-NEXT:    ret void
 ;
-; CGSCC: Function Attrs: nosync memory(none)
+; CGSCC: Function Attrs: nosync memory(argmem: write)
 ; CGSCC-LABEL: define {{[^@]+}}@argmem_and_unknown
 ; CGSCC-SAME: (i1 noundef [[C:%.*]], ptr writeonly [[ARG:%.*]]) #[[ATTR11:[0-9]+]] {
 ; CGSCC-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
@@ -753,7 +753,7 @@ f:
 ; TUNIT: attributes #[[ATTR7]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
 ; TUNIT: attributes #[[ATTR8]] = { nofree nosync nounwind memory(argmem: write) }
 ; TUNIT: attributes #[[ATTR9]] = { nofree norecurse nosync nounwind memory(none) }
-; TUNIT: attributes #[[ATTR10]] = { nosync memory(none) }
+; TUNIT: attributes #[[ATTR10]] = { nosync memory(argmem: write) }
 ; TUNIT: attributes #[[ATTR11]] = { nofree nosync nounwind willreturn }
 ; TUNIT: attributes #[[ATTR12]] = { nofree nosync nounwind }
 ;.
@@ -768,7 +768,7 @@ f:
 ; CGSCC: attributes #[[ATTR8]] = { mustprogress nofree nosync nounwind willreturn memory(write) }
 ; CGSCC: attributes #[[ATTR9]] = { nofree nosync nounwind memory(argmem: write) }
 ; CGSCC: attributes #[[ATTR10]] = { nofree nosync nounwind memory(none) }
-; CGSCC: attributes #[[ATTR11]] = { nosync memory(none) }
+; CGSCC: attributes #[[ATTR11]] = { nosync memory(argmem: write) }
 ; CGSCC: attributes #[[ATTR12]] = { nounwind willreturn }
 ; CGSCC: attributes #[[ATTR13]] = { nofree nosync nounwind }
 ; CGSCC: attributes #[[ATTR14]] = { nounwind }


        


More information about the llvm-commits mailing list