diff options
| author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-25 17:11:47 +0000 |
|---|---|---|
| committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-06-25 17:11:47 +0000 |
| commit | 07594cba7c91a7bd498925041a73ea5eb7fd0ec2 (patch) | |
| tree | 133323e55443ecd1941ae7faa1c2d56ac9ff4a32 /llvm/lib | |
| parent | 9ecc8761bceabd5b6392d3473c1bf181160cb2a3 (diff) | |
| download | bcm5719-llvm-07594cba7c91a7bd498925041a73ea5eb7fd0ec2.tar.gz bcm5719-llvm-07594cba7c91a7bd498925041a73ea5eb7fd0ec2.zip | |
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)
llvm-svn: 159146
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/VMCore/Verifier.cpp | 3 |
3 files changed, 17 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 269ea1516ff..07793ac6b5f 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -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); } diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp index a66b3e38258..594369780ac 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -157,11 +157,16 @@ static bool MarkAliveBlocks(BasicBlock *BB, } // Turn invokes that call 'nounwind' functions into ordinary calls. - if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) - if (II->doesNotThrow()) { + if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) { + Value *Callee = II->getCalledValue(); + if (isa<ConstantPointerNull>(Callee) || isa<UndefValue>(Callee)) { + ChangeToUnreachable(II, true); + Changed = true; + } else if (II->doesNotThrow()) { ChangeToCall(II); Changed = true; } + } Changed |= ConstantFoldTerminator(BB, true); for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index 477b81dc67f..9a9b0b7e0b3 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -1636,7 +1636,8 @@ void Verifier::visitInstruction(Instruction &I) { if (Function *F = dyn_cast<Function>(I.getOperand(i))) { // Check to make sure that the "address of" an intrinsic function is never // taken. - Assert1(!F->isIntrinsic() || (i + 1 == e && isa<CallInst>(I)), + CallSite CS(&I); + Assert1(!F->isIntrinsic() || (CS && i == (CS.isCall() ? e-1 : 2)), "Cannot take the address of an intrinsic!", &I); Assert1(F->getParent() == Mod, "Referencing function in another module!", &I); |

