mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Rollup merge of #163653 - Gelbpunkt:mips64-16-byte-scalar-alignment, r=folkertdev
callconv: mips64: Match GCC for alignment of 16-byte scalars Previously, the calling convention code would not register align 16-byte scalars to even/odd register pairs. It seems like GCC does not differentiate between integer and floating point scalars when calculating whether a scalar is aligned. To our understanding, the MIPS n64 ABI [^1] would require doing so for integer and floating point parameters respectively [^2], but GCC violates the specification here and will happily pass an f128 in an odd-even floating point register pair and therefore sometimes shift following integer arguments due to unnecessary (if the spec is to be believed) inserted integer padding. [^1]: https://web.archive.org/web/20160121005457/http://techpubs.sgi.com/library/manuals/2000/007-2816-005/pdf/007-2816-005.pdf#page=20 [^2]: "This requires that they be passed in even-odd floating point register pairs, even if doing so requires skipping a register parameter" Fixes rust-lang/rust#161679 r? folkertdev cc @beetrees
This commit is contained in:
@@ -118,6 +118,19 @@ where
|
||||
|
||||
if !arg.layout.is_aggregate() {
|
||||
extend_integer_width_mips(arg, 64);
|
||||
|
||||
// We always pad with an integer, even if the primitive is a float. This
|
||||
// conflicts with our reading of the specification, which would require
|
||||
// padding floats with floats and integers with integers.
|
||||
// However, this implementation is consistent with GCC, which means we
|
||||
// are compatible with the de-facto ABI on the platform.
|
||||
if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr {
|
||||
let kind = match scalar.primitive() {
|
||||
Primitive::Int(_, _) | Primitive::Pointer(_) => RegKind::Integer,
|
||||
Primitive::Float(_) => RegKind::Float,
|
||||
};
|
||||
arg.cast_to_and_pad_i32(CastTarget::from(Reg { kind, size }), pad_i32);
|
||||
}
|
||||
} else if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
|
||||
arg.make_indirect();
|
||||
} else if let Some(component) = arg.layout.complex_number(cx)
|
||||
|
||||
33
tests/codegen-llvm/mips64-abi/register-alignment.rs
Normal file
33
tests/codegen-llvm/mips64-abi/register-alignment.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
//@ add-minicore
|
||||
//@ compile-flags: -Copt-level=3
|
||||
//
|
||||
//@ revisions: mips64 mips64el
|
||||
//@[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64
|
||||
//@[mips64el] compile-flags: --target mips64el-unknown-linux-gnuabi64
|
||||
//
|
||||
//@ needs-llvm-components: mips
|
||||
|
||||
// Test that 16-byte scalars are correctly aligned in registers.
|
||||
|
||||
#![feature(f128, lang_items, no_core)]
|
||||
#![crate_type = "lib"]
|
||||
#![no_core]
|
||||
|
||||
extern crate minicore;
|
||||
use minicore::*;
|
||||
|
||||
// CHECK: @i128_gets_aligned(i8 %0, i32 %1, i128 %2)
|
||||
#[no_mangle]
|
||||
extern "C" fn i128_gets_aligned(arg0: u8, arg1: i128) {}
|
||||
|
||||
// CHECK: @i128_is_aligned(i8 %0, i16 %1, i128 %2)
|
||||
#[no_mangle]
|
||||
extern "C" fn i128_is_aligned(arg0: u8, arg1: i16, arg2: i128) {}
|
||||
|
||||
// CHECK: @f128_gets_aligned(i8 %0, i32 %1, fp128 %2)
|
||||
#[no_mangle]
|
||||
extern "C" fn f128_gets_aligned(arg0: u8, arg1: f128) {}
|
||||
|
||||
// CHECK: @f128_is_aligned(i8 %0, float %1, fp128 %2)
|
||||
#[no_mangle]
|
||||
extern "C" fn f128_is_aligned(arg0: u8, arg1: f32, arg2: f128) {}
|
||||
Reference in New Issue
Block a user