diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -106,6 +106,31 @@ return true; } +// Add the default target features implied by the architecture +// version. We should agree with GCC on these. A summary of the +// features can be found at +// https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#AArch64-Options, +// under the description of the option `-march=name`. +static void AddAArch64DefaultFeatures(std::vector &Features, + llvm::AArch64::ArchKind ArchKind) { + switch (ArchKind) { + case llvm::AArch64::ArchKind::ARMV8_6A: + Features.push_back("+i8mm"); + Features.push_back("+bf16"); + LLVM_FALLTHROUGH; + case llvm::AArch64::ArchKind::ARMV8_5A: + Features.push_back("+sb"); + Features.push_back("+ssbs"); + Features.push_back("+predres"); + LLVM_FALLTHROUGH; + // TODO: sort out the remaining cases from 8.4a to 8a. Update test + // cases in clang/test/Driver/aarch64-march-default-features.c + // accordingly. + default: + break; + } +} + static bool getAArch64ArchFeaturesFromMarch(const Driver &D, StringRef March, const ArgList &Args, @@ -114,10 +139,15 @@ std::pair Split = StringRef(MarchLowerCase).split("+"); llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseArch(Split.first); - if (ArchKind == llvm::AArch64::ArchKind::INVALID || - !llvm::AArch64::getArchFeatures(ArchKind, Features) || - (Split.second.size() && - !DecodeAArch64Features(D, Split.second, Features, ArchKind))) + + if (!llvm::AArch64::getArchFeatures(ArchKind, Features)) + return false; + + assert(ArchKind != llvm::AArch64::ArchKind::INVALID && + "Invalid architecture."); + AddAArch64DefaultFeatures(Features, ArchKind); + + if (!DecodeAArch64Features(D, Split.second, Features, ArchKind)) return false; return true; diff --git a/clang/test/Driver/aarch64-cpus.c b/clang/test/Driver/aarch64-cpus.c --- a/clang/test/Driver/aarch64-cpus.c +++ b/clang/test/Driver/aarch64-cpus.c @@ -643,7 +643,7 @@ // GENERICV85A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.5a" // RUN: %clang -target aarch64 -march=armv8.5-a+fp16 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV85A-FP16 %s -// GENERICV85A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.5a" "-target-feature" "+fullfp16" +// GENERICV85A-FP16: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.5a" "-target-feature" "+sb" "-target-feature" "+ssbs" "-target-feature" "+predres" "-target-feature" "+fullfp16" // RUN: %clang -target aarch64 -march=armv8.6a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV86A %s // RUN: %clang -target aarch64 -march=armv8.6-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV86A %s diff --git a/clang/test/Driver/aarch64-march-default-features.c b/clang/test/Driver/aarch64-march-default-features.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/aarch64-march-default-features.c @@ -0,0 +1,27 @@ +// RUN: %clang -target aarch64-linux-gnu -march=armv8.6a -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK-8_6,CHECK-8_5 +// RUN: %clang -target aarch64-linux-gnu -march=armv8.6a+nobf16 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-8_6-NOBF16 +// RUN: %clang -target aarch64-linux-gnu -march=armv8.6a+noi8mm -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-8_6-NOI8MM + +// CHECK-8_6: "-target-feature" "+i8mm" "-target-feature" "+bf16" +// CHECK-8_6-NOBF16-NOT: "-target-feature" "+bf16" +// CHECK-8_6-NOBF16: "-target-feature" "+i8mm" +// CHECK-8_6-NOBF16-SAME: "-target-feature" "-bf16" +// CHECK-8_6-NOI8MM-NOT: "-target-feature" "+i8mm" +// CHECK-8_6-NOI8MM: "-target-feature" "+bf16" +// CHECK-8_6-NOI8MM-SAME: "-target-feature" "-i8mm" + +// RUN: %clang -target aarch64-linux-gnu -march=armv8.5a -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK-8_5 +// RUN: %clang -target aarch64-linux-gnu -march=armv8.5a+nosb -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-8_5-NOSB +// RUN: %clang -target aarch64-linux-gnu -march=armv8.5a+nossbs -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-8_5-NOSSBS +// RUN: %clang -target aarch64-linux-gnu -march=armv8.5a+nopredres -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-8_5-NOPREDRES + +// CHECK-8_5: "-target-feature" "+sb" "-target-feature" "+ssbs" "-target-feature" "+predres" +// CHECK-8_5-NOSB-NOT: "-target-feature" "+sb" +// CHECK-8_5-NOSB: "-target-feature" "+ssbs" "-target-feature" "+predres" +// CHECK-8_5-NOSB-SAME: "-target-feature" "-sb" +// CHECK-8_5-NOSSBS-NOT: "-target-feature" "+ssbs" +// CHECK-8_5-NOSSBS: "-target-feature" "+sb" "-target-feature" "+predres" +// CHECK-8_5-NOSSBS-SAME: "-target-feature" "-ssbs" +// CHECK-8_5-NOPREDRES-NOT: "-target-feature" "+predres" +// CHECK-8_5-NOPREDRES: "-target-feature" "+sb" "-target-feature" "+ssbs" +// CHECK-8_5-NOPREDRES-SAME: "-target-feature" "-predres"