Legalize sret call arguments

This commit is contained in:
teapotd
2020-05-25 19:57:43 +02:00
parent b18846057f
commit 9e70a64728
2 changed files with 31 additions and 6 deletions

View File

@@ -757,12 +757,6 @@ pub fn handle_call_abi(
{ {
legalize_sret_call(isa, pos, sig_ref, inst); legalize_sret_call(isa, pos, sig_ref, inst);
} else { } 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() { if !pos.func.dfg.signatures[sig_ref].returns.is_empty() {
inst = legalize_inst_results(pos, |func, abi_res| { inst = legalize_inst_results(pos, |func, abi_res| {
func.dfg.signatures[sig_ref].returns[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!( debug_assert!(
check_call_signature(&pos.func.dfg, inst).is_ok(), check_call_signature(&pos.func.dfg, inst).is_ok(),
"Signature still wrong: {}, {}{}", "Signature still wrong: {}, {}{}",

View File

@@ -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
}