1; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s 2 3; Test that the "returned" attribute is optimized effectively. 4 5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" 6target triple = "wasm32-unknown-unknown" 7 8; CHECK-LABEL: _Z3foov: 9; CHECK-NEXT: .functype _Z3foov () -> (i32){{$}} 10; CHECK-NEXT: i32.const $push0=, 1{{$}} 11; CHECK-NEXT: {{^}} call $push1=, _Znwm, $pop0{{$}} 12; CHECK-NEXT: {{^}} call $push2=, _ZN5AppleC1Ev, $pop1{{$}} 13; CHECK-NEXT: return $pop2{{$}} 14%class.Apple = type { i8 } 15declare noalias i8* @_Znwm(i32) 16declare %class.Apple* @_ZN5AppleC1Ev(%class.Apple* returned) 17define %class.Apple* @_Z3foov() { 18entry: 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) 22 ret %class.Apple* %0 23} 24 25; CHECK-LABEL: _Z3barPvS_l: 26; CHECK-NEXT: .functype _Z3barPvS_l (i32, i32, i32) -> (i32){{$}} 27; CHECK-NEXT: {{^}} call $push0=, memcpy, $0, $1, $2{{$}} 28; CHECK-NEXT: return $pop0{{$}} 29declare i8* @memcpy(i8* returned, i8*, i32) 30define i8* @_Z3barPvS_l(i8* %p, i8* %s, i32 %n) { 31entry: 32 %call = tail call i8* @memcpy(i8* %p, i8* %s, i32 %n) 33 ret i8* %p 34} 35 36; Test that the optimization isn't performed on constant arguments. 37 38; CHECK-LABEL: test_constant_arg: 39; CHECK: i32.const $push0=, global{{$}} 40; CHECK-NEXT: {{^}} call $drop=, returns_arg, $pop0{{$}} 41; CHECK-NEXT: return{{$}} 42@global = external global i32 43@addr = global i32* @global 44define void @test_constant_arg() { 45 %call = call i32* @returns_arg(i32* @global) 46 ret void 47} 48declare i32* @returns_arg(i32* returned) 49 50; Test that the optimization isn't performed on arguments without the 51; "returned" attribute. 52 53; CHECK-LABEL: test_other_skipped: 54; CHECK-NEXT: .functype test_other_skipped (i32, i32, f64) -> (){{$}} 55; CHECK-NEXT: {{^}} 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{{$}} 58declare i32 @do_something(i32 returned, i32, double) 59declare void @do_something_with_i32(i32) 60declare void @do_something_with_double(double) 61define 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) 65 ret void 66} 67 68; Test that the optimization is performed on arguments other than the first. 69 70; CHECK-LABEL: test_second_arg: 71; CHECK-NEXT: .functype test_second_arg (i32, i32) -> (i32){{$}} 72; CHECK-NEXT: {{^}} call $push0=, do_something_else, $0, $1{{$}} 73; CHECK-NEXT: return $pop0{{$}} 74declare i32 @do_something_else(i32, i32 returned) 75define i32 @test_second_arg(i32 %a, i32 %b) { 76 %call = call i32 @do_something_else(i32 %a, i32 %b) 77 ret i32 %b 78} 79