- if (Function *F = II->getCalledFunction())
- if (DoesNotUnwind.count(CG[F])) {
- SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
- // Insert a call instruction before the invoke.
- CallInst *Call = new CallInst(II->getCalledValue(),
- &Args[0], Args.size(), "", II);
- Call->takeName(II);
- Call->setCallingConv(II->getCallingConv());
-
- // Anything that used the value produced by the invoke instruction
- // now uses the value produced by the call instruction.
- II->replaceAllUsesWith(Call);
- BasicBlock *UnwindBlock = II->getUnwindDest();
- UnwindBlock->removePredecessor(II->getParent());
-
- // Insert a branch to the normal destination right before the
- // invoke.
- new BranchInst(II->getNormalDest(), II);
-
- // Finally, delete the invoke instruction!
- BB->getInstList().pop_back();
+ if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(F)) {
+ BasicBlock *UnwindBlock = II->getUnwindDest();
+ removeUnwindEdge(&*BB);