[llvm-commits] [llvm] r61535 - in /llvm/trunk: lib/Transforms/IPO/FunctionAttrs.cpp test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll

Duncan Sands baldrick at free.fr
Wed Dec 31 12:21:34 PST 2008


Author: baldrick
Date: Wed Dec 31 14:21:34 2008
New Revision: 61535

URL: http://llvm.org/viewvc/llvm-project?rev=61535&view=rev
Log:
Look through phi nodes and select instructions when
calculating nocapture attributes.

Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
    llvm/trunk/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll

Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=61535&r1=61534&r2=61535&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Wed Dec 31 14:21:34 2008
@@ -225,9 +225,14 @@
       continue;
     }
 
-    if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) {
-      // Type conversion or calculating an offset.  Does not escape if the new
-      // value doesn't.
+    if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I) ||
+        isa<PHINode>(I) || isa<SelectInst>(I)) {
+      // Type conversion, calculating an offset, or merging values.
+      // The original value does not escape via this if the new value doesn't.
+      // Note that in the case of a select instruction it is important that
+      // the value not be used as the condition, since otherwise one bit of
+      // information might escape.  It cannot be the condition because it has
+      // the wrong type.
       for (Instruction::use_iterator UI = I->use_begin(), UE = I->use_end();
            UI != UE; ++UI) {
         Use *U = &UI.getUse();

Modified: llvm/trunk/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll?rev=61535&r1=61534&r2=61535&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll Wed Dec 31 14:21:34 2008
@@ -1,34 +1,41 @@
-; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep {@c.*nocapture}
-; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep nocapture | count 3
+; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep {nocapture *%%q}
+; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep {nocapture *%%p} | count 3
 @g = global i32* null		; <i32**> [#uses=1]
 
-define i32* @c1(i32* %p) {
-	ret i32* %p
+define i32* @c1(i32* %q) {
+	ret i32* %q
 }
 
-define void @c2(i32* %p) {
-	store i32* %p, i32** @g
+define void @c2(i32* %q) {
+	store i32* %q, i32** @g
 	ret void
 }
 
-define void @c3(i32* %p) {
-	call void @c2(i32* %p)
+define void @c3(i32* %q) {
+	call void @c2(i32* %q)
 	ret void
 }
 
-define i32 @nc1(i32* %p) {
-	%tmp = bitcast i32* %p to i32*		; <i32*> [#uses=2]
-	%val = load i32* %tmp		; <i32> [#uses=1]
+define i32 @nc1(i32* %q, i32* %p, i1 %b) {
+e:
+	br label %l
+l:
+	%x = phi i32* [ %p, %e ]
+	%y = phi i32* [ %q, %e ]
+	%tmp = bitcast i32* %x to i32*		; <i32*> [#uses=2]
+	%tmp2 = select i1 %b, i32* %tmp, i32* %y
+	%val = load i32* %tmp2		; <i32> [#uses=1]
 	store i32 0, i32* %tmp
+	store i32* %y, i32** @g
 	ret i32 %val
 }
 
-define void @nc2(i32* %p) {
-	%1 = call i32 @nc1(i32* %p)		; <i32> [#uses=0]
+define void @nc2(i32* %p, i32* %q) {
+	%1 = call i32 @nc1(i32* %q, i32* %p, i1 0)		; <i32> [#uses=0]
 	ret void
 }
 
-define void @nc3(void ()* %f) {
-	call void %f()
+define void @nc3(void ()* %p) {
+	call void %p()
 	ret void
 }





More information about the llvm-commits mailing list