diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-02-24 10:02:16 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-02-24 10:02:16 +0000 |
commit | ec72e3722033762fdbf828f1ff8ec2cf406411c8 (patch) | |
tree | 3850d5f3e50e062601f573ea65632fb7f394042f /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | e2ad73759d80376f3d450d05843bd86ac408c221 (diff) | |
download | bcm5719-llvm-ec72e3722033762fdbf828f1ff8ec2cf406411c8.tar.gz bcm5719-llvm-ec72e3722033762fdbf828f1ff8ec2cf406411c8.zip |
[SimplifyCFG] Do not blindly remove unreachable blocks
DeleteDeadBlock was called indiscriminately, leading to cleanuprets with
undef cleanuppad references.
Instead, try to drain the BB of most of it's instructions if it is
unreachable. We can then remove the BB if it solely consists of a
terminator (and maybe some phis).
llvm-svn: 261731
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index dc56ebb08d1..7a3d368f34c 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -5278,9 +5278,17 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) { if ((pred_empty(BB) && BB != &BB->getParent()->getEntryBlock()) || BB->getSinglePredecessor() == BB) { - DEBUG(dbgs() << "Removing BB: \n" << *BB); - DeleteDeadBlock(BB); - return true; + // Get the block mostly empty. + Changed |= removeAllNonTerminatorAndEHPadInstructions(BB) > 0; + // Now, verify that we succeeded getting the block empty. + // This will not be the case if this unreachable BB creates a token which is + // consumed by other unreachable blocks. + Instruction *FirstNonPHI = BB->getFirstNonPHI(); + if (isa<TerminatorInst>(FirstNonPHI) && FirstNonPHI->use_empty()) { + DEBUG(dbgs() << "Removing BB: \n" << *BB); + DeleteDeadBlock(BB); + return true; + } } // Check to see if we can constant propagate this terminator instruction |