[llvm] r238152 - Remove conflicting attributes before adding deduced readonly/readnone

Bjorn Steinbrink bsteinbr at gmail.com
Mon May 25 12:46:38 PDT 2015


Author: bsteinbr
Date: Mon May 25 14:46:38 2015
New Revision: 238152

URL: http://llvm.org/viewvc/llvm-project?rev=238152&view=rev
Log:
Remove conflicting attributes before adding deduced readonly/readnone

Summary:
In case of functions that have a pointer argument and only pass it to
each other, the function attributes pass deduces that the pointer should
get the readnone attribute, but fails to remove a readonly attribute
that may already have been present.

Reviewers: nlewycky

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9995

Added:
    llvm/trunk/test/Transforms/FunctionAttrs/readnone.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=238152&r1=238151&r2=238152&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Mon May 25 14:46:38 2015
@@ -703,10 +703,14 @@ bool FunctionAttrs::AddArgumentAttrs(con
     }
 
     if (ReadAttr != Attribute::None) {
-      AttrBuilder B;
+      AttrBuilder B, R;
       B.addAttribute(ReadAttr);
+      R.addAttribute(Attribute::ReadOnly)
+        .addAttribute(Attribute::ReadNone);
       for (unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
         Argument *A = ArgumentSCC[i]->Definition;
+        // Clear out existing readonly/readnone attributes
+        A->removeAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, R));
         A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B));
         ReadAttr == Attribute::ReadOnly ? ++NumReadOnlyArg : ++NumReadNoneArg;
         Changed = true;

Added: llvm/trunk/test/Transforms/FunctionAttrs/readnone.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/readnone.ll?rev=238152&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/readnone.ll (added)
+++ llvm/trunk/test/Transforms/FunctionAttrs/readnone.ll Mon May 25 14:46:38 2015
@@ -0,0 +1,13 @@
+; RUN: opt < %s -functionattrs -S | FileCheck %s
+
+; CHECK: define void @bar(i8* nocapture readnone)
+define void @bar(i8* readonly) {
+  call void @foo(i8* %0)
+    ret void
+}
+
+; CHECK: define void @foo(i8* nocapture readnone)
+define void @foo(i8* readonly) {
+  call void @bar(i8* %0)
+  ret void
+}





More information about the llvm-commits mailing list