[llvm-commits] [llvm] r69808 - in /llvm/trunk: lib/Analysis/ScalarEvolutionExpander.cpp test/Transforms/IndVarSimplify/casted-argument.ll

Dan Gohman gohman at apple.com
Wed Apr 22 09:11:16 PDT 2009


Author: djg
Date: Wed Apr 22 11:11:16 2009
New Revision: 69808

URL: http://llvm.org/viewvc/llvm-project?rev=69808&view=rev
Log:
SCEVExpander's InsertCastOfTo knows how to move existing cast
instructions in order to avoid inserting new ones. However, if
the cast instruction is the SCEVExpander's InsertPt, this
causes subsequently emitted instructions to be inserted near
the cast, and not at the location of the original insert point.
Fix this by adjusting the insert point in such cases.
This fixes PR4009.

Added:
    llvm/trunk/test/Transforms/IndVarSimplify/casted-argument.ll
Modified:
    llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=69808&r1=69807&r2=69808&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Wed Apr 22 11:11:16 2009
@@ -49,6 +49,9 @@
             // If the cast isn't the first instruction of the function, move it.
             if (BasicBlock::iterator(CI) != 
                 A->getParent()->getEntryBlock().begin()) {
+              // If the CastInst is the insert point, change the insert point.
+              if (CI == InsertPt) ++InsertPt;
+              // Splice the cast at the beginning of the entry block.
               CI->moveBefore(A->getParent()->getEntryBlock().begin());
             }
             return CI;
@@ -71,6 +74,8 @@
             It = cast<InvokeInst>(I)->getNormalDest()->begin();
           while (isa<PHINode>(It)) ++It;
           if (It != BasicBlock::iterator(CI)) {
+            // If the CastInst is the insert point, change the insert point.
+            if (CI == InsertPt) ++InsertPt;
             // Splice the cast immediately after the operand in question.
             CI->moveBefore(It);
           }

Added: llvm/trunk/test/Transforms/IndVarSimplify/casted-argument.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/casted-argument.ll?rev=69808&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/casted-argument.ll (added)
+++ llvm/trunk/test/Transforms/IndVarSimplify/casted-argument.ll Wed Apr 22 11:11:16 2009
@@ -0,0 +1,24 @@
+; RUN: llvm-as < %s | opt -indvars -disable-output
+; PR4009
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
+target triple = "i386-pc-linux-gnu"
+
+define void @safe_bcopy(i8* %to) nounwind {
+entry:
+	%cmp11 = icmp ult i8* %to, null		; <i1> [#uses=1]
+	br i1 %cmp11, label %loop, label %return
+
+return:		; preds = %entry
+	ret void
+
+loop:		; preds = %loop, %if.else
+	%pn = phi i8* [ %ge, %loop ], [ null, %entry ]		; <i8*> [#uses=1]
+	%cp = ptrtoint i8* %to to i32		; <i32> [#uses=1]
+	%su = sub i32 0, %cp		; <i32> [#uses=1]
+	%ge = getelementptr i8* %pn, i32 %su		; <i8*> [#uses=2]
+	tail call void @bcopy(i8* %ge) nounwind
+	br label %loop
+}
+
+declare void @bcopy(i8* nocapture) nounwind





More information about the llvm-commits mailing list