forked from OSchip/llvm-project
parent
7c8e6047d6
commit
73a58627c3
|
@ -168,40 +168,38 @@ bool JumpThreading::runOnFunction(Function &F) {
|
||||||
LVI->eraseBlock(BB);
|
LVI->eraseBlock(BB);
|
||||||
DeleteDeadBlock(BB);
|
DeleteDeadBlock(BB);
|
||||||
Changed = true;
|
Changed = true;
|
||||||
} else if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
|
continue;
|
||||||
// Can't thread an unconditional jump, but if the block is "almost
|
}
|
||||||
// empty", we can replace uses of it with uses of the successor and make
|
|
||||||
// this dead.
|
BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator());
|
||||||
if (BI->isUnconditional() &&
|
|
||||||
BB != &BB->getParent()->getEntryBlock()) {
|
// Can't thread an unconditional jump, but if the block is "almost
|
||||||
BasicBlock::iterator BBI = BB->getFirstNonPHI();
|
// empty", we can replace uses of it with uses of the successor and make
|
||||||
// Ignore dbg intrinsics.
|
// this dead.
|
||||||
while (isa<DbgInfoIntrinsic>(BBI))
|
if (BI && BI->isUnconditional() &&
|
||||||
++BBI;
|
BB != &BB->getParent()->getEntryBlock() &&
|
||||||
// If the terminator is the only non-phi instruction, try to nuke it.
|
// If the terminator is the only non-phi instruction, try to nuke it.
|
||||||
if (BBI->isTerminator()) {
|
BB->getFirstNonPHIOrDbg()->isTerminator()) {
|
||||||
// Since TryToSimplifyUncondBranchFromEmptyBlock may delete the
|
// Since TryToSimplifyUncondBranchFromEmptyBlock may delete the
|
||||||
// block, we have to make sure it isn't in the LoopHeaders set. We
|
// block, we have to make sure it isn't in the LoopHeaders set. We
|
||||||
// reinsert afterward if needed.
|
// reinsert afterward if needed.
|
||||||
bool ErasedFromLoopHeaders = LoopHeaders.erase(BB);
|
bool ErasedFromLoopHeaders = LoopHeaders.erase(BB);
|
||||||
BasicBlock *Succ = BI->getSuccessor(0);
|
BasicBlock *Succ = BI->getSuccessor(0);
|
||||||
|
|
||||||
// FIXME: It is always conservatively correct to drop the info
|
// FIXME: It is always conservatively correct to drop the info
|
||||||
// for a block even if it doesn't get erased. This isn't totally
|
// for a block even if it doesn't get erased. This isn't totally
|
||||||
// awesome, but it allows us to use AssertingVH to prevent nasty
|
// awesome, but it allows us to use AssertingVH to prevent nasty
|
||||||
// dangling pointer issues within LazyValueInfo.
|
// dangling pointer issues within LazyValueInfo.
|
||||||
LVI->eraseBlock(BB);
|
LVI->eraseBlock(BB);
|
||||||
if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) {
|
if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) {
|
||||||
Changed = true;
|
Changed = true;
|
||||||
// If we deleted BB and BB was the header of a loop, then the
|
// If we deleted BB and BB was the header of a loop, then the
|
||||||
// successor is now the header of the loop.
|
// successor is now the header of the loop.
|
||||||
BB = Succ;
|
BB = Succ;
|
||||||
}
|
|
||||||
|
|
||||||
if (ErasedFromLoopHeaders)
|
|
||||||
LoopHeaders.insert(BB);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ErasedFromLoopHeaders)
|
||||||
|
LoopHeaders.insert(BB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EverChanged |= Changed;
|
EverChanged |= Changed;
|
||||||
|
|
Loading…
Reference in New Issue