mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
Do not mark ALL terminators live if any instruciton in the block is live. We only
want to mark it live if it is an unconditional branch. This fixes bug: ADCE/2002-05-28-Crash.ll and makes this pass _much_ more useful. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6887 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e4b79d3324
commit
99c91e021a
@ -105,8 +105,11 @@ void ADCE::markBlockAlive(BasicBlock *BB) {
|
|||||||
bind_obj(this, &ADCE::markTerminatorLive));
|
bind_obj(this, &ADCE::markTerminatorLive));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this basic block is live, then the terminator must be as well!
|
// If this basic block is live, and it ends in an unconditional branch, then
|
||||||
markTerminatorLive(BB);
|
// the branch is alive as well...
|
||||||
|
if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator()))
|
||||||
|
if (BI->isUnconditional())
|
||||||
|
markTerminatorLive(BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dropReferencesOfDeadInstructionsInLiveBlock - Loop over all of the
|
// dropReferencesOfDeadInstructionsInLiveBlock - Loop over all of the
|
||||||
@ -248,6 +251,7 @@ bool ADCE::doADCE() {
|
|||||||
NewEntry->getInstList().push_back(new BranchInst(&Func->front()));
|
NewEntry->getInstList().push_back(new BranchInst(&Func->front()));
|
||||||
Func->getBasicBlockList().push_front(NewEntry);
|
Func->getBasicBlockList().push_front(NewEntry);
|
||||||
AliveBlocks.insert(NewEntry); // This block is always alive!
|
AliveBlocks.insert(NewEntry); // This block is always alive!
|
||||||
|
LiveSet.insert(NewEntry->getTerminator()); // The branch is live
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over all of the alive blocks in the function. If any successor
|
// Loop over all of the alive blocks in the function. If any successor
|
||||||
@ -260,6 +264,23 @@ bool ADCE::doADCE() {
|
|||||||
BasicBlock *BB = I;
|
BasicBlock *BB = I;
|
||||||
TerminatorInst *TI = BB->getTerminator();
|
TerminatorInst *TI = BB->getTerminator();
|
||||||
|
|
||||||
|
// If the terminator instruction is alive, but the block it is contained
|
||||||
|
// in IS alive, this means that this terminator is a conditional branch
|
||||||
|
// on a condition that doesn't matter. Make it an unconditional branch
|
||||||
|
// to ONE of the successors. This has the side effect of dropping a use
|
||||||
|
// of the conditional value, which may also be dead.
|
||||||
|
if (!LiveSet.count(TI)) {
|
||||||
|
assert(TI->getNumSuccessors() > 1 && "Not a conditional?");
|
||||||
|
BranchInst *NB = new BranchInst(TI->getSuccessor(0), TI);
|
||||||
|
|
||||||
|
// Remove entries from PHI nodes to avoid confusing ourself later...
|
||||||
|
for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i)
|
||||||
|
TI->getSuccessor(i)->removePredecessor(BB);
|
||||||
|
|
||||||
|
BB->getInstList().erase(TI);
|
||||||
|
TI = NB;
|
||||||
|
}
|
||||||
|
|
||||||
// Loop over all of the successors, looking for ones that are not alive.
|
// Loop over all of the successors, looking for ones that are not alive.
|
||||||
// We cannot save the number of successors in the terminator instruction
|
// We cannot save the number of successors in the terminator instruction
|
||||||
// here because we may remove them if we don't have a postdominator...
|
// here because we may remove them if we don't have a postdominator...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user