diff --git a/cranelift/codegen/src/legalizer/boundary.rs b/cranelift/codegen/src/legalizer/boundary.rs index 7fb977a06a..185e4c74fa 100644 --- a/cranelift/codegen/src/legalizer/boundary.rs +++ b/cranelift/codegen/src/legalizer/boundary.rs @@ -757,12 +757,6 @@ pub fn handle_call_abi( { legalize_sret_call(isa, pos, sig_ref, inst); } else { - // OK, we need to fix the call arguments to match the ABI signature. - let abi_args = pos.func.dfg.signatures[sig_ref].params.len(); - legalize_inst_arguments(pos, cfg, abi_args, |func, abi_arg| { - func.dfg.signatures[sig_ref].params[abi_arg] - }); - if !pos.func.dfg.signatures[sig_ref].returns.is_empty() { inst = legalize_inst_results(pos, |func, abi_res| { func.dfg.signatures[sig_ref].returns[abi_res] @@ -770,6 +764,13 @@ pub fn handle_call_abi( } } + // Go back and fix the call arguments to match the ABI signature. + pos.goto_inst(inst); + let abi_args = pos.func.dfg.signatures[sig_ref].params.len(); + legalize_inst_arguments(pos, cfg, abi_args, |func, abi_arg| { + func.dfg.signatures[sig_ref].params[abi_arg] + }); + debug_assert!( check_call_signature(&pos.func.dfg, inst).is_ok(), "Signature still wrong: {}, {}{}", diff --git a/cranelift/filetests/filetests/wasm/multi-val-call-legalize-args.clif b/cranelift/filetests/filetests/wasm/multi-val-call-legalize-args.clif new file mode 100644 index 0000000000..b57090d851 --- /dev/null +++ b/cranelift/filetests/filetests/wasm/multi-val-call-legalize-args.clif @@ -0,0 +1,24 @@ +test legalizer +target x86_64 haswell + +;; Test if arguments are legalized if function uses sret + +function %call_indirect_with_split_arg(i64, i64, i64) { + ; check: ss0 = sret_slot 32 + sig0 = (i128) -> i64, i64, i64, i64 + ; check: sig0 = (i64 [%rsi], i64 [%rdx], i64 sret [%rdi]) -> i64 sret [%rax] fast +block0(v0: i64, v1: i64, v2: i64): + v3 = iconcat v1, v2 + v4, v5, v6, v7 = call_indirect sig0, v0(v3) + ; check: v8 = stack_addr.i64 ss0 + ; check: v9 = call_indirect sig0, v0(v1, v2, v8) + ; check: v10 = load.i64 notrap aligned v9 + ; check: v4 -> v10 + ; check: v11 = load.i64 notrap aligned v9+8 + ; check: v5 -> v11 + ; check: v12 = load.i64 notrap aligned v9+16 + ; check: v6 -> v12 + ; check: v13 = load.i64 notrap aligned v9+24 + ; check: v7 -> v13 + return +}