summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-02-20 18:05:56 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-02-20 18:05:56 +0000
commit183c24c51b9afb3fb3607142a7a1fce88719ec8e (patch)
treeaba2a1eaa63f7ff001ef4418bfe2c5b9c2126aa5 /llvm/lib/Transforms/Utils/Local.cpp
parentbd466d404a4f8390bfcbd1cd7eb04952223d1599 (diff)
downloadbcm5719-llvm-183c24c51b9afb3fb3607142a7a1fce88719ec8e.tar.gz
bcm5719-llvm-183c24c51b9afb3fb3607142a7a1fce88719ec8e.zip
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. llvm-svn: 126088
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 063c76e9522..20d798948e2 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/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<PHINode *, 4> PHIs;
PHIs.insert(PN);
- for (Instruction *J = cast<Instruction>(*PN->use_begin());
- areAllUsesEqual(J) && !J->mayHaveSideEffects();
- J = cast<Instruction>(*J->use_begin()))
+ for (Instruction *I = cast<Instruction>(*PN->use_begin());
+ areAllUsesEqual(I) && !I->mayHaveSideEffects();
+ I = cast<Instruction>(*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<PHINode>(J))
- if (!PHIs.insert(JP)) {
+ if (PHINode *IP = dyn_cast<PHINode>(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;
}
OpenPOWER on IntegriCloud