[llvm-commits] [llvm] r126088 - in /llvm/trunk: lib/Transforms/Utils/Local.cpp test/CodeGen/X86/codegen-dce.ll unittests/Transforms/Utils/Local.cpp
Nick Lewycky
nicholas at mxc.ca
Sun Feb 20 10:05:56 PST 2011
Author: nicholas
Date: Sun Feb 20 12:05:56 2011
New Revision: 126088
URL: http://llvm.org/viewvc/llvm-project?rev=126088&view=rev
Log:
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.
Removed:
llvm/trunk/test/CodeGen/X86/codegen-dce.ll
Modified:
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/unittests/Transforms/Utils/Local.cpp
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=126088&r1=126087&r2=126088&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Sun Feb 20 12:05:56 2011
@@ -283,6 +283,11 @@
/// 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 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;
}
Removed: llvm/trunk/test/CodeGen/X86/codegen-dce.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/codegen-dce.ll?rev=126087&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/codegen-dce.ll (original)
+++ llvm/trunk/test/CodeGen/X86/codegen-dce.ll (removed)
@@ -1,43 +0,0 @@
-; RUN: llc < %s -march=x86 -stats |& grep {codegen-dce} | grep {Number of dead instructions deleted}
-
- %struct.anon = type { [3 x double], double, %struct.node*, [64 x %struct.bnode*], [64 x %struct.bnode*] }
- %struct.bnode = type { i16, double, [3 x double], i32, i32, [3 x double], [3 x double], [3 x double], double, %struct.bnode*, %struct.bnode* }
- %struct.node = type { i16, double, [3 x double], i32, i32 }
-
-define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {
-entry:
- %0 = malloc %struct.anon ; <%struct.anon*> [#uses=2]
- %1 = getelementptr %struct.anon* %0, i32 0, i32 2 ; <%struct.node**> [#uses=1]
- br label %bb14.i
-
-bb14.i: ; preds = %bb14.i, %entry
- %i8.0.reg2mem.0.i = phi i32 [ 0, %entry ], [ %2, %bb14.i ] ; <i32> [#uses=1]
- %2 = add i32 %i8.0.reg2mem.0.i, 1 ; <i32> [#uses=2]
- %exitcond74.i = icmp eq i32 %2, 32 ; <i1> [#uses=1]
- br i1 %exitcond74.i, label %bb32.i, label %bb14.i
-
-bb32.i: ; preds = %bb32.i, %bb14.i
- %tmp.0.reg2mem.0.i = phi i32 [ %indvar.next63.i, %bb32.i ], [ 0, %bb14.i ] ; <i32> [#uses=1]
- %indvar.next63.i = add i32 %tmp.0.reg2mem.0.i, 1 ; <i32> [#uses=2]
- %exitcond64.i = icmp eq i32 %indvar.next63.i, 64 ; <i1> [#uses=1]
- br i1 %exitcond64.i, label %bb47.loopexit.i, label %bb32.i
-
-bb.i.i: ; preds = %bb47.loopexit.i
- unreachable
-
-stepsystem.exit.i: ; preds = %bb47.loopexit.i
- store %struct.node* null, %struct.node** %1, align 4
- br label %bb.i6.i
-
-bb.i6.i: ; preds = %bb.i6.i, %stepsystem.exit.i
- br i1 false, label %bb107.i.i, label %bb.i6.i
-
-bb107.i.i: ; preds = %bb107.i.i, %bb.i6.i
- %q_addr.0.i.i.in = phi %struct.bnode** [ null, %bb107.i.i ], [ %3, %bb.i6.i ] ; <%struct.bnode**> [#uses=0]
- br label %bb107.i.i
-
-bb47.loopexit.i: ; preds = %bb32.i
- %3 = getelementptr %struct.anon* %0, i32 0, i32 4, i32 0 ; <%struct.bnode**> [#uses=1]
- %4 = icmp eq %struct.node* null, null ; <i1> [#uses=1]
- br i1 %4, label %stepsystem.exit.i, label %bb.i.i
-}
Modified: llvm/trunk/unittests/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Local.cpp?rev=126088&r1=126087&r2=126088&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/Local.cpp Sun Feb 20 12:05:56 2011
@@ -42,6 +42,11 @@
EXPECT_EQ(&bb0->front(), br0);
EXPECT_EQ(&bb1->front(), br1);
+ builder.SetInsertPoint(bb0);
+ phi = builder.CreatePHI(Type::getInt32Ty(C));
+
+ EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));
+
bb0->dropAllReferences();
bb1->dropAllReferences();
delete bb0;
More information about the llvm-commits
mailing list