From: Chris Lattner Date: Tue, 4 May 2004 17:00:46 +0000 (+0000) Subject: Do not mark instructions in unreachable sections of the function as live. X-Git-Tag: android-x86-6.0-r1~1003^2~55404 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b9110c61fb16354c659703870340c020b7c5b10a;p=android-x86%2Fexternal-llvm.git Do not mark instructions in unreachable sections of the function as live. This fixes PR332 and ADCE/2004-05-04-UnreachableBlock.llx git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13349 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 3423fdd4929..98f8bed5160 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -215,8 +215,10 @@ bool ADCE::doADCE() { // instructions live in basic blocks that are unreachable. These blocks will // be eliminated later, along with the instructions inside. // - for (df_iterator BBI = df_begin(Func), BBE = df_end(Func); - BBI != BBE; ++BBI) { + std::set ReachableBBs; + for (df_ext_iterator + BBI = df_ext_begin(&Func->front(), ReachableBBs), + BBE = df_ext_end(&Func->front(), ReachableBBs); BBI != BBE; ++BBI) { BasicBlock *BB = *BBI; for (BasicBlock::iterator II = BB->begin(), EI = BB->end(); II != EI; ) { Instruction *I = II++; @@ -279,6 +281,7 @@ bool ADCE::doADCE() { WorkList.pop_back(); BasicBlock *BB = I->getParent(); + if (!ReachableBBs.count(BB)) continue; if (!AliveBlocks.count(BB)) { // Basic block not alive yet... AliveBlocks.insert(BB); // Block is now ALIVE! markBlockAlive(BB); // Make it so now!