diff options
author | Chris Lattner <sabre@nondot.org> | 2002-07-29 23:40:46 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-07-29 23:40:46 +0000 |
commit | a61fab8c6d11bddeacec99c4b21278e1008fd08c (patch) | |
tree | 7043c3a9b19cef1b3e9e4d6f1c1d9440fc16cc9f /lib/Transforms/Scalar/ADCE.cpp | |
parent | 1ad4436cc249e7b426085a97fbc94dc23efb6600 (diff) | |
download | external_llvm-a61fab8c6d11bddeacec99c4b21278e1008fd08c.zip external_llvm-a61fab8c6d11bddeacec99c4b21278e1008fd08c.tar.gz external_llvm-a61fab8c6d11bddeacec99c4b21278e1008fd08c.tar.bz2 |
Add code to ensure that no PHI nodes are left laying around with their
arguments dropped. This fixes bug:
test/Regression/Transforms/ADCE/2002-07-17-PHIAssertion.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3134 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/ADCE.cpp')
-rw-r--r-- | lib/Transforms/Scalar/ADCE.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index bba30a1..56b219a 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -284,9 +284,23 @@ bool ADCE::doADCE() { // sweep over the program can safely delete dead instructions without // other dead instructions still refering to them. // - for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I) - if (!LiveSet.count(I)) // Is this instruction alive? + for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ) + if (!LiveSet.count(I)) { // Is this instruction alive? I->dropAllReferences(); // Nope, drop references... + if (PHINode *PN = dyn_cast<PHINode>(&*I)) { + // We don't want to leave PHI nodes in the program that have + // #arguments != #predecessors, so we remove them now. + // + PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); + + // Delete the instruction... + I = BB->getInstList().erase(I); + } else { + ++I; + } + } else { + ++I; + } } } |