llvm.org GIT mirror llvm / eff5e69
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 Nick Lewycky 9 years ago
3 changed file(s) with 17 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
282282 /// delete it. If that makes any of its operands trivially dead, delete them
283283 /// too, recursively. Return true if the PHI node is actually deleted.
284284 bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
285 if (PN->use_empty()) {
286 PN->eraseFromParent();
287 return true;
288 }
289
285290 // We can remove a PHI if it is on a cycle in the def-use graph
286291 // where each node in the cycle has degree one, i.e. only one use,
287292 // and is an instruction with no side effects.
291296 bool Changed = false;
292297 SmallPtrSet PHIs;
293298 PHIs.insert(PN);
294 for (Instruction *J = cast(*PN->use_begin());
295 areAllUsesEqual(J) && !J->mayHaveSideEffects();
296 J = cast(*J->use_begin()))
299 for (Instruction *I = cast(*PN->use_begin());
300 areAllUsesEqual(I) && !I->mayHaveSideEffects();
301 I = cast(*I->use_begin()))
297302 // If we find a PHI more than once, we're on a cycle that
298303 // won't prove fruitful.
299 if (PHINode *JP = dyn_cast(J))
300 if (!PHIs.insert(JP)) {
304 if (PHINode *IP = dyn_cast(I))
305 if (!PHIs.insert(IP)) {
301306 // Break the cycle and delete the PHI and its operands.
302 JP->replaceAllUsesWith(UndefValue::get(JP->getType()));
303 (void)RecursivelyDeleteTriviallyDeadInstructions(JP);
307 IP->replaceAllUsesWith(UndefValue::get(IP->getType()));
308 (void)RecursivelyDeleteTriviallyDeadInstructions(IP);
304309 Changed = true;
305310 break;
306311 }
+0
-43
test/CodeGen/X86/codegen-dce.ll less more
None ; RUN: llc < %s -march=x86 -stats |& grep {codegen-dce} | grep {Number of dead instructions deleted}
1
2 %struct.anon = type { [3 x double], double, %struct.node*, [64 x %struct.bnode*], [64 x %struct.bnode*] }
3 %struct.bnode = type { i16, double, [3 x double], i32, i32, [3 x double], [3 x double], [3 x double], double, %struct.bnode*, %struct.bnode* }
4 %struct.node = type { i16, double, [3 x double], i32, i32 }
5
6 define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {
7 entry:
8 %0 = malloc %struct.anon ; <%struct.anon*> [#uses=2]
9 %1 = getelementptr %struct.anon* %0, i32 0, i32 2 ; <%struct.node**> [#uses=1]
10 br label %bb14.i
11
12 bb14.i: ; preds = %bb14.i, %entry
13 %i8.0.reg2mem.0.i = phi i32 [ 0, %entry ], [ %2, %bb14.i ] ; [#uses=1]
14 %2 = add i32 %i8.0.reg2mem.0.i, 1 ; [#uses=2]
15 %exitcond74.i = icmp eq i32 %2, 32 ; [#uses=1]
16 br i1 %exitcond74.i, label %bb32.i, label %bb14.i
17
18 bb32.i: ; preds = %bb32.i, %bb14.i
19 %tmp.0.reg2mem.0.i = phi i32 [ %indvar.next63.i, %bb32.i ], [ 0, %bb14.i ] ; [#uses=1]
20 %indvar.next63.i = add i32 %tmp.0.reg2mem.0.i, 1 ; [#uses=2]
21 %exitcond64.i = icmp eq i32 %indvar.next63.i, 64 ; [#uses=1]
22 br i1 %exitcond64.i, label %bb47.loopexit.i, label %bb32.i
23
24 bb.i.i: ; preds = %bb47.loopexit.i
25 unreachable
26
27 stepsystem.exit.i: ; preds = %bb47.loopexit.i
28 store %struct.node* null, %struct.node** %1, align 4
29 br label %bb.i6.i
30
31 bb.i6.i: ; preds = %bb.i6.i, %stepsystem.exit.i
32 br i1 false, label %bb107.i.i, label %bb.i6.i
33
34 bb107.i.i: ; preds = %bb107.i.i, %bb.i6.i
35 %q_addr.0.i.i.in = phi %struct.bnode** [ null, %bb107.i.i ], [ %3, %bb.i6.i ] ; <%struct.bnode**> [#uses=0]
36 br label %bb107.i.i
37
38 bb47.loopexit.i: ; preds = %bb32.i
39 %3 = getelementptr %struct.anon* %0, i32 0, i32 4, i32 0 ; <%struct.bnode**> [#uses=1]
40 %4 = icmp eq %struct.node* null, null ; [#uses=1]
41 br i1 %4, label %stepsystem.exit.i, label %bb.i.i
42 }
4141 EXPECT_EQ(&bb0->front(), br0);
4242 EXPECT_EQ(&bb1->front(), br1);
4343
44 builder.SetInsertPoint(bb0);
45 phi = builder.CreatePHI(Type::getInt32Ty(C));
46
47 EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));
48
4449 bb0->dropAllReferences();
4550 bb1->dropAllReferences();
4651 delete bb0;