mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-16 12:24:03 +00:00
Fix PR867 (and maybe 868) and testcsae:
Transforms/SimplifyCFG/2006-08-03-Crash.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29515 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -459,12 +459,31 @@ static bool GatherValueComparisons(Instruction *Cond, Value *&CompVal,
|
|||||||
/// has no side effects, nuke it. If it uses any instructions that become dead
|
/// has no side effects, nuke it. If it uses any instructions that become dead
|
||||||
/// because the instruction is now gone, nuke them too.
|
/// because the instruction is now gone, nuke them too.
|
||||||
static void ErasePossiblyDeadInstructionTree(Instruction *I) {
|
static void ErasePossiblyDeadInstructionTree(Instruction *I) {
|
||||||
if (isInstructionTriviallyDead(I)) {
|
if (!isInstructionTriviallyDead(I)) return;
|
||||||
std::vector<Value*> Operands(I->op_begin(), I->op_end());
|
|
||||||
I->getParent()->getInstList().erase(I);
|
std::vector<Instruction*> InstrsToInspect;
|
||||||
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
|
InstrsToInspect.push_back(I);
|
||||||
if (Instruction *OpI = dyn_cast<Instruction>(Operands[i]))
|
|
||||||
ErasePossiblyDeadInstructionTree(OpI);
|
while (!InstrsToInspect.empty()) {
|
||||||
|
I = InstrsToInspect.back();
|
||||||
|
InstrsToInspect.pop_back();
|
||||||
|
|
||||||
|
if (!isInstructionTriviallyDead(I)) continue;
|
||||||
|
|
||||||
|
// If I is in the work list multiple times, remove previous instances.
|
||||||
|
for (unsigned i = 0, e = InstrsToInspect.size(); i != e; ++i)
|
||||||
|
if (InstrsToInspect[i] == I) {
|
||||||
|
InstrsToInspect.erase(InstrsToInspect.begin()+i);
|
||||||
|
--i, --e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add operands of dead instruction to worklist.
|
||||||
|
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
||||||
|
if (Instruction *OpI = dyn_cast<Instruction>(I->getOperand(i)))
|
||||||
|
InstrsToInspect.push_back(OpI);
|
||||||
|
|
||||||
|
// Remove dead instruction.
|
||||||
|
I->eraseFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user