Restructure dead argument elimination, try #3 :-)
[oota-llvm.git] / test / Transforms / DeadArgElim / multdeadretval.ll
1 ; This test sees if return values (and arguments) are properly removed when they
2 ; are unused. All unused values are typed i16, so we can easily check. We also
3 ; run instcombine to fold insert/extractvalue chains and we run dce to clean up
4 ; any remaining dead stuff.
5 ; RUN: llvm-as < %s | opt -deadargelim -instcombine -dce | llvm-dis | not grep i16
6
7 define internal {i16, i32} @test(i16 %DEADARG) {
8         %A = insertvalue {i16,i32} undef, i16 1, 0
9         %B = insertvalue {i16,i32} %A, i32 1001, 1
10         ret {i16,i32} %B
11 }
12
13 define internal {i32, i16} @test2() {
14         %DEAD = call i16 @test4()
15         %A = insertvalue {i32,i16} undef, i32 1, 0
16         %B = insertvalue {i32,i16} %A, i16 %DEAD, 1
17         ret {i32,i16} %B
18 }
19
20 ; Dead argument, used to check if the second result of test2 is dead even when
21 ; it's used as a dead argument
22 define internal i32 @test3(i16 %A) {
23         %ret = call {i16, i32} @test( i16 %A )                ; <i32> [#uses=0]
24         %DEAD = extractvalue {i16, i32} %ret, 0
25         %LIVE = extractvalue {i16, i32} %ret, 1
26         ret i32 %LIVE
27 }
28
29 define internal i16 @test4() {
30         ret i16 0
31 }
32
33 ; Multiple return values, multiple live return values
34 define internal {i32, i32, i16} @test5() {
35         %A = insertvalue {i32,i32,i16} undef, i32 1, 0
36         %B = insertvalue {i32,i32,i16} %A, i32 2, 1
37         %C = insertvalue {i32,i32,i16} %B, i16 3, 2
38         ret {i32, i32, i16} %C
39 }
40
41 define i32 @main() {
42         %ret = call {i32, i16} @test2()                ; <i32> [#uses=1]
43         %LIVE = extractvalue {i32, i16} %ret, 0
44         %DEAD = extractvalue {i32, i16} %ret, 1
45         %Y = add i32 %LIVE, -123           ; <i32> [#uses=1]
46         %LIVE2 = call i32 @test3(i16 %DEAD)                ; <i32> [#uses=1]
47         %Z = add i32 %LIVE2, %Y           ; <i32> [#uses=1]
48         %ret1 = call { i32, i32, i16 } @test5 ()
49         %LIVE3 = extractvalue { i32, i32, i16} %ret1, 0
50         %LIVE4 = extractvalue { i32, i32, i16} %ret1, 1
51         %DEAD2 = extractvalue { i32, i32, i16} %ret1, 2
52         %V = add i32 %LIVE3, %LIVE4
53         %W = add i32 %Z, %V
54         ret i32 %W
55 }