From eff5e69c82096812acec0c5c6f135c755a1632d2 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 20 Feb 2011 18:05:56 +0000 Subject: Make RecursivelyDeleteDeadPHINode delete a phi node that has no users and add a test for that. With this change, test/CodeGen/X86/codegen-dce.ll no longer finds any instructions to DCE, so delete the test. Also renamed J and JP to I and IP in RecursivelyDeleteDeadPHINode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126088 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/Local.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lib/Transforms/Utils/Local.cpp') diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 063c76e952..20d798948e 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -283,6 +283,11 @@ static bool areAllUsesEqual(Instruction *I) { /// delete it. If that makes any of its operands trivially dead, delete them /// too, recursively. Return true if the PHI node is actually deleted. bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) { + if (PN->use_empty()) { + PN->eraseFromParent(); + return true; + } + // We can remove a PHI if it is on a cycle in the def-use graph // where each node in the cycle has degree one, i.e. only one use, // and is an instruction with no side effects. @@ -292,16 +297,16 @@ bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) { bool Changed = false; SmallPtrSet PHIs; PHIs.insert(PN); - for (Instruction *J = cast(*PN->use_begin()); - areAllUsesEqual(J) && !J->mayHaveSideEffects(); - J = cast(*J->use_begin())) + for (Instruction *I = cast(*PN->use_begin()); + areAllUsesEqual(I) && !I->mayHaveSideEffects(); + I = cast(*I->use_begin())) // If we find a PHI more than once, we're on a cycle that // won't prove fruitful. - if (PHINode *JP = dyn_cast(J)) - if (!PHIs.insert(JP)) { + if (PHINode *IP = dyn_cast(I)) + if (!PHIs.insert(IP)) { // Break the cycle and delete the PHI and its operands. - JP->replaceAllUsesWith(UndefValue::get(JP->getType())); - (void)RecursivelyDeleteTriviallyDeadInstructions(JP); + IP->replaceAllUsesWith(UndefValue::get(IP->getType())); + (void)RecursivelyDeleteTriviallyDeadInstructions(IP); Changed = true; break; } -- cgit v1.2.3