summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-04-22 16:11:16 +0000
committerDan Gohman <gohman@apple.com>2009-04-22 16:11:16 +0000
commit54fd2869a3b6d3e1d11a45b39c77953356c3476d (patch)
treeadecb5b26025a7132cb823c7b4e4c02bcaeed30e /llvm
parent9dd9a45e129caf7813eee690e2df06871591f43c (diff)
downloadbcm5719-llvm-54fd2869a3b6d3e1d11a45b39c77953356c3476d.tar.gz
bcm5719-llvm-54fd2869a3b6d3e1d11a45b39c77953356c3476d.zip
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. llvm-svn: 69808
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Analysis/ScalarEvolutionExpander.cpp5
-rw-r--r--llvm/test/Transforms/IndVarSimplify/casted-argument.ll24
2 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
index 394ad6c0109..74c11183e81 100644
--- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -49,6 +49,9 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
// 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 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
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);
}
diff --git a/llvm/test/Transforms/IndVarSimplify/casted-argument.ll b/llvm/test/Transforms/IndVarSimplify/casted-argument.ll
new file mode 100644
index 00000000000..ae41e3a8b7c
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/casted-argument.ll
@@ -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
OpenPOWER on IntegriCloud