Home | History | Annotate | Download | only in DeadArgElim
      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: opt < %s -deadargelim -instcombine -dce -S | 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 ; Nested return values
     42 define internal {{i32}, {i16, i16}} @test6() {
     43         %A = insertvalue {{i32}, {i16, i16}} undef, i32 1, 0, 0
     44         %B = insertvalue {{i32}, {i16, i16}} %A, i16 2, 1, 0
     45         %C = insertvalue {{i32}, {i16, i16}} %B, i16 3, 1, 1
     46         ret {{i32}, {i16, i16}} %C
     47 }
     48 
     49 define i32 @main() {
     50         %ret = call {i32, i16} @test2()                ; <i32> [#uses=1]
     51         %LIVE = extractvalue {i32, i16} %ret, 0
     52         %DEAD = extractvalue {i32, i16} %ret, 1
     53         %Y = add i32 %LIVE, -123           ; <i32> [#uses=1]
     54         %LIVE2 = call i32 @test3(i16 %DEAD)                ; <i32> [#uses=1]
     55         %Z = add i32 %LIVE2, %Y           ; <i32> [#uses=1]
     56         %ret1 = call { i32, i32, i16 } @test5 ()
     57         %LIVE3 = extractvalue { i32, i32, i16} %ret1, 0
     58         %LIVE4 = extractvalue { i32, i32, i16} %ret1, 1
     59         %DEAD2 = extractvalue { i32, i32, i16} %ret1, 2
     60         %V = add i32 %LIVE3, %LIVE4
     61         %W = add i32 %Z, %V
     62         %ret2 = call { { i32 }, { i16, i16 } } @test6 ()
     63         %LIVE5 = extractvalue { { i32 }, { i16, i16 } } %ret2, 0, 0
     64         %DEAD3 = extractvalue { { i32 }, { i16, i16 } } %ret2, 1, 0
     65         %DEAD4 = extractvalue { { i32 }, { i16, i16 } } %ret2, 1, 1
     66         %Q = add i32 %W, %LIVE5
     67         ret i32 %Q
     68 }
     69