Skip to content

Commit 778ec18

Browse files
committed
x86_win64 ABI: do not use xmm0 with softfloat ABI
1 parent 608e228 commit 778ec18

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

compiler/rustc_target/src/callconv/x86_win64.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind, Size};
1+
use rustc_abi::{BackendRepr, Float, Integer, Primitive};
22

33
use crate::callconv::{ArgAbi, FnAbi, Reg};
44
use crate::spec::HasTargetSpec;
@@ -23,15 +23,11 @@ pub(crate) fn compute_abi_info<Ty>(_cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<
2323
// (probably what clang calls "illegal vectors").
2424
}
2525
BackendRepr::Scalar(scalar) => {
26-
if is_ret && matches!(scalar.primitive(), Primitive::Int(Integer::I128, _)) {
27-
// `i128` is returned in xmm0 by Clang and GCC
28-
// FIXME(#134288): This may change for the `-msvc` targets in the future.
29-
let reg = Reg { kind: RegKind::Vector, size: Size::from_bits(128) };
30-
a.cast_to(reg);
31-
} else if a.layout.size.bytes() > 8
26+
if a.layout.size.bytes() > 8
3227
&& !matches!(scalar.primitive(), Primitive::Float(Float::F128))
28+
&& !(is_ret && matches!(scalar.primitive(), Primitive::Int(Integer::I128, _)))
3329
{
34-
// Match what LLVM does for `f128` so that `compiler-builtins` builtins match up
30+
// Match what LLVM does for `f128` and `i128` (the latter only for return values) so that `compiler-builtins` builtins match up
3531
// with what LLVM expects.
3632
a.make_indirect();
3733
} else {

tests/codegen/i128-x86-callconv.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
//@ compile-flags: -Copt-level=1
55

66
//@ add-core-stubs
7-
//@ revisions: MSVC MINGW
7+
//@ revisions: MSVC MINGW softfloat
88
//@ [MSVC] needs-llvm-components: x86
9-
//@ [MINGW] needs-llvm-components: x86
109
//@ [MSVC] compile-flags: --target x86_64-pc-windows-msvc
11-
//@ [MINGW] compile-flags: --target x86_64-pc-windows-gnu
10+
// Use `WIN` as a common prefix for MSVC and MINGW but *not* the softfloat test.
1211
//@ [MSVC] filecheck-flags: --check-prefix=WIN
12+
//@ [MINGW] needs-llvm-components: x86
13+
//@ [MINGW] compile-flags: --target x86_64-pc-windows-gnu
1314
//@ [MINGW] filecheck-flags: --check-prefix=WIN
15+
// The `x86_64-unknown-uefi` target also uses the Windows calling convention,
16+
// but does not have SSE registers available.
17+
//@ [softfloat] needs-llvm-components: x86
18+
//@ [softfloat] compile-flags: --target x86_64-unknown-uefi
1419

1520
#![crate_type = "lib"]
1621
#![no_std]
@@ -28,35 +33,34 @@ extern "C" {
2833
pub extern "C" fn pass(_arg0: u32, arg1: i128) {
2934
// CHECK-LABEL: @pass(
3035
// i128 is passed indirectly on Windows. It should load the pointer to the stack and pass
31-
// a pointer to that allocation.
32-
// WIN-SAME: %_arg0, ptr{{.*}} %arg1)
33-
// WIN: [[PASS:%[_0-9]+]] = alloca [16 x i8], align 16
34-
// WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1
35-
// WIN: store i128 [[LOADED]], ptr [[PASS]]
36-
// WIN: call void @extern_call
36+
// a pointer to that allocation. The softfloat ABI works the same.
37+
// CHECK-SAME: %_arg0, ptr{{.*}} %arg1)
38+
// CHECK: [[PASS:%[_0-9]+]] = alloca [16 x i8], align 16
39+
// CHECK: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1
40+
// CHECK: store i128 [[LOADED]], ptr [[PASS]]
41+
// CHECK: call void @extern_call
3742
unsafe { extern_call(arg1) };
3843
}
3944

4045
// Check that we produce the correct return ABI
4146
#[no_mangle]
4247
pub extern "C" fn ret(_arg0: u32, arg1: i128) -> i128 {
43-
// CHECK-LABEL: @ret(
44-
// i128 is returned in xmm0 on Windows
45-
// FIXME(#134288): This may change for the `-msvc` targets in the future.
46-
// WIN-SAME: i32{{.*}} %_arg0, ptr{{.*}} %arg1)
47-
// WIN: [[LOADED:%[_0-9]+]] = load <16 x i8>, ptr %arg1
48-
// WIN-NEXT: ret <16 x i8> [[LOADED]]
48+
// we use the LLVM native ABI for the return value
49+
// CHECK-LABEL: i128 @ret(
50+
// CHECK-SAME: i32{{.*}} %_arg0, ptr{{.*}} %arg1)
51+
// CHECK: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1
52+
// CHECK-NEXT: ret i128 [[LOADED]]
4953
arg1
5054
}
5155

5256
// Check that we consume the correct return ABI
5357
#[no_mangle]
5458
pub extern "C" fn forward(dst: *mut i128) {
5559
// CHECK-LABEL: @forward
56-
// WIN-SAME: ptr{{.*}} %dst)
57-
// WIN: [[RETURNED:%[_0-9]+]] = tail call <16 x i8> @extern_ret()
58-
// WIN: store <16 x i8> [[RETURNED]], ptr %dst
59-
// WIN: ret void
60+
// CHECK-SAME: ptr{{.*}} %dst)
61+
// CHECK: [[RETURNED:%[_0-9]+]] = tail call {{.*}}i128 @extern_ret()
62+
// CHECK: store i128 [[RETURNED]], ptr %dst
63+
// CHECK: ret void
6064
unsafe { *dst = extern_ret() };
6165
}
6266

@@ -70,10 +74,10 @@ struct RetAggregate {
7074
pub extern "C" fn ret_aggregate(_arg0: u32, arg1: i128) -> RetAggregate {
7175
// CHECK-LABEL: @ret_aggregate(
7276
// Aggregates should also be returned indirectly
73-
// WIN-SAME: ptr{{.*}}sret([32 x i8]){{.*}}[[RET:%[_0-9]+]], i32{{.*}}%_arg0, ptr{{.*}}%arg1)
74-
// WIN: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1
75-
// WIN: [[GEP:%[_0-9]+]] = getelementptr{{.*}}, ptr [[RET]]
76-
// WIN: store i128 [[LOADED]], ptr [[GEP]]
77-
// WIN: ret void
77+
// CHECK-SAME: ptr{{.*}}sret([32 x i8]){{.*}}[[RET:%[_0-9]+]], i32{{.*}}%_arg0, ptr{{.*}}%arg1)
78+
// CHECK: [[LOADED:%[_0-9]+]] = load i128, ptr %arg1
79+
// CHECK: [[GEP:%[_0-9]+]] = getelementptr{{.*}}, ptr [[RET]]
80+
// CHECK: store i128 [[LOADED]], ptr [[GEP]]
81+
// CHECK: ret void
7882
RetAggregate { a: 1, b: arg1 }
7983
}

0 commit comments

Comments
 (0)