1 ; RUN: opt -S -deadargelim %s | FileCheck %s
3 ; Case 0: the basic example: an entire aggregate use is returned, but it's
4 ; actually only used in ways we can eliminate. We gain benefit from analysing
5 ; the "use" and applying its results to all sub-values.
7 ; CHECK-LABEL: define internal void @agguse_dead()
9 define internal { i32, i32 } @agguse_dead() {
10 ret { i32, i32 } { i32 0, i32 1 }
13 define internal { i32, i32 } @test_agguse_dead() {
14 %val = call { i32, i32 } @agguse_dead()
20 ; Case 1: an opaque use of the aggregate exists (in this case dead). Otherwise
21 ; only one value is used, so function can be simplified.
23 ; CHECK-LABEL: define internal i32 @rets_independent_if_agguse_dead()
24 ; CHECK: [[RET:%.*]] = extractvalue { i32, i32 } { i32 0, i32 1 }, 1
25 ; CHECK: ret i32 [[RET]]
27 define internal { i32, i32 } @rets_independent_if_agguse_dead() {
28 ret { i32, i32 } { i32 0, i32 1 }
31 define internal { i32, i32 } @test_rets_independent_if_agguse_dead(i1 %tst) {
32 %val = call { i32, i32 } @rets_independent_if_agguse_dead()
33 br i1 %tst, label %use_1, label %use_aggregate
36 ; This use can be classified as applying only to ret 1.
37 %val0 = extractvalue { i32, i32 } %val, 1
38 call void @callee(i32 %val0)
39 ret { i32, i32 } undef
42 ; This use is assumed to apply to both 0 and 1.
46 ; Case 2: an opaque use of the aggregate exists (in this case *live*). Other
47 ; uses shouldn't matter.
49 ; CHECK-LABEL: define internal { i32, i32 } @rets_live_agguse()
50 ; CHECK: ret { i32, i32 } { i32 0, i32 1 }
52 define internal { i32, i32 } @rets_live_agguse() {
53 ret { i32, i32} { i32 0, i32 1 }
56 define { i32, i32 } @test_rets_live_aggues(i1 %tst) {
57 %val = call { i32, i32 } @rets_live_agguse()
58 br i1 %tst, label %use_1, label %use_aggregate
61 ; This use can be classified as applying only to ret 1.
62 %val0 = extractvalue { i32, i32 } %val, 1
63 call void @callee(i32 %val0)
64 ret { i32, i32 } undef
67 ; This use is assumed to apply to both 0 and 1.
71 declare void @callee(i32)