diff options
author | Chris Lattner <sabre@nondot.org> | 2003-09-23 20:26:48 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-09-23 20:26:48 +0000 |
commit | 332ae7f501e36d88b1dfdff4f18485ef07663085 (patch) | |
tree | 9a9b6bfd678205dd000388bb81cb5ea3412e86ad /lib/Transforms | |
parent | e1a37cba9c8f03d5292c0d420d4ac9dd6226a210 (diff) |
Fix bug: IndVarsSimplify/2003-09-23-NotAtTop.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8689 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 814f452497..33c8c700e6 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -76,8 +76,8 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) { // indvar. If we don't have one, add one now... if (!Canonical) { // Create the PHI node for the new induction variable, and insert the phi - // node at the end of the other phi nodes... - PHINode *PN = new PHINode(Type::UIntTy, "cann-indvar", AfterPHIIt); + // node at the start of the PHI nodes... + PHINode *PN = new PHINode(Type::UIntTy, "cann-indvar", Header->begin()); // Create the increment instruction to add one to the counter... Instruction *Add = BinaryOperator::create(Instruction::Add, PN, @@ -108,6 +108,12 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) { Canonical = &IndVars.back(); ++NumInserted; Changed = true; + } else { + // If we have a canonical induction variable, make sure that it is the first + // one in the basic block. + if (&Header->front() != Canonical->Phi) + Header->getInstList().splice(Header->begin(), Header->getInstList(), + Canonical->Phi); } DEBUG(std::cerr << "Induction variables:\n"); |