summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-10-24 12:23:30 +0000
committerDuncan Sands <baldrick@free.fr>2010-10-24 12:23:30 +0000
commit31c803b2ba6333a9db18c384dff6b5da92e1d314 (patch)
tree177f8e66e53927d7cce0970d29414c3d1c680047 /llvm/lib
parent772324971d6d32273fa17f7942c3678a146ba626 (diff)
downloadbcm5719-llvm-31c803b2ba6333a9db18c384dff6b5da92e1d314.tar.gz
bcm5719-llvm-31c803b2ba6333a9db18c384dff6b5da92e1d314.zip
Fix PR8445: a block with no predecessors may be the entry block, in which case
it isn't unreachable and should not be zapped. The check for the entry block was missing in one case: a block containing a unwind instruction. While there, do some small cleanups: "M" is not a great name for a Function* (it would be more appropriate for a Module*), change it to "Fn"; use Fn in more places. llvm-svn: 117224
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 28d7afbf1c3..de1f12ec1b7 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1720,15 +1720,14 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
bool SimplifyCFGOpt::run(BasicBlock *BB) {
bool Changed = false;
- Function *M = BB->getParent();
+ Function *Fn = BB->getParent();
- assert(BB && BB->getParent() && "Block not embedded in function!");
+ assert(BB && Fn && "Block not embedded in function!");
assert(BB->getTerminator() && "Degenerate basic block encountered!");
// Remove basic blocks that have no predecessors (except the entry block)...
// or that just have themself as a predecessor. These are unreachable.
- if ((pred_begin(BB) == pred_end(BB) &&
- &BB->getParent()->getEntryBlock() != BB) ||
+ if ((pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) ||
BB->getSinglePredecessor() == BB) {
DEBUG(dbgs() << "Removing BB: \n" << *BB);
DeleteDeadBlock(BB);
@@ -1798,7 +1797,7 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
// If we eliminated all predecessors of the block, delete the block now.
if (pred_begin(BB) == pred_end(BB))
// We know there are no successors, so just nuke the block.
- M->getBasicBlockList().erase(BB);
+ Fn->getBasicBlockList().erase(BB);
return true;
}
@@ -1847,10 +1846,10 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
Preds.pop_back();
}
- // If this block is now dead, remove it.
- if (pred_begin(BB) == pred_end(BB)) {
+ // If this block is now dead (and isn't the entry block), remove it.
+ if (pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) {
// We know there are no successors, so just nuke the block.
- M->getBasicBlockList().erase(BB);
+ Fn->getBasicBlockList().erase(BB);
return true;
}
@@ -1880,7 +1879,7 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
while (isa<DbgInfoIntrinsic>(BBI))
++BBI;
if (BBI->isTerminator()) // Terminator is the only non-phi instruction!
- if (BB != &BB->getParent()->getEntryBlock())
+ if (BB != &Fn->getEntryBlock())
if (TryToSimplifyUncondBranchFromEmptyBlock(BB))
return true;
@@ -2050,10 +2049,9 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
}
// If this block is now dead, remove it.
- if (pred_begin(BB) == pred_end(BB) &&
- BB != &BB->getParent()->getEntryBlock()) {
+ if (pred_begin(BB) == pred_end(BB) && BB != &Fn->getEntryBlock()) {
// We know there are no successors, so just nuke the block.
- M->getBasicBlockList().erase(BB);
+ Fn->getBasicBlockList().erase(BB);
return true;
}
}
OpenPOWER on IntegriCloud