From 32a81a3f6d75c5343e7df65ce5d228f2128ca943 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 24 Jun 2009 14:31:06 +0000 Subject: 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 --- lib/Transforms/Scalar/IndVarSimplify.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/Transforms') 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 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 ExitValues; -- cgit v1.1