[PATCH] D20616: Fix Function Attributes computation for llvm.assume

Boaz Ouriel via llvm-commits llvm-commits at lists.llvm.org
Wed May 25 02:08:12 PDT 2016


boazo created this revision.
boazo added reviewers: aaboud, DavidKreitzer, gberry.
boazo added a subscriber: llvm-commits.

When running the function attributes pass llvm.assume is marked as readnone.
Running instcombine after this pass will remove the llvm.assume causing a potential optimization from happening.
This required after commit [[ http://reviews.llvm.org/rL268068 | rL268068 ]]

http://reviews.llvm.org/D20616

Files:
  lib/Transforms/IPO/FunctionAttrs.cpp
  test/Transforms/FunctionAttrs/assume.ll

Index: lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- lib/Transforms/IPO/FunctionAttrs.cpp
+++ lib/Transforms/IPO/FunctionAttrs.cpp
@@ -205,6 +205,11 @@
       // No change.
       continue;
 
+	if (F->getIntrinsicID() == Intrinsic::assume)
+		// don't change attributes of the assume intrinsic, 
+		// so that later on, it is not thrown away by other optimizations
+		continue;
+
     MadeChange = true;
 
     // Clear out any existing attributes.
Index: test/Transforms/FunctionAttrs/assume.ll
===================================================================
--- test/Transforms/FunctionAttrs/assume.ll
+++ test/Transforms/FunctionAttrs/assume.ll
@@ -0,0 +1,29 @@
+; RUN: opt -functionattrs -S < %s | FileCheck %s
+; RUN: opt -functionattrs -instcombine -S < %s | FileCheck %s -check-prefix=ASSUME
+;
+; Ensures that llvm.assume:
+;  is not marked with readnone attribute.
+;  is not considered as accessing memory for the purposes of function attributes computation.
+
+;CHECK: declare void @llvm.assume(i1) #0
+declare void @llvm.assume(i1)
+
+;CHECK: define i32 @foo(i32 %x) #1
+;ASSUME: define i32 @foo(i32 %x)
+define i32 @foo(i32 %x) {
+	entry:
+		%cmp = icmp eq i32 %x, 2
+		call void @llvm.assume(i1 %cmp)
+;ASSUME: ret i32 2
+		ret i32 %x
+}
+
+;CHECK: define i32 @foo2(i32 %x) #1
+define i32 @foo2(i32 %x) {
+	entry:
+		%foo.x = call i32 @foo(i32 %x)
+		ret i32 %foo.x
+}
+
+;CHECK: attributes #0 = { nounwind }
+;CHECK: attributes #1 = { readnone }
\ No newline at end of file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20616.58390.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160525/d3470707/attachment.bin>


More information about the llvm-commits mailing list