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 datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
8 ; CHECK-LABEL: _Z3foov:
9 ; CHECK-NEXT: .functype _Z3foov () -> (i32){{$}}
10 ; CHECK-NEXT: i32.const $push0=, 1{{$}}
11 ; CHECK-NEXT: {{^}} i32.call $push1=, _Znwm, $pop0{{$}}
12 ; CHECK-NEXT: {{^}} i32.call $push2=, _ZN5AppleC1Ev, $pop1{{$}}
13 ; CHECK-NEXT: return $pop2{{$}}
14 %class.Apple = type { i8 }
15 declare noalias i8* @_Znwm(i32)
16 declare %class.Apple* @_ZN5AppleC1Ev(%class.Apple* returned)
17 define %class.Apple* @_Z3foov() {
19 %call = tail call noalias i8* @_Znwm(i32 1)
20 %0 = bitcast i8* %call to %class.Apple*
21 %call1 = tail call %class.Apple* @_ZN5AppleC1Ev(%class.Apple* %0)
25 ; CHECK-LABEL: _Z3barPvS_l:
26 ; CHECK-NEXT: .functype _Z3barPvS_l (i32, i32, i32) -> (i32){{$}}
27 ; CHECK-NEXT: {{^}} i32.call $push0=, memcpy, $0, $1, $2{{$}}
28 ; CHECK-NEXT: return $pop0{{$}}
29 declare i8* @memcpy(i8* returned, i8*, i32)
30 define i8* @_Z3barPvS_l(i8* %p, i8* %s, i32 %n) {
32 %call = tail call i8* @memcpy(i8* %p, i8* %s, i32 %n)
36 ; Test that the optimization isn't performed on constant arguments.
38 ; CHECK-LABEL: test_constant_arg:
39 ; CHECK: i32.const $push0=, global{{$}}
40 ; CHECK-NEXT: {{^}} i32.call $drop=, returns_arg, $pop0{{$}}
41 ; CHECK-NEXT: return{{$}}
42 @global = external global i32
43 @addr = global i32* @global
44 define void @test_constant_arg() {
45 %call = call i32* @returns_arg(i32* @global)
48 declare i32* @returns_arg(i32* returned)
50 ; Test that the optimization isn't performed on arguments without the
51 ; "returned" attribute.
53 ; CHECK-LABEL: test_other_skipped:
54 ; CHECK-NEXT: .functype test_other_skipped (i32, i32, f64) -> (){{$}}
55 ; CHECK-NEXT: {{^}} i32.call $drop=, do_something, $0, $1, $2{{$}}
56 ; CHECK-NEXT: {{^}} call do_something_with_i32, $1{{$}}
57 ; CHECK-NEXT: {{^}} call do_something_with_double, $2{{$}}
58 declare i32 @do_something(i32 returned, i32, double)
59 declare void @do_something_with_i32(i32)
60 declare void @do_something_with_double(double)
61 define void @test_other_skipped(i32 %a, i32 %b, double %c) {
62 %call = call i32 @do_something(i32 %a, i32 %b, double %c)
63 call void @do_something_with_i32(i32 %b)
64 call void @do_something_with_double(double %c)
68 ; Test that the optimization is performed on arguments other than the first.
70 ; CHECK-LABEL: test_second_arg:
71 ; CHECK-NEXT: .functype test_second_arg (i32, i32) -> (i32){{$}}
72 ; CHECK-NEXT: {{^}} i32.call $push0=, do_something_else, $0, $1{{$}}
73 ; CHECK-NEXT: return $pop0{{$}}
74 declare i32 @do_something_else(i32, i32 returned)
75 define i32 @test_second_arg(i32 %a, i32 %b) {
76 %call = call i32 @do_something_else(i32 %a, i32 %b)