aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-07-20 01:17:38 +0000
committerChris Lattner <sabre@nondot.org>2004-07-20 01:17:38 +0000
commitaf17b1df84c31cb4f9a09213db9aa3c1e8b910ea (patch)
tree87d28ae8c50375a461e9bb9299226879d3cb4eb9 /lib/Transforms/Utils/SimplifyCFG.cpp
parentc6c9db2fd7a8039f01a103cd5f5b0eae3858a870 (diff)
Implement SimplifyCFG/BrUnwind.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15022 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index cc28e54c37..2cf4ab9cde 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -764,12 +764,19 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
} else if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->begin())) {
// Check to see if the first instruction in this block is just an unwind.
// If so, replace any invoke instructions which use this as an exception
- // destination with call instructions.
+ // destination with call instructions, and any unconditional branch
+ // predecessor with an unwind.
//
std::vector<BasicBlock*> Preds(pred_begin(BB), pred_end(BB));
while (!Preds.empty()) {
BasicBlock *Pred = Preds.back();
- if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
+ if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) {
+ if (BI->isUnconditional()) {
+ Pred->getInstList().pop_back(); // nuke uncond branch
+ new UnwindInst(Pred); // Use unwind.
+ Changed = true;
+ }
+ } else if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
if (II->getUnwindDest() == BB) {
// Insert a new branch instruction before the invoke, because this
// is now a fall through...