[llvm] 8b4e128 - [Attributor][FIX] Consistently use the access/remote instruction

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 15:21:50 PST 2023


Author: Johannes Doerfert
Date: 2023-01-12T15:21:34-08:00
New Revision: 8b4e1287acfb3c31c235bc2d1d0da1547e168afb

URL: https://github.com/llvm/llvm-project/commit/8b4e1287acfb3c31c235bc2d1d0da1547e168afb
DIFF: https://github.com/llvm/llvm-project/commit/8b4e1287acfb3c31c235bc2d1d0da1547e168afb.diff

LOG: [Attributor][FIX] Consistently use the access/remote instruction

We use the actual access (=remote) instruction when reasoning about
accesses, except for one leftover use case of the local instruction.
This caused us to potentially ignore the dominating write if the read
and write were in a different function than the (stack) allocation.

Reported by @ye-luo

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp
    llvm/test/Transforms/Attributor/value-simplify-dominance.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 6fc47c73d60f..5830426c2073 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1228,7 +1228,7 @@ struct AAPointerInfoImpl
         return false;
       if (!DominatingWrites.count(&Acc))
         return false;
-      return LeastDominatingWriteInst != Acc.getLocalInst();
+      return LeastDominatingWriteInst != Acc.getRemoteInst();
     };
 
     // Run the user callback on all accesses we cannot skip and return if

diff  --git a/llvm/test/Transforms/Attributor/value-simplify-dominance.ll b/llvm/test/Transforms/Attributor/value-simplify-dominance.ll
index 64756306f512..438dace4d2f2 100644
--- a/llvm/test/Transforms/Attributor/value-simplify-dominance.ll
+++ b/llvm/test/Transforms/Attributor/value-simplify-dominance.ll
@@ -135,11 +135,51 @@ m2:
   %l = load i32, ptr %p
   ret i32 %l
 }
+
+declare void @usei32(i32) nocallback
+; Ensure we use 42, not undef, for %l in the usei32 call and %r in the return.
+define internal i32 @remote_write_and_read(ptr %p) norecurse {
+; TUNIT: Function Attrs: norecurse
+; TUNIT-LABEL: define {{[^@]+}}@remote_write_and_read
+; TUNIT-SAME: (ptr noalias nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[P:%.*]]) #[[ATTR2]] {
+; TUNIT-NEXT:    call void @usei32(i32 noundef 42)
+; TUNIT-NEXT:    ret i32 undef
+;
+; CGSCC: Function Attrs: norecurse
+; CGSCC-LABEL: define {{[^@]+}}@remote_write_and_read
+; CGSCC-SAME: (ptr noalias nocapture nofree noundef nonnull align 4 dereferenceable(4) [[P:%.*]]) #[[ATTR2]] {
+; CGSCC-NEXT:    store i32 42, ptr [[P]], align 4
+; CGSCC-NEXT:    [[L:%.*]] = load i32, ptr [[P]], align 4
+; CGSCC-NEXT:    call void @usei32(i32 [[L]])
+; CGSCC-NEXT:    ret i32 [[L]]
+;
+  store i32 42, ptr %p
+  %l = load i32, ptr %p
+  call void @usei32(i32 %l)
+  ret i32 %l
+}
+
+define i32 @local_stack_remote_write_and_read() norecurse {
+; TUNIT: Function Attrs: norecurse
+; TUNIT-LABEL: define {{[^@]+}}@local_stack_remote_write_and_read
+; TUNIT-SAME: () #[[ATTR2]] {
+; TUNIT-NEXT:    [[A:%.*]] = alloca i32, align 4
+; TUNIT-NEXT:    [[R:%.*]] = call i32 @remote_write_and_read(ptr noalias nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[A]])
+; TUNIT-NEXT:    ret i32 42
+;
+; CGSCC: Function Attrs: norecurse
+; CGSCC-LABEL: define {{[^@]+}}@local_stack_remote_write_and_read
+; CGSCC-SAME: () #[[ATTR2]] {
+; CGSCC-NEXT:    [[A:%.*]] = alloca i32, align 4
+; CGSCC-NEXT:    [[R:%.*]] = call i32 @remote_write_and_read(ptr noalias nocapture nofree noundef nonnull align 4 dereferenceable(4) [[A]])
+; CGSCC-NEXT:    ret i32 [[R]]
+;
+  %a = alloca i32
+  %r = call i32 @remote_write_and_read(ptr %a)
+  ret i32 %r
+}
 ;.
 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback }
 ; CHECK: attributes #[[ATTR1]] = { norecurse nosync }
 ; CHECK: attributes #[[ATTR2]] = { norecurse }
 ;.
-;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
-; CGSCC: {{.*}}
-; TUNIT: {{.*}}


        


More information about the llvm-commits mailing list