1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
3 ; Test that the "returned" attribute is optimized effectively.
5 target triple = "wasm32-unknown-unknown"
7 ; CHECK-LABEL: _Z3foov:
8 ; CHECK-NEXT: .functype _Z3foov () -> (i32){{$}}
9 ; CHECK-NEXT: i32.const $push0=, 1{{$}}
10 ; CHECK-NEXT: {{^}} call $push1=, _Znwm, $pop0{{$}}
11 ; CHECK-NEXT: {{^}} call $push2=, _ZN5AppleC1Ev, $pop1{{$}}
12 ; CHECK-NEXT: return $pop2{{$}}
13 %class.Apple = type { i8 }
14 declare noalias i8* @_Znwm(i32)
15 declare %class.Apple* @_ZN5AppleC1Ev(%class.Apple* returned)
16 define %class.Apple* @_Z3foov() {
18 %call = tail call noalias i8* @_Znwm(i32 1)
19 %0 = bitcast i8* %call to %class.Apple*
20 %call1 = tail call %class.Apple* @_ZN5AppleC1Ev(%class.Apple* %0)
24 ; CHECK-LABEL: _Z3barPvS_l:
25 ; CHECK-NEXT: .functype _Z3barPvS_l (i32, i32, i32) -> (i32){{$}}
26 ; CHECK-NEXT: {{^}} call $push0=, memcpy, $0, $1, $2{{$}}
27 ; CHECK-NEXT: return $pop0{{$}}
28 declare i8* @memcpy(i8* returned, i8*, i32)
29 define i8* @_Z3barPvS_l(i8* %p, i8* %s, i32 %n) {
31 %call = tail call i8* @memcpy(i8* %p, i8* %s, i32 %n)
35 ; Test that the optimization isn't performed on constant arguments.
37 ; CHECK-LABEL: test_constant_arg:
38 ; CHECK: i32.const $push0=, global{{$}}
39 ; CHECK-NEXT: {{^}} call $drop=, returns_arg, $pop0{{$}}
40 ; CHECK-NEXT: return{{$}}
41 @global = external global i32
42 @addr = global i32* @global
43 define void @test_constant_arg() {
44 %call = call i32* @returns_arg(i32* @global)
47 declare i32* @returns_arg(i32* returned)
49 ; Test that the optimization isn't performed on arguments without the
50 ; "returned" attribute.
52 ; CHECK-LABEL: test_other_skipped:
53 ; CHECK-NEXT: .functype test_other_skipped (i32, i32, f64) -> (){{$}}
54 ; CHECK-NEXT: {{^}} call $drop=, do_something, $0, $1, $2{{$}}
55 ; CHECK-NEXT: {{^}} call do_something_with_i32, $1{{$}}
56 ; CHECK-NEXT: {{^}} call do_something_with_double, $2{{$}}
57 declare i32 @do_something(i32 returned, i32, double)
58 declare void @do_something_with_i32(i32)
59 declare void @do_something_with_double(double)
60 define void @test_other_skipped(i32 %a, i32 %b, double %c) {
61 %call = call i32 @do_something(i32 %a, i32 %b, double %c)
62 call void @do_something_with_i32(i32 %b)
63 call void @do_something_with_double(double %c)
67 ; Test that the optimization is performed on arguments other than the first.
69 ; CHECK-LABEL: test_second_arg:
70 ; CHECK-NEXT: .functype test_second_arg (i32, i32) -> (i32){{$}}
71 ; CHECK-NEXT: {{^}} call $push0=, do_something_else, $0, $1{{$}}
72 ; CHECK-NEXT: return $pop0{{$}}
73 declare i32 @do_something_else(i32, i32 returned)
74 define i32 @test_second_arg(i32 %a, i32 %b) {
75 %call = call i32 @do_something_else(i32 %a, i32 %b)