Skip to content

Commit e3c3417

Browse files
Rollup merge of #163824 - adamgemmell:dev/adagem01/neon-in-registers, r=davidtwco
aarch64: Use neon registers for ABI on targets that require `neon" This PR is the aarch64 version of #161583. When a target requires the neon feature (which all `aarch64[_be]` hardfloat targets do), pass any vectors that fit (all sized vectors on aarch64 should do) in those registers. We also make disable the `neon` target feature a hard error since doing so is much more likely to result in miscompilations as a result of this change, as the previous patch did for SSE. I've also check the stdarch CI for aarch64-unknown-linux-gnu and aarch64_be-linux-gnu locally with no issues.
2 parents b542750 + 379c47e commit e3c3417

8 files changed

Lines changed: 47 additions & 19 deletions

File tree

‎compiler/rustc_interface/src/util.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub(crate) fn check_abi_required_features(sess: &Session) {
110110
// emit a (less friendly) hard error.
111111
// Also make it a hard error on x86, where we use SSE registers for the "Rust" ABI. The
112112
// post-mono ABI check only systematically checks "C" calls, so we better reject this here.
113-
let hard_error = matches!(sess.target.arch, Arch::Arm | Arch::X86);
113+
let hard_error = matches!(sess.target.arch, Arch::AArch64 | Arch::Arm | Arch::X86);
114114

115115
for feature in abi_feature_constraints.required {
116116
if !sess.internal_target_features.contains(&Symbol::intern(feature)) {

‎compiler/rustc_target/src/callconv/mod.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,10 @@ impl<'a, Ty> FnAbi<'a, Ty> {
809809
// x86-64 non-softfloat targets all require SSE2 so we can use SSE registers.
810810
arg.layout.size.bits() <= 128
811811
}
812-
// So far, we haven't implemented this logic for any other target.
812+
Arch::AArch64 if spec.rustc_abi != Some(RustcAbi::Softfloat) => {
813+
// aarch64 non-softfloat targets all require Neon
814+
arg.layout.size.bits() <= 128
815+
}
813816
_ => false,
814817
};
815818

‎src/tools/compiletest/src/runtest.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,7 @@ impl<'test> TestCx<'test> {
13731373

13741374
rustc.args(&["--crate-type", "rlib"]);
13751375
rustc.arg("-Cpanic=abort");
1376+
rustc.arg("--check-cfg=cfg(target_has_reliable_f16b)");
13761377
rustc.args(self.props.minicore_compile_flags.clone());
13771378

13781379
let res =

‎tests/codegen-llvm/simd-intrinsic/simd-intrinsic-transmute-array.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
//@ ignore-i686-pc-windows-gnu
66

77
// LLVM IR isn't very portable and the one tested here depends on the ABI which is different between
8-
// x86 (where we use SSE registers) and others. `x86-64` and `x86-32-sse2` are identical, but
9-
// compiletest does not support taking the union of multiple `only` annotations.
10-
//@ revisions: x86-64 x86-32-sse2 by-ref
8+
// architectures that pass vectors via registers and others that don't.
9+
// The architecture-specific revisions are identical and only exist as compiletest does not support
10+
// taking the union of multiple `only` annotations.
11+
12+
//@ revisions: x86-64 x86-32-sse2 aarch64 by-ref
13+
1114
//@[x86-64] only-x86_64
1215
//@[x86-64] filecheck-flags: --check-prefix=by-val
1316
//@[x86-32-sse2] only-rustc_abi-x86-sse2
1417
//@[x86-32-sse2] filecheck-flags: --check-prefix=by-val
18+
//@[aarch64] only-aarch64
19+
//@[aarch64] filecheck-flags: --check-prefix=by-val
20+
1521
//@[by-ref] ignore-rustc_abi-x86-sse2
1622
//@[by-ref] ignore-x86_64
23+
//@[by-ref] ignore-aarch64
1724

1825
#![crate_type = "lib"]
1926
#![allow(non_camel_case_types)]

‎tests/codegen-llvm/simd/splat.rs‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
//@ compile-flags: -Copt-level=3
22

33
// LLVM IR isn't very portable and the one tested here depends on the ABI which is different between
4-
// x86 (where we use SSE registers) and others. `x86-64` and `x86-32-sse2` are identical, but
5-
// compiletest does not support taking the union of multiple `only` annotations.
6-
//@ revisions: x86-64 x86-32-sse2 by-ref
4+
// architectures that pass vectors via registers and others that don't.
5+
// The architecture-specific revisions are identical and only exist as compiletest does not support
6+
// taking the union of multiple `only` annotations.
7+
8+
//@ revisions: x86-64 x86-32-sse2 aarch64 by-ref
9+
710
//@[x86-64] only-x86_64
811
//@[x86-64] filecheck-flags: --check-prefix=by-val
912
//@[x86-32-sse2] only-rustc_abi-x86-sse2
1013
//@[x86-32-sse2] filecheck-flags: --check-prefix=by-val
14+
//@[aarch64] only-aarch64
15+
//@[aarch64] filecheck-flags: --check-prefix=by-val
16+
1117
//@[by-ref] ignore-rustc_abi-x86-sse2
1218
//@[by-ref] ignore-x86_64
19+
//@[by-ref] ignore-aarch64
1320

1421
#![crate_type = "lib"]
1522
#![no_std]

‎tests/codegen-llvm/tied-features-strength.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
// ignore-tidy-linelength
22
//@ add-minicore
33
//@ revisions: ENABLE_SVE DISABLE_SVE DISABLE_NEON ENABLE_NEON
4-
//@ compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu
4+
//@ compile-flags: --crate-type=rlib
55
//@ needs-llvm-components: aarch64
66

77
// Rust made SVE require neon.
8+
//@ [ENABLE_SVE] compile-flags: --target=aarch64-unknown-linux-gnu
89
//@ [ENABLE_SVE] compile-flags: -C target-feature=+sve -Copt-level=0
910
// ENABLE_SVE: attributes #0
1011
// ENABLE_SVE-SAME: +neon
1112
// ENABLE_SVE-SAME: +sve
1213

1314
// However, disabling SVE does not disable neon.
15+
//@ [DISABLE_SVE] compile-flags: --target=aarch64-unknown-linux-gnu
1416
//@ [DISABLE_SVE] compile-flags: -C target-feature=-sve -Copt-level=0
1517
// DISABLE_SVE: attributes #0
1618
// DISABLE_SVE-NOT: -neon
1719
// DISABLE_SVE-SAME: -sve
1820

1921
// OTOH, neon fn `fp-armv8` are fully tied; toggling neon must toggle `fp-armv8` the same way.
22+
// Use the softfloat target as neon is a required feature on hardfloat targets
23+
//@ [DISABLE_NEON] compile-flags: --target=aarch64-unknown-none-softfloat
2024
//@ [DISABLE_NEON] compile-flags: -C target-feature=-neon -Copt-level=0
2125
// DISABLE_NEON: attributes #0
2226
// DISABLE_NEON-SAME: -neon
2327
// DISABLE_NEON-SAME: -fp-armv8
2428

29+
//@ [ENABLE_NEON] compile-flags: --target=aarch64-unknown-linux-gnu
2530
//@ [ENABLE_NEON] compile-flags: -C target-feature=+neon -Copt-level=0
2631
// ENABLE_NEON: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fp-armv8,?)|(\+neon,?))*}}" }
2732

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
warning: target feature `neon` must be enabled to ensure that the ABI of the current target can be implemented correctly
2-
|
3-
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4-
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>
1+
error: target feature `neon` must be enabled to ensure that the ABI of the current target can be implemented correctly
52

6-
warning: 1 warning emitted
3+
error: aborting due to 1 previous error
74

‎tests/ui/target-feature/abi-required-target-feature-flag-disable.rs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
//@ revisions: x86 x86-implied aarch64 riscv loongarch
55
//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-x87
66
//@[x86] needs-llvm-components: x86
7+
//@[x86] build-pass
78
//@[x86-implied] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-sse
89
//@[x86-implied] needs-llvm-components: x86
9-
//@[aarch64] compile-flags: --target=aarch64-unknown-linux-gnu -Ctarget-feature=-neon
10-
//@[aarch64] needs-llvm-components: aarch64
10+
//@[x86-implied] build-pass
1111
//@[riscv] compile-flags: --target=riscv64gc-unknown-none-elf -Ctarget-feature=-d
1212
//@[riscv] needs-llvm-components: riscv
13+
//@[riscv] build-pass
1314
//@[loongarch] compile-flags: --target=loongarch64-unknown-none -Ctarget-feature=-d
1415
//@[loongarch] needs-llvm-components: loongarch
15-
// For now this is just a warning.
16-
//@ build-pass
16+
//@[loongarch] build-pass
17+
18+
//@[aarch64] compile-flags: --target=aarch64-unknown-linux-gnu -Ctarget-feature=-neon
19+
//@[aarch64] needs-llvm-components: aarch64
20+
//@[aarch64] minicore-compile-flags: -Ctarget-feature=+neon
21+
// Just a warning on most targets, but a hard error on aarch64
22+
//@[aarch64] check-fail
23+
1724
// Remove some LLVM warnings that only show up sometimes.
1825
//@ normalize-stderr: "\n[^\n]*(target-abi|lp64f)[^\n]*" -> ""
1926
//@ ignore-backends: gcc
@@ -25,4 +32,5 @@
2532
extern crate minicore;
2633
use minicore::*;
2734

28-
//~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly
35+
//[x86,x86-implied,riscv,loongarch]~? WARN must be enabled to ensure that the ABI
36+
//[aarch64]~? ERROR must be enabled to ensure that the ABI

0 commit comments

Comments
 (0)