mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-16 14:31:59 +00:00
Do not eliminate loop when it is invalid to do so. For example,
for(int i = 0; i < N; i++) { if ( i == XYZ) { A; else B; } C; D; } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42058 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5279d064bc
commit
8893ca6dab
@ -528,6 +528,20 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
|
|||||||
if (!safeExitingBlock(SD, ExitCondition->getParent()))
|
if (!safeExitingBlock(SD, ExitCondition->getParent()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// If split condition is not safe then do not process this loop.
|
||||||
|
// For example,
|
||||||
|
// for(int i = 0; i < N; i++) {
|
||||||
|
// if ( i == XYZ) {
|
||||||
|
// A;
|
||||||
|
// else
|
||||||
|
// B;
|
||||||
|
// }
|
||||||
|
// C;
|
||||||
|
// D;
|
||||||
|
// }
|
||||||
|
if (!safeSplitCondition(SD))
|
||||||
|
return false;
|
||||||
|
|
||||||
// Update CFG.
|
// Update CFG.
|
||||||
|
|
||||||
// Replace index variable with split value in loop body. Loop body is executed
|
// Replace index variable with split value in loop body. Loop body is executed
|
||||||
@ -956,24 +970,11 @@ void LoopIndexSplit::removeBlocks(BasicBlock *DeadBB, Loop *LP,
|
|||||||
bool LoopIndexSplit::safeSplitCondition(SplitInfo &SD) {
|
bool LoopIndexSplit::safeSplitCondition(SplitInfo &SD) {
|
||||||
|
|
||||||
BasicBlock *SplitCondBlock = SD.SplitCondition->getParent();
|
BasicBlock *SplitCondBlock = SD.SplitCondition->getParent();
|
||||||
|
|
||||||
// Unable to handle triange loops at the moment.
|
|
||||||
// In triangle loop, split condition is in header and one of the
|
|
||||||
// the split destination is loop latch. If split condition is EQ
|
|
||||||
// then such loops are already handle in processOneIterationLoop().
|
|
||||||
BasicBlock *Latch = L->getLoopLatch();
|
BasicBlock *Latch = L->getLoopLatch();
|
||||||
BranchInst *SplitTerminator =
|
BranchInst *SplitTerminator =
|
||||||
cast<BranchInst>(SplitCondBlock->getTerminator());
|
cast<BranchInst>(SplitCondBlock->getTerminator());
|
||||||
BasicBlock *Succ0 = SplitTerminator->getSuccessor(0);
|
BasicBlock *Succ0 = SplitTerminator->getSuccessor(0);
|
||||||
BasicBlock *Succ1 = SplitTerminator->getSuccessor(1);
|
BasicBlock *Succ1 = SplitTerminator->getSuccessor(1);
|
||||||
if (L->getHeader() == SplitCondBlock
|
|
||||||
&& (Latch == Succ0 || Latch == Succ1))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// If split condition branches heads do not have single predecessor,
|
|
||||||
// SplitCondBlock, then is not possible to remove inactive branch.
|
|
||||||
if (!Succ0->getSinglePredecessor() || !Succ1->getSinglePredecessor())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Finally this split condition is safe only if merge point for
|
// Finally this split condition is safe only if merge point for
|
||||||
// split condition branch is loop latch. This check along with previous
|
// split condition branch is loop latch. This check along with previous
|
||||||
@ -1196,6 +1197,26 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
|
|||||||
if (!safeSplitCondition(SD))
|
if (!safeSplitCondition(SD))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
BasicBlock *SplitCondBlock = SD.SplitCondition->getParent();
|
||||||
|
|
||||||
|
// Unable to handle triange loops at the moment.
|
||||||
|
// In triangle loop, split condition is in header and one of the
|
||||||
|
// the split destination is loop latch. If split condition is EQ
|
||||||
|
// then such loops are already handle in processOneIterationLoop().
|
||||||
|
BasicBlock *Latch = L->getLoopLatch();
|
||||||
|
BranchInst *SplitTerminator =
|
||||||
|
cast<BranchInst>(SplitCondBlock->getTerminator());
|
||||||
|
BasicBlock *Succ0 = SplitTerminator->getSuccessor(0);
|
||||||
|
BasicBlock *Succ1 = SplitTerminator->getSuccessor(1);
|
||||||
|
if (L->getHeader() == SplitCondBlock
|
||||||
|
&& (Latch == Succ0 || Latch == Succ1))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// If split condition branches heads do not have single predecessor,
|
||||||
|
// SplitCondBlock, then is not possible to remove inactive branch.
|
||||||
|
if (!Succ0->getSinglePredecessor() || !Succ1->getSinglePredecessor())
|
||||||
|
return false;
|
||||||
|
|
||||||
// After loop is cloned there are two loops.
|
// After loop is cloned there are two loops.
|
||||||
//
|
//
|
||||||
// First loop, referred as ALoop, executes first part of loop's iteration
|
// First loop, referred as ALoop, executes first part of loop's iteration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user