diff options
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index 9938dd89c19..880f5389171 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -1629,15 +1629,27 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) { ReplaceUsesOfWith(PN, PN->getIncomingValue(0), Worklist, L, LPM, MSSAU.get()); - // If Succ has any successors with PHI nodes, update them to have - // entries coming from Pred instead of Succ. - Succ->replaceAllUsesWith(Pred); + Instruction *STI = Succ->getTerminator(); + Instruction *Start = &*Succ->begin(); + // If there's nothing to move, mark the starting instruction as the last + // instruction in the block. + if (Start == STI) + Start = BI; // Move all of the successor contents from Succ to Pred. Pred->getInstList().splice(BI->getIterator(), Succ->getInstList(), - Succ->begin(), Succ->end()); + Succ->begin(), STI->getIterator()); if (MSSAU) - MSSAU->moveAllAfterMergeBlocks(Succ, Pred, BI); + MSSAU->moveAllAfterMergeBlocks(Succ, Pred, Start); + + // Move terminator instruction from Succ now, we're deleting BI below. + // FIXME: remove BI first might be more intuitive. + Pred->getInstList().splice(Pred->end(), Succ->getInstList()); + + // If Succ has any successors with PHI nodes, update them to have + // entries coming from Pred instead of Succ. + Succ->replaceAllUsesWith(Pred); + LPM->deleteSimpleAnalysisValue(BI, L); RemoveFromWorklist(BI, Worklist); BI->eraseFromParent(); |