From 92b3987e547c38e89ed7d7933b430fe35401cd92 Mon Sep 17 00:00:00 2001 From: Steffen Butzer Date: Sat, 9 Mar 2019 21:27:55 +0100 Subject: [PATCH] windows/x64 call convention: only use XMM0 for float return values (#691) --- cranelift/codegen/src/isa/x86/abi.rs | 9 +++++---- .../filetests/isa/x86/windows_fastcall_x64.clif | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cranelift/codegen/src/isa/x86/abi.rs b/cranelift/codegen/src/isa/x86/abi.rs index b25c17e1f6..37d9ffb257 100644 --- a/cranelift/codegen/src/isa/x86/abi.rs +++ b/cranelift/codegen/src/isa/x86/abi.rs @@ -161,13 +161,14 @@ pub fn legalize_signature(sig: &mut ir::Signature, triple: &Triple, _current: bo legalize_args(&mut sig.params, &mut args); - let regs = if sig.call_conv == CallConv::WindowsFastcall { - &RET_GPRS_WIN_FASTCALL_X64[..] + let (regs, fpr_limit) = if sig.call_conv == CallConv::WindowsFastcall { + // windows-x64 calling convention only uses XMM0 or RAX for return values + (&RET_GPRS_WIN_FASTCALL_X64[..], 1) } else { - &RET_GPRS[..] + (&RET_GPRS[..], 2) }; - let mut rets = Args::new(bits, regs, 2, sig.call_conv); + let mut rets = Args::new(bits, regs, fpr_limit, sig.call_conv); legalize_args(&mut sig.returns, &mut rets); } diff --git a/cranelift/filetests/filetests/isa/x86/windows_fastcall_x64.clif b/cranelift/filetests/filetests/isa/x86/windows_fastcall_x64.clif index a84c17fb9e..14b46e579f 100644 --- a/cranelift/filetests/filetests/isa/x86/windows_fastcall_x64.clif +++ b/cranelift/filetests/filetests/isa/x86/windows_fastcall_x64.clif @@ -36,4 +36,10 @@ function %mixed_int_float(i64, f64, i64, f32) windows_fastcall { ebb0(v0: i64, v1: f64, v2: i64, v3: f32): return } -; check: function %mixed_int_float(i64 [%rcx], f64 [%xmm1], i64 [%r8], f32 [%xmm3], i64 fp [%rbp]) -> i64 fp [%rbp] windows_fastcall { \ No newline at end of file +; check: function %mixed_int_float(i64 [%rcx], f64 [%xmm1], i64 [%r8], f32 [%xmm3], i64 fp [%rbp]) -> i64 fp [%rbp] windows_fastcall { + +function %ret_val_float(f32, f64, i64, i64) -> f64 windows_fastcall { +ebb0(v0: f32, v1: f64, v2: i64, v3: i64): + return v1 +} +; check: function %ret_val_float(f32 [%xmm0], f64 [%xmm1], i64 [%r8], i64 [%r9], i64 fp [%rbp]) -> f64 [%xmm0], i64 fp [%rbp] windows_fastcall {