[PATCH] D60761: [FunctionAttrs] Remove readonly and writeonly assertion

Luke Lau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 01:31:01 PDT 2019


luke created this revision.
luke added reviewers: hfinkel, jdoerfert, homerdin.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

There are scenarios where mutually recursive functions may cause the SCC
to contain both read only and write only functions. This removes an
assertion when adding read attributes which caused a crash with a the
provided test case, and instead just doesn't add the attributes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60761

Files:
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/test/Transforms/FunctionAttrs/read-write-scc.ll


Index: llvm/test/Transforms/FunctionAttrs/read-write-scc.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/FunctionAttrs/read-write-scc.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -functionattrs < %s | FileCheck %s
+; RUN: opt -S -passes=function-attrs < %s | FileCheck %s
+
+ at i = global i32 0
+
+define void @foo() {
+; CHECK-LABEL: define void @foo() #0 {
+  store i32 1, i32* @i
+  call void @bar()
+  ret void
+}
+
+define void @bar() {
+; CHECK-LABEL: define void @bar() #0 {
+  %i = load i32, i32* @i
+  call void @foo()
+  ret void
+}
+
+; CHECK: attributes #0 = { nounwind }
Index: llvm/lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -255,12 +255,15 @@
     }
   }
 
+  // If the SCC contains both functions that read and functions that write, then
+  // we cannot add readonly attributes.
+  if (ReadsMemory && WritesMemory)
+    return false;
+
   // Success!  Functions in this SCC do not access memory, or only read memory.
   // Give them the appropriate attribute.
   bool MadeChange = false;
 
-  assert(!(ReadsMemory && WritesMemory) &&
-          "Function marked read-only and write-only");
   for (Function *F : SCCNodes) {
     if (F->doesNotAccessMemory())
       // Already perfect!


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60761.195326.patch
Type: text/x-patch
Size: 1409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190416/75445d46/attachment.bin>


More information about the llvm-commits mailing list