1; RUN: opt < %s -deadargelim -dce -S > %t
2; RUN: cat %t | not grep DEAD
3; RUN: cat %t | grep LIVE | count 4
4
5@P = external global i32                ; <i32*> [#uses=1]
6
7; Dead arg only used by dead retval
8define internal i32 @test(i32 %DEADARG) {
9        ret i32 %DEADARG
10}
11
12define internal i32 @test2(i32 %DEADARG) {
13        %DEADRETVAL = call i32 @test( i32 %DEADARG )            ; <i32> [#uses=1]
14        ret i32 %DEADRETVAL
15}
16
17define void @test3(i32 %X) {
18        %DEADRETVAL = call i32 @test2( i32 %X )         ; <i32> [#uses=0]
19        ret void
20}
21
22define internal i32 @foo() {
23        %DEAD = load i32, i32* @P            ; <i32> [#uses=1]
24        ret i32 %DEAD
25}
26
27define internal i32 @id(i32 %X) {
28        ret i32 %X
29}
30
31define void @test4() {
32        %DEAD = call i32 @foo( )                ; <i32> [#uses=1]
33        %DEAD2 = call i32 @id( i32 %DEAD )              ; <i32> [#uses=0]
34        ret void
35}
36
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}
60