aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-06-24 14:31:06 +0000
committerDan Gohman <gohman@apple.com>2009-06-24 14:31:06 +0000
commit4815a0efee67175bb11e09966247fc80afe4870a (patch)
treefa4c4d4b3387abafbb90850cc3f08cc49b96109f /lib/Transforms
parent85625696b9357fc4313a34de25fef95fc2c023f1 (diff)
downloadexternal_llvm-4815a0efee67175bb11e09966247fc80afe4870a.zip
external_llvm-4815a0efee67175bb11e09966247fc80afe4870a.tar.gz
external_llvm-4815a0efee67175bb11e09966247fc80afe4870a.tar.bz2
When inserting code into a loop preheader, insert it before the
terminator, instead of after the last phi. This fixes a bug exposed by ScalarEvolution analyzing more kinds of loops. This fixes PR4436. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 658b788..ec4be9b 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -230,13 +230,16 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L,
// We insert the code into the preheader of the loop if the loop contains
// multiple exit blocks, or in the exit block if there is exactly one.
BasicBlock *BlockToInsertInto;
+ BasicBlock::iterator InsertPt;
SmallVector<BasicBlock*, 8> ExitBlocks;
L->getUniqueExitBlocks(ExitBlocks);
- if (ExitBlocks.size() == 1)
+ if (ExitBlocks.size() == 1) {
BlockToInsertInto = ExitBlocks[0];
- else
+ InsertPt = BlockToInsertInto->getFirstNonPHI();
+ } else {
BlockToInsertInto = Preheader;
- BasicBlock::iterator InsertPt = BlockToInsertInto->getFirstNonPHI();
+ InsertPt = BlockToInsertInto->getTerminator();
+ }
std::map<Instruction*, Value*> ExitValues;