[llvm] r341927 - [FuncAttrs] Remove "access range attributes" for read-none functions

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 11 04:51:29 PDT 2018


Author: jdoerfert
Date: Tue Sep 11 04:51:29 2018
New Revision: 341927

URL: http://llvm.org/viewvc/llvm-project?rev=341927&view=rev
Log:
[FuncAttrs] Remove "access range attributes" for read-none functions

The presence of readnone and an access range attribute (argmemonly,
inaccessiblememonly, inaccessiblemem_or_argmemonly) is considered an
error by the verifier. This seems strict but also not wrong. This
patch makes sure function attribute detection will remove all access
range attributes for readnone functions.

Added:
    llvm/trunk/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp

Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=341927&r1=341926&r2=341927&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Tue Sep 11 04:51:29 2018
@@ -281,6 +281,13 @@ static bool addReadAttrs(const SCCNodeSe
     F->removeFnAttr(Attribute::ReadNone);
     F->removeFnAttr(Attribute::WriteOnly);
 
+    if (!WritesMemory && !ReadsMemory) {
+      // Clear out any "access range attributes" if readnone was deduced.
+      F->removeFnAttr(Attribute::ArgMemOnly);
+      F->removeFnAttr(Attribute::InaccessibleMemOnly);
+      F->removeFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
+    }
+
     // Add in the new attribute.
     if (WritesMemory && !ReadsMemory)
       F->addFnAttr(Attribute::WriteOnly);

Added: llvm/trunk/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll?rev=341927&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll (added)
+++ llvm/trunk/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll Tue Sep 11 04:51:29 2018
@@ -0,0 +1,32 @@
+; RUN: opt -S -o - -functionattrs %s | FileCheck %s
+; RUN: opt -S -o - -passes=function-attrs %s | FileCheck %s
+
+; Verify we remove argmemonly/inaccessiblememonly/inaccessiblemem_or_argmemonly
+; function attributes when we derive readnone.
+
+; Function Attrs: argmemonly
+define i32* @given_argmem_infer_readnone(i32* %p) #0 {
+; CHECK: define i32* @given_argmem_infer_readnone(i32* readnone returned %p) #0 {
+entry:
+  ret i32* %p
+}
+
+; Function Attrs: inaccessiblememonly
+define i32* @given_inaccessible_infer_readnone(i32* %p) #1 {
+; CHECK: define i32* @given_inaccessible_infer_readnone(i32* readnone returned %p) #0 {
+entry:
+  ret i32* %p
+}
+
+; Function Attrs: inaccessiblemem_or_argmemonly
+define i32* @given_inaccessible_or_argmem_infer_readnone(i32* %p) #2 {
+; CHECK: define i32* @given_inaccessible_or_argmem_infer_readnone(i32* readnone returned %p) #0 {
+entry:
+  ret i32* %p
+}
+
+attributes #0 = { argmemonly }
+attributes #1 = { inaccessiblememonly }
+attributes #2 = { inaccessiblemem_or_argmemonly }
+; CHECK: attributes #0 = { norecurse nounwind readnone }
+; CHECK-NOT: attributes




More information about the llvm-commits mailing list