From: Duncan Sands Date: Mon, 21 Feb 2011 17:32:05 +0000 (+0000) Subject: If the phi node was used by an unreachable instruction that ends up using X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2cfbf018a938d14126b9cb10c600e025f9831d2d;p=oota-llvm.git If the phi node was used by an unreachable instruction that ends up using itself without going via a phi node then we could return false here in spite of making a change. Also, tweak the comment because this method can (and always could) return true without deleting the original phi node. For example, if the phi node was used by a read-only invoke instruction which is used by another phi node phi2 which is only used by and only uses the invoke, then phi2 would be deleted but not the invoke instruction and not the original phi node. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126129 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Transforms/Utils/Local.h b/include/llvm/Transforms/Utils/Local.h index 26b5dd8365f..2823fbb7199 100644 --- a/include/llvm/Transforms/Utils/Local.h +++ b/include/llvm/Transforms/Utils/Local.h @@ -60,7 +60,7 @@ bool RecursivelyDeleteTriviallyDeadInstructions(Value *V); /// dead PHI node, due to being a def-use chain of single-use nodes that /// either forms a cycle or is terminated by a trivially dead instruction, /// delete it. If that makes any of its operands trivially dead, delete them -/// too, recursively. Return true if the PHI node is actually deleted. +/// too, recursively. Return true if a change was made. bool RecursivelyDeleteDeadPHINode(PHINode *PN); diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 40a56b0c99a..3f789fa8658 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -282,7 +282,7 @@ static bool areAllUsesEqual(Instruction *I) { /// dead PHI node, due to being a def-use chain of single-use nodes that /// either forms a cycle or is terminated by a trivially dead instruction, /// delete it. If that makes any of its operands trivially dead, delete them -/// too, recursively. Return true if the PHI node is actually deleted. +/// too, recursively. Return true if a change was made. bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) { SmallPtrSet Visited; for (Instruction *I = PN; areAllUsesEqual(I) && !I->mayHaveSideEffects(); @@ -295,7 +295,8 @@ bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) { if (!Visited.insert(I)) { // Break the cycle and delete the instruction and its operands. I->replaceAllUsesWith(UndefValue::get(I->getType())); - return RecursivelyDeleteTriviallyDeadInstructions(I); + (void)RecursivelyDeleteTriviallyDeadInstructions(I); + return true; } } return false;