blob: 316d7555e927d7b003b43bfa01b23d40d3e46ea1 [file] [log] [blame]
Matthijs Kooijman1e0eea12008-06-24 16:30:26 +00001; RUN: llvm-as < %s | opt -deadargelim -die | llvm-dis > %t
2; RUN: cat %t | not grep DEAD
3; RUN: cat %t | grep LIVE | count 4
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004
Tanya Lattner4c4d0b82008-03-01 09:15:35 +00005@P = external global i32 ; <i32*> [#uses=1]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006
Tanya Lattner4c4d0b82008-03-01 09:15:35 +00007; Dead arg only used by dead retval
8define internal i32 @test(i32 %DEADARG) {
9 ret i32 %DEADARG
Dan Gohmanf17a25c2007-07-18 16:29:46 +000010}
11
Tanya Lattner4c4d0b82008-03-01 09:15:35 +000012define internal i32 @test2(i32 %DEADARG) {
13 %DEADRETVAL = call i32 @test( i32 %DEADARG ) ; <i32> [#uses=1]
14 ret i32 %DEADRETVAL
Dan Gohmanf17a25c2007-07-18 16:29:46 +000015}
16
Tanya Lattner4c4d0b82008-03-01 09:15:35 +000017define void @test3(i32 %X) {
18 %DEADRETVAL = call i32 @test2( i32 %X ) ; <i32> [#uses=0]
19 ret void
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020}
21
Tanya Lattner4c4d0b82008-03-01 09:15:35 +000022define internal i32 @foo() {
23 %DEAD = load i32* @P ; <i32> [#uses=1]
24 ret i32 %DEAD
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025}
26
Tanya Lattner4c4d0b82008-03-01 09:15:35 +000027define internal i32 @id(i32 %X) {
28 ret i32 %X
Dan Gohmanf17a25c2007-07-18 16:29:46 +000029}
30
Tanya Lattner4c4d0b82008-03-01 09:15:35 +000031define void @test4() {
32 %DEAD = call i32 @foo( ) ; <i32> [#uses=1]
33 %DEAD2 = call i32 @id( i32 %DEAD ) ; <i32> [#uses=0]
34 ret void
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035}
Matthijs Kooijman1e0eea12008-06-24 16:30:26 +000036
37; These test if returning another functions return value properly marks that
38; other function's return value as live. We do this twice, with the functions in
39; different orders (ie, first the caller, than the callee and first the callee
40; and then the caller) since DAE processes functions one by one and handles
41; these cases slightly different.
42
43define internal i32 @test5() {
44 ret i32 123
45}
46
47define i32 @test6() {
48 %LIVE = call i32 @test5()
49 ret i32 %LIVE
50}
51
52define i32 @test7() {
53 %LIVE = call i32 @test8()
54 ret i32 %LIVE
55}
56
57define internal i32 @test8() {
58 ret i32 124
59}