Skip to content

Commit 53cd5cf

Browse files
Stylie777mstorsjo
andauthored
[Clang][ARM] Ensure FPU Features are parsed when targeting cc1as (#134612)
Previously, `cc1as` did not consider the Features that can be included from a target's FPU. This could lead to a situation where assembly files could not compile as cc1as did not know if a feature was supported. With this change, all the features for the FPU will be passed to `cc1as` as `-target-feature` lines. By making this change, it will enable `+nosimd` to be functional, worked on in #130623, and fix a regression introduced in 8fa0f0e so armv7s-apple-darwin targets can utilise VFPv4 correctly. --------- Co-authored-by: Martin Storsjö <[email protected]>
1 parent cf188d6 commit 53cd5cf

File tree

6 files changed

+111
-27
lines changed

6 files changed

+111
-27
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Potentially Breaking Changes
3838
- Fix missing diagnostics for uses of declarations when performing typename access,
3939
such as when performing member access on a '[[deprecated]]' type alias.
4040
(#GH58547)
41+
- For ARM targets when compiling assembly files, the features included in the selected CPU
42+
or Architecture's FPU are included. If you wish not to use a specific feature,
43+
the relevant ``+no`` option will need to be amended to the command line option.
4144

4245
C/C++ Language Potentially Breaking Changes
4346
-------------------------------------------
@@ -512,6 +515,7 @@ X86 Support
512515

513516
Arm and AArch64 Support
514517
^^^^^^^^^^^^^^^^^^^^^^^
518+
- For ARM targets, cc1as now considers the FPU's features for the selected CPU or Architecture.
515519

516520
Android Support
517521
^^^^^^^^^^^^^^^

clang/lib/Driver/ToolChains/Arch/ARM.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -679,21 +679,17 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D,
679679
CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : ArchArgFPUKind;
680680
(void)llvm::ARM::getFPUFeatures(FPUKind, Features);
681681
} else {
682-
bool Generic = true;
683-
if (!ForAS) {
684-
std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
685-
if (CPU != "generic")
686-
Generic = false;
687-
llvm::ARM::ArchKind ArchKind =
688-
arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
689-
FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
690-
(void)llvm::ARM::getFPUFeatures(FPUKind, Features);
691-
}
682+
std::string CPU = arm::getARMTargetCPU(CPUName, ArchName, Triple);
683+
bool Generic = CPU == "generic";
692684
if (Generic && (Triple.isOSWindows() || Triple.isOSDarwin()) &&
693685
getARMSubArchVersionNumber(Triple) >= 7) {
694686
FPUKind = llvm::ARM::parseFPU("neon");
695-
(void)llvm::ARM::getFPUFeatures(FPUKind, Features);
687+
} else {
688+
llvm::ARM::ArchKind ArchKind =
689+
arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
690+
FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
696691
}
692+
(void)llvm::ARM::getFPUFeatures(FPUKind, Features);
697693
}
698694

699695
// Now we've finished accumulating features from arch, cpu and fpu,

clang/test/Driver/arm-fpu-selection.s

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// REQUIRES: arm-registered-target
2+
/// Ensures that when targeting an ARM target with an Asm file, clang
3+
/// collects the features from the FPU. This is critical in the
4+
/// activation of NEON for supported targets. The Cortex-R52 will be
5+
/// used and tested for VFP and NEON Support
6+
7+
// RUN: %clang -target arm-none-eabi -mcpu=cortex-r52 -c %s -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-STDERR %s --allow-empty
8+
// RUN: %clang -target arm-none-eabi -mcpu=cortex-r52 -c %s -o /dev/null -### 2>&1 | FileCheck --check-prefix=CHECK-TARGET-FEATURES %s
9+
10+
/// Check that no errors or warnings are present when assembling using cc1as.
11+
// CHECK-STDERR-NOT: error:
12+
// CHECK-STDERR-NOT: warning:
13+
14+
/// Check that NEON and VFPV5 have been activated when using Cortex-R52 when using cc1as
15+
// CHECK-TARGET-FEATURES: "-target-feature" "+vfp2sp"
16+
// CHECK-TARGET-FEATURES: "-target-feature" "+vfp3"
17+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8"
18+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8d16"
19+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8d16sp"
20+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8sp"
21+
// CHECK-TARGET-FEATURES: "-target-feature" "+neon"
22+
23+
vadd.f32 s0, s1, s2
24+
vadd.f64 d0, d1, d2
25+
vcvt.u32.f32 s0, s0, #1
26+
vcvt.u32.f64 d0, d0, #1
27+
vcvtb.f32.f16 s0, s1
28+
vcvtb.f64.f16 d0, s1
29+
vfma.f32 s0, s1, s2
30+
vfma.f64 d0, d1, d2
31+
vcvta.u32.f32 s0, s1
32+
vcvta.u32.f64 s0, d1
33+
vadd.f32 q0, q1, q2
34+
vcvt.f32.f16 q0, d1
35+
vfma.f32 q0, q1, q2
36+
vcvta.u32.f32 q0, q1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// Ensure that we can assemble NEON by just specifying an armv7
2+
/// Apple or Windows target.
3+
4+
// REQUIRES: arm-registered-target
5+
// RUN: %clang -c -target armv7-apple-darwin -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-STDERR %s --allow-empty
6+
// RUN: %clang -c -target armv7-apple-darwin -o /dev/null %s -### 2>&1 | FileCheck --check-prefix=CHECK-TARGET-FEATURES %s
7+
// RUN: %clang -c -target armv7-windows -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-STDERR %s --allow-empty
8+
// RUN: %clang -c -target armv7-windows -o /dev/null %s -### 2>&1 | FileCheck --check-prefix=CHECK-TARGET-FEATURES %s
9+
10+
/// Check that no errors or warnings are present when assembling using cc1as.
11+
// CHECK-STDERR-NOT: error:
12+
// CHECK-STDERR-NOT: warning:
13+
14+
// CHECK-TARGET-FEATURES: "-target-feature" "+neon"
15+
16+
vadd.i32 q0, q0, q0
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// Ensure that we can assemble VFPv4 by just specifying an armv7s target.
2+
3+
// REQUIRES: arm-registered-target
4+
// RUN: %clang -c -target armv7s-apple-darwin -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-STDERR %s --allow-empty
5+
// RUN: %clang -c -target armv7s-apple-darwin -o /dev/null %s -### 2>&1 | FileCheck --check-prefix=CHECK-TARGET-FEATURES %s
6+
7+
/// Check that no errors or warnings are present when assembling using cc1as.
8+
// CHECK-STDERR-NOT: error:
9+
// CHECK-STDERR-NOT: warning:
10+
11+
// CHECK-TARGET-FEATURES: "-target-feature" "+vfp4"
12+
13+
vfma.f32 q1, q2, q3

clang/test/Driver/armv8.1m.main.s

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+fp -o /dev/null %s 2>%t
99
# RUN: FileCheck --check-prefix=ERROR-V81M_FP < %t %s
1010
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+nofp -o /dev/null %s 2>%t
11-
# RUN: FileCheck --check-prefix=ERROR-V81M_FP < %t %s
11+
# RUN: FileCheck --check-prefix=ERROR-V81M_NOFP < %t %s
1212
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+fp.dp -o /dev/null %s 2>%t
1313
# RUN: FileCheck --check-prefix=ERROR-V81M_FPDP < %t %s
1414
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+nofp.dp -o /dev/null %s 2>%t
15-
# RUN: FileCheck --check-prefix=ERROR-V81M_FPDP < %t %s
15+
# RUN: FileCheck --check-prefix=ERROR-V81M_NOFPDP < %t %s
1616
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+mve -o /dev/null %s 2>%t
1717
# RUN: FileCheck --check-prefix=ERROR-V81M_MVE < %t %s
1818
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+nomve -o /dev/null %s 2>%t
19-
# RUN: FileCheck --check-prefix=ERROR-V81M_MVE < %t %s
19+
# RUN: FileCheck --check-prefix=ERROR-V81M_NOMVE < %t %s
2020
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+mve+fp -o /dev/null %s 2>%t
2121
# RUN: FileCheck --check-prefix=ERROR-V81M_MVE_FP < %t %s
2222
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+mve.fp -o /dev/null %s 2>%t
2323
# RUN: FileCheck --check-prefix=ERROR-V81M_MVEFP < %t %s
2424
# RUN: not %clang -c -target arm-none-none-eabi -march=armv8.1-m.main+nomve.fp -o /dev/null %s 2>%t
25-
# RUN: FileCheck --check-prefix=ERROR-V81M_MVEFP < %t %s
25+
# RUN: FileCheck --check-prefix=ERROR-V81M_NOMVEFP < %t %s
2626

2727
.syntax unified
2828
.thumb
@@ -35,39 +35,58 @@ qadd r0, r1, r2
3535
# ERROR-V8M: :[[@LINE-1]]:1: error
3636
# ERROR-V81M: :[[@LINE-2]]:1: error
3737
# ERROR-V81M_FP: :[[@LINE-3]]:1: error
38-
# ERROR-V81M_FPDP: :[[@LINE-4]]:1: error
38+
# ERROR-V81M_NOFP: :[[@LINE-4]]:1: error
39+
# ERROR-V81M_FPDP: :[[@LINE-5]]:1: error
40+
# ERROR-V81M_NOFPDP: :[[@LINE-6]]:1: error
41+
# ERROR-V81M_NOMVE: :[[@LINE-7]]:1: error
42+
# ERROR-V81M_NOMVEFP: :[[@LINE-8]]:1: error
3943

4044
vadd.f16 s0, s1, s2
4145
# ERROR-V8M: :[[@LINE-1]]:1: error
42-
# ERROR-V81M: :[[@LINE-2]]:1: error
43-
# ERROR-V81M_DSP: :[[@LINE-3]]:1: error
44-
# ERROR-V81M_MVE: :[[@LINE-4]]:1: error
46+
# ERROR-V81M_NOFP: :[[@LINE-2]]:1: error
4547

4648
vabs.f32 s0, s1
47-
# ERROR-V8M: :[[@LINE-1]]:1: error
48-
# ERROR-V81M: :[[@LINE-2]]:1: error
49-
# ERROR-V81M_DSP: :[[@LINE-3]]:1: error
50-
# ERROR-V81M_MVE: :[[@LINE-4]]:1: error
49+
# ERROR-V81M_NOFP: :[[@LINE-1]]:1: error
5150

52-
vcmp.f64 d0,d1
51+
vabs.s32 q0, q1
5352
# ERROR-V8M: :[[@LINE-1]]:1: error
5453
# ERROR-V81M: :[[@LINE-2]]:1: error
5554
# ERROR-V81M_DSP: :[[@LINE-3]]:1: error
5655
# ERROR-V81M_FP: :[[@LINE-4]]:1: error
57-
# ERROR-V81M_MVE: :[[@LINE-5]]:1: error
58-
# ERROR-V81M_MVE_FP: :[[@LINE-6]]:1: error
59-
# ERROR-V81M_MVEFP: :[[@LINE-7]]:1: error
56+
# ERROR-V81M_NOFP: :[[@LINE-5]]:1: error
57+
# ERROR-V81M_FPDP: :[[@LINE-6]]:1: error
58+
# ERROR-V81M_NOFPDP: :[[@LINE-7]]:1: error
59+
# ERROR-V81M_NOMVE: :[[@LINE-8]]:1: error
60+
# ERROR-V81M_NOMVEFP: :[[@LINE-9]]:1: error
61+
62+
vcmp.f64 d0,d1
63+
# ERROR-V81M: :[[@LINE-1]]:1: error
64+
# ERROR-V81M_DSP: :[[@LINE-2]]:1: error
65+
# ERROR-V81M_FP: :[[@LINE-3]]:1: error
66+
# ERROR-V81M_NOFP: :[[@LINE-4]]:1: error
67+
# ERROR-V81M_NOFPDP: :[[@LINE-5]]:1: error
68+
# ERROR-V81M_MVE: :[[@LINE-6]]:1: error
69+
# ERROR-V81M_NOMVE: :[[@LINE-7]]:1: error
70+
# ERROR-V81M_MVE_FP: :[[@LINE-8]]:1: error
71+
# ERROR-V81M_MVEFP: :[[@LINE-9]]:1: error
72+
# ERROR-V81M_NOMVEFP: :[[@LINE-10]]:1: error
6073

6174
asrl r0, r1, r2
6275
# ERROR-V8M: :[[@LINE-1]]:1: error
6376
# ERROR-V81M: :[[@LINE-2]]:1: error
6477
# ERROR-V81M_DSP: :[[@LINE-3]]:1: error
6578
# ERROR-V81M_FP: :[[@LINE-4]]:1: error
6679
# ERROR-V81M_FPDP: :[[@LINE-5]]:1: error
80+
# ERROR-V81M_NOFPDP: :[[@LINE-6]]:1: error
81+
# ERROR-V81M_NOMVE: :[[@LINE-7]]:1: error
82+
# ERROR-V81M_NOMVEFP: :[[@LINE-8]]:1: error
6783

6884
vcadd.i8 q0, q1, q2, #90
6985
# ERROR-V8M: :[[@LINE-1]]:1: error
7086
# ERROR-V81M: :[[@LINE-2]]:1: error
7187
# ERROR-V81M_DSP: :[[@LINE-3]]:1: error
7288
# ERROR-V81M_FP: :[[@LINE-4]]:1: error
7389
# ERROR-V81M_FPDP: :[[@LINE-5]]:1: error
90+
# ERROR-V81M_NOFPDP: :[[@LINE-6]]:1: error
91+
# ERROR-V81M_NOMVE: :[[@LINE-7]]:1: error
92+
# ERROR-V81M_NOMVEFP: :[[@LINE-8]]:1: error

0 commit comments

Comments
 (0)