Skip to content

Commit a5b81d2

Browse files
Stylie777mstorsjo
andcommitted
[Clang] [ARM] Ensure FPU Features are collected when using the Clang Assembler
Previously, FPU features were not collected when forming a list of features for the Assembler. This fixes a regression from 8fa0f0e, which caused VFPv4 to be unavailable if assembling for an armv7s-apple-darwin target. Co-authored-by: Martin Storsjö <[email protected]>
1 parent 2f8b486 commit a5b81d2

File tree

6 files changed

+92
-26
lines changed

6 files changed

+92
-26
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 using cc1as, the features included in the selected CPU or
42+
Arch's FPU are now loaded and utilized. If you wish not to use a specific feature,
43+
this will need appending to the command line used.
4144

4245
C/C++ Language Potentially Breaking Changes
4346
-------------------------------------------
@@ -463,6 +466,7 @@ X86 Support
463466

464467
Arm and AArch64 Support
465468
^^^^^^^^^^^^^^^^^^^^^^^
469+
- For ARM targets, cc1as now considers the FPU's features for the selected CPU or Arch.
466470

467471
Android Support
468472
^^^^^^^^^^^^^^^

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -679,20 +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");
695687
(void)llvm::ARM::getFPUFeatures(FPUKind, Features);
688+
} else {
689+
llvm::ARM::ArchKind ArchKind =
690+
arm::getLLVMArchKindForARM(CPU, ArchName, Triple);
691+
FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
692+
(void)llvm::ARM::getFPUFeatures(FPUKind, Features);
696693
}
697694
}
698695

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 | count 0
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 NEON and VFPV5 have been activated when using Cortex-R52 when using cc1as
11+
// CHECK-TARGET-FEATURES: "-target-feature" "+vfp2sp"
12+
// CHECK-TARGET-FEATURES: "-target-feature" "+vfp3"
13+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8"
14+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8d16"
15+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8d16sp"
16+
// CHECK-TARGET-FEATURES: "-target-feature" "+fp-armv8sp"
17+
// CHECK-TARGET-FEATURES: "-target-feature" "+neon"
18+
19+
vadd.f32 s0, s1, s2
20+
vadd.f64 d0, d1, d2
21+
vcvt.u32.f32 s0, s0, #1
22+
vcvt.u32.f64 d0, d0, #1
23+
vcvtb.f32.f16 s0, s1
24+
vcvtb.f64.f16 d0, s1
25+
vfma.f32 s0, s1, s2
26+
vfma.f64 d0, d1, d2
27+
vcvta.u32.f32 s0, s1
28+
vcvta.u32.f64 s0, d1
29+
vadd.f32 q0, q1, q2
30+
vcvt.f32.f16 q0, d1
31+
vfma.f32 q0, q1, q2
32+
vcvta.u32.f32 q0, q1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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
6+
// RUN: %clang -c -target armv7-windows -o /dev/null %s
7+
8+
vadd.i32 q0, q0, q0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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
5+
6+
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)