From f05ac1dcb998e870466a5dba2dce9cac3eb7cee9 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Mon, 6 Jul 2026 21:01:44 -0400 Subject: [PATCH 1/3] tests: catch up with LLVM returning f128 on the stack In LLVM 22 the x64 MSVC ABI wasn't matched and f128 was being directly returned in %xmm0, but now it correctly returns the value via a pointer. --- tests/assembly-llvm/x86_64-windows-float-abi.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/assembly-llvm/x86_64-windows-float-abi.rs b/tests/assembly-llvm/x86_64-windows-float-abi.rs index 51daff56789e6..b6ab9995fdb3e 100644 --- a/tests/assembly-llvm/x86_64-windows-float-abi.rs +++ b/tests/assembly-llvm/x86_64-windows-float-abi.rs @@ -3,6 +3,9 @@ //@ compile-flags: --target x86_64-pc-windows-msvc //@ needs-llvm-components: x86 //@ add-minicore +//@ revisions: LLVM22 LLVM23 +//@ [LLVM22] max-llvm-major-version: 22 +//@ [LLVM23] min-llvm-version: 23 #![feature(f16, f128)] #![feature(no_core)] @@ -37,8 +40,12 @@ pub extern "C" fn second_f64(_: f64, x: f64) -> f64 { } // CHECK-LABEL: second_f128 -// CHECK: movaps (%rdx), %xmm0 -// CHECK-NEXT: retq +// LLVM22: movaps (%rdx), %xmm0 +// LLVM22-NEXT: retq +// LLVM23: movq %rcx, %rax +// LLVM23-NEXT: movaps (%r8), %xmm0 +// LLVM23-NEXT: movaps %xmm0, (%rcx) +// LLVM23-NEXT: retq #[no_mangle] pub extern "C" fn second_f128(_: f128, x: f128) -> f128 { x From 04c6eddaa78a45511b543ca934c27384e7b0b9c1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 7 Jul 2026 16:42:27 +0000 Subject: [PATCH 2/3] x86_64-win: Return f128 on the stack, matching LLVM We can start matching the codegen introduced by LLVM at [1]. This alone isn't enough to make f128 functional on the platform because libcalls use the LLVM ABI. Current behavior originally introduced in RUST-128388. [1]: https://github.com/llvm/llvm-project/commit/aa47e59245e24edb6d0c7d5f91b3a1c5a7bb35f1 --- compiler/rustc_target/src/callconv/x86_win64.rs | 8 ++------ tests/assembly-llvm/x86_64-windows-float-abi.rs | 13 ++++--------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_target/src/callconv/x86_win64.rs b/compiler/rustc_target/src/callconv/x86_win64.rs index cece9d032b53a..c0916727126e1 100644 --- a/compiler/rustc_target/src/callconv/x86_win64.rs +++ b/compiler/rustc_target/src/callconv/x86_win64.rs @@ -1,4 +1,4 @@ -use rustc_abi::{BackendRepr, Float, Integer, Primitive, Size, TyAbiInterface}; +use rustc_abi::{BackendRepr, Integer, Primitive, Size, TyAbiInterface}; use crate::callconv::{ArgAbi, FnAbi, Reg}; use crate::spec::{HasTargetSpec, RustcAbi}; @@ -35,11 +35,7 @@ where // FIXME(#134288): This may change for the `-msvc` targets in the future. a.cast_to(Reg::opaque_vector(Size::from_bits(128))); } - } else if a.layout.size.bytes() > 8 - && !matches!(scalar.primitive(), Primitive::Float(Float::F128)) - { - // Match what LLVM does for `f128` so that `compiler-builtins` builtins match up - // with what LLVM expects. + } else if a.layout.size.bytes() > 8 { a.make_indirect(); } else { a.extend_integer_width_to(32); diff --git a/tests/assembly-llvm/x86_64-windows-float-abi.rs b/tests/assembly-llvm/x86_64-windows-float-abi.rs index b6ab9995fdb3e..3b9d85b279ca7 100644 --- a/tests/assembly-llvm/x86_64-windows-float-abi.rs +++ b/tests/assembly-llvm/x86_64-windows-float-abi.rs @@ -3,9 +3,6 @@ //@ compile-flags: --target x86_64-pc-windows-msvc //@ needs-llvm-components: x86 //@ add-minicore -//@ revisions: LLVM22 LLVM23 -//@ [LLVM22] max-llvm-major-version: 22 -//@ [LLVM23] min-llvm-version: 23 #![feature(f16, f128)] #![feature(no_core)] @@ -40,12 +37,10 @@ pub extern "C" fn second_f64(_: f64, x: f64) -> f64 { } // CHECK-LABEL: second_f128 -// LLVM22: movaps (%rdx), %xmm0 -// LLVM22-NEXT: retq -// LLVM23: movq %rcx, %rax -// LLVM23-NEXT: movaps (%r8), %xmm0 -// LLVM23-NEXT: movaps %xmm0, (%rcx) -// LLVM23-NEXT: retq +// CHECK: movq %rcx, %rax +// CHECK-NEXT: movaps (%r8), %xmm0 +// CHECK-NEXT: movaps %xmm0, (%rcx) +// CHECK-NEXT: retq #[no_mangle] pub extern "C" fn second_f128(_: f128, x: f128) -> f128 { x From 23a594cff71aba2543dc2e075d9d48c96c9c8a1a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 7 Jul 2026 16:50:00 +0000 Subject: [PATCH 3/3] x86_64-win: Enable f128 on LLVM 23+ LLVM23 includes the ABI fix to make f128 work [1]. That version isn't yet stable, but at least the type will start getting picked up in top-of-tree CI. While addressing this, also update the comment regarding f16. [1]: https://github.com/llvm/llvm-project/commit/aa47e59245e24edb6d0c7d5f91b3a1c5a7bb35f1 --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 73b7f699b606d..61e503101fe89 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -369,7 +369,8 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { cfg.has_reliable_f16 = match (target_arch, target_os) { // Unsupported (fixed in llvm22) (Arch::Arm64EC, _) if major < 22 => false, - // MinGW ABI bugs + // MinGW ABI bugs resolved in GCC 16 + // but our toolchain hasn't been updated. (Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm => { false } @@ -397,8 +398,10 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) { (Arch::PowerPC | Arch::PowerPC64, _) => false, // ABI unsupported (fixed in llvm22) (Arch::Sparc, _) if major < 22 => false, - // MinGW ABI bugs - (Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm => { + // MinGW ABI bugs (fixed in llvm23) + (Arch::X86_64, Os::Windows) + if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm && major < 23 => + { false } // There are no known problems on other platforms, so the only requirement is that symbols