[PATCH] D32006: Mark invariant.group.barrier as inaccessiblememonly

Piotr Padlewski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 04:38:18 PDT 2017


Prazek created this revision.

It turned out that readonly argmemonly is not enough.

  store 42, %p
  %b = barrier(%p)
  store 43, %b

the first store is dead, but because barrier was marked as
reading argument memory, it was considered alive. With
inaccessiblememonly it doesn't read the argument, but
it also can't be CSEd.


https://reviews.llvm.org/D32006

Files:
  include/llvm/IR/Intrinsics.td
  test/Analysis/MemorySSA/invariant-groups.ll
  test/Other/invariant.group.barrier.ll


Index: test/Other/invariant.group.barrier.ll
===================================================================
--- test/Other/invariant.group.barrier.ll
+++ test/Other/invariant.group.barrier.ll
@@ -54,7 +54,7 @@
 declare void @use(i8* readonly)
 
 declare void @clobber(i8*)
-; CHECK: Function Attrs: argmemonly nounwind readonly
+; CHECK: Function Attrs: inaccessiblememonly nounwind readonly
 ; CHECK-NEXT: declare i8* @llvm.invariant.group.barrier(i8*)
 declare i8* @llvm.invariant.group.barrier(i8*)
 
Index: test/Analysis/MemorySSA/invariant-groups.ll
===================================================================
--- test/Analysis/MemorySSA/invariant-groups.ll
+++ test/Analysis/MemorySSA/invariant-groups.ll
@@ -16,7 +16,7 @@
   store i32 1, i32* @g, align 4
 
   %1 = bitcast i32* %a to i8*
-; CHECK: MemoryUse(2)
+; CHECK: MemoryUse(liveOnEntry)
 ; CHECK-NEXT: %a8 = call i8* @llvm.invariant.group.barrier(i8* %1)
   %a8 = call i8* @llvm.invariant.group.barrier(i8* %1)
   %a32 = bitcast i8* %a8 to i32*
@@ -35,7 +35,7 @@
   store i32 0, i32* %a, align 4, !invariant.group !0
 
   %1 = bitcast i32* %a to i8*
-; CHECK: MemoryUse(1)
+; CHECK: MemoryUse(liveOnEntry)
 ; CHECK-NEXT: %a8 = call i8* @llvm.invariant.group.barrier(i8* %1)
   %a8 = call i8* @llvm.invariant.group.barrier(i8* %1)
   %a32 = bitcast i8* %a8 to i32*
@@ -85,7 +85,7 @@
 ; CHECK-NEXT: store i32 1
   store i32 1, i32* @g, align 4
   %1 = bitcast i32* %a to i8*
-; CHECK: MemoryUse(2)
+; CHECK: MemoryUse(liveOnEntry)
 ; CHECK-NEXT: %a8 = call i8* @llvm.invariant.group.barrier(i8* %1)
   %a8 = call i8* @llvm.invariant.group.barrier(i8* %1)
   %a32 = bitcast i8* %a8 to i32*
Index: include/llvm/IR/Intrinsics.td
===================================================================
--- include/llvm/IR/Intrinsics.td
+++ include/llvm/IR/Intrinsics.td
@@ -617,14 +617,17 @@
 
 // invariant.group.barrier can't be marked with 'readnone' (IntrNoMem),
 // because it would cause CSE of two barriers with the same argument.
-// Readonly and argmemonly says that barrier only reads its argument and
-// it can be CSE only if memory didn't change between 2 barriers call,
-// which is valid.
+// Readonly and inaccessiblememonly says that barrier only reads memory
+// inaccessible to this module, so it can be CSE only if memory didn't change
+// between 2 barriers call, which is valid.
+// Since the barrier doesn't read the argument, we can perform DSE through
+// the barrier.
 // The argument also can't be marked with 'returned' attribute, because
 // it would remove barrier. 
 def int_invariant_group_barrier : Intrinsic<[llvm_ptr_ty],
                                             [llvm_ptr_ty],
-                                            [IntrReadMem, IntrArgMemOnly]>;
+                                            [IntrReadMem,
+                                             IntrInaccessibleMemOnly]>;
 
 //===------------------------ Stackmap Intrinsics -------------------------===//
 //


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32006.95104.patch
Type: text/x-patch
Size: 2981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170413/68311678/attachment.bin>


More information about the llvm-commits mailing list