diff options
author | Dan Gohman <gohman@apple.com> | 2009-04-22 16:11:16 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-04-22 16:11:16 +0000 |
commit | aabb04f52714ceb271dba7da18f757a4365bb4ac (patch) | |
tree | 87f55a4ac2b1d42a6f432ee1896facefc65af46f /lib/Analysis/ScalarEvolutionExpander.cpp | |
parent | 6cdc727f2d7f68734526ef078f4632798ad40791 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r-- | lib/Analysis/ScalarEvolutionExpander.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index 394ad6c010..74c11183e8 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/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); } |