improve optimization of invoke instructions:

- simplifycfg:  invoke undef/null -> unreachable
 - instcombine:  invoke new  -> invoke expect(0, 0)  (an arbitrary NOOP intrinsic;  only done if the allocated memory is unused, of course)
 - verifier:  allow invoke of intrinsics  (to make the previous step work)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159146 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nuno Lopes
2012-06-25 17:11:47 +00:00
parent e8742d084c
commit 3769fe149b
5 changed files with 63 additions and 5 deletions
@@ -1169,7 +1169,14 @@ Instruction *InstCombiner::visitMalloc(Instruction &MI) {
}
if (InvokeInst *II = dyn_cast<InvokeInst>(&MI)) {
BranchInst::Create(II->getNormalDest(), II->getParent());
// Replace invoke with a NOOP intrinsic to maintain the original CFG
Module *M = II->getParent()->getParent()->getParent();
IntegerType *Ty = IntegerType::get(II->getContext(), 8);
ConstantInt *CI = ConstantInt::get(Ty, 0);
Value *Args[] = {CI, CI};
Function *F = Intrinsic::getDeclaration(M, Intrinsic::expect, Ty);
InvokeInst::Create(F, II->getNormalDest(), II->getUnwindDest(), Args,
"dummy", II->getParent());
}
return EraseInstFromFunction(MI);
}