From 4f8aaa0928caf36d7982534748c8390c5186d534 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 31 Aug 2011 20:55:20 +0000 Subject: Make sure we aren't deleting the landingpad instruction. The landingpad instruction is required in the landing pad block. Because we're not deleting terminating instructions, the invoke may still jump to here (see Transforms/SCCP/2004-11-16-DeadInvoke.ll). Remove all uses of the landingpad instruction, but keep it around until code-gen can remove the basic block. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138890 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/SCCP.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lib/Transforms/Scalar/SCCP.cpp') diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index cfe750c5fa..3d52afa2e1 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1681,15 +1681,31 @@ FunctionPass *llvm::createSCCPPass() { static void DeleteInstructionInBlock(BasicBlock *BB) { DEBUG(dbgs() << " BasicBlock Dead:" << *BB); ++NumDeadBlocks; - + + // Check to see if there are non-terminating instructions to delete. + if (isa(BB->begin())) + return; + // Delete the instructions backwards, as it has a reduced likelihood of // having to update as many def-use and use-def chains. - while (!isa(BB->begin())) { - Instruction *I = --BasicBlock::iterator(BB->getTerminator()); - + std::vector WorkList; + WorkList.reserve(BB->size()); + BasicBlock::iterator I = --BasicBlock::iterator(BB->getTerminator()); + + while (true) { if (!I->use_empty()) I->replaceAllUsesWith(UndefValue::get(I->getType())); - BB->getInstList().erase(I); + WorkList.push_back(I); + if (I == BB->begin()) + break; + --I; + } + + for (std::vector::iterator + II = WorkList.begin(), IE = WorkList.end(); II != IE; ++II) { + if (isa(*II)) + continue; + BB->getInstList().erase(*II); ++NumInstRemoved; } } -- cgit v1.2.3