[llvm] r366090 - [FunctionAttrs] Remove readonly and writeonly assertion

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 15 10:31:27 PDT 2019


Author: jdoerfert
Date: Mon Jul 15 10:31:26 2019
New Revision: 366090

URL: http://llvm.org/viewvc/llvm-project?rev=366090&view=rev
Log:
[FunctionAttrs] Remove readonly and writeonly assertion

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.

Patch by Luke Lau <luke.lau at intel.com>

Differential Revision: https://reviews.llvm.org/D60761

Added:
    llvm/trunk/test/Transforms/FunctionAttrs/read-write-scc.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=366090&r1=366089&r2=366090&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Mon Jul 15 10:31:26 2019
@@ -261,12 +261,15 @@ static bool addReadAttrs(const SCCNodeSe
     }
   }
 
+  // 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!

Added: llvm/trunk/test/Transforms/FunctionAttrs/read-write-scc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/read-write-scc.ll?rev=366090&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/read-write-scc.ll (added)
+++ llvm/trunk/test/Transforms/FunctionAttrs/read-write-scc.ll Mon Jul 15 10:31:26 2019
@@ -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 = { nofree nounwind }




More information about the llvm-commits mailing list