[clang] [AArch64][Driver] Enable host supported features with march=native. (PR #177128)
Ricardo Jesus via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 23 07:02:11 PST 2026
https://github.com/rj-jesus updated https://github.com/llvm/llvm-project/pull/177128
>From 1c2fc1fda008661918377763e64c5be98e4201b3 Mon Sep 17 00:00:00 2001
From: Ricardo Jesus <rjj at nvidia.com>
Date: Thu, 15 Jan 2026 03:41:56 -0800
Subject: [PATCH 1/2] [AArch64][Driver] Enable host supported features with
march=native.
Currently, march=native enables the base features implied by the host
system architecture, such as Armv8.2-A, Armv9-A, etc, rather than the
actual features supported by the host (e.g. crypto). This is suboptimal
as it generally leaves optional but supported features disabled.
This patch aligns the behaviour of march=native with mcpu=native by
using the feature decoding logic of the latter to decode the former.
This means both options should enable a similar(*) set of features.
(*) march=native and mcpu=native can still enable slightly different
features due to the former setting -target-cpu generic (compared to the
latter setting -target-cpu <name>) and the generic target enabling Neon
and ETE. This is not new behaviour introduced by this patch, it just
wasn't being tested. These differences can be seen in the updated
`aarch64-mcpu-native.c`.
---
clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 5 +++--
clang/test/Driver/aarch64-mcpu-native.c | 12 ++++++++++++
.../Driver/print-enabled-extensions/aarch64-grace.c | 1 +
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index cc6e408f45e07..9ac070e5e16cd 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -159,10 +159,11 @@ getAArch64ArchFeaturesFromMarch(const Driver &D, StringRef March,
std::string MarchLowerCase = March.lower();
std::pair<StringRef, StringRef> Split = StringRef(MarchLowerCase).split("+");
+ if (Split.first == "native")
+ return DecodeAArch64Mcpu(D, MarchLowerCase, Extensions);
+
const llvm::AArch64::ArchInfo *ArchInfo =
llvm::AArch64::parseArch(Split.first);
- if (Split.first == "native")
- ArchInfo = llvm::AArch64::getArchForCpu(llvm::sys::getHostCPUName().str());
if (!ArchInfo)
return false;
diff --git a/clang/test/Driver/aarch64-mcpu-native.c b/clang/test/Driver/aarch64-mcpu-native.c
index e132081062851..ee88ea6024e97 100644
--- a/clang/test/Driver/aarch64-mcpu-native.c
+++ b/clang/test/Driver/aarch64-mcpu-native.c
@@ -1,6 +1,7 @@
// REQUIRES: aarch64-registered-target,system-linux,aarch64-host
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/neoverse-n1
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-NN1 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-NN1,CHECK-GENERIC-NN1 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-NN1: Extensions enabled for the given AArch64 target
// CHECK-FEAT-NN1-EMPTY:
@@ -10,6 +11,7 @@
// CHECK-FEAT-NN1: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
// CHECK-FEAT-NN1: FEAT_DPB Enable Armv8.2-A data Cache Clean to Point of Persistence
// CHECK-FEAT-NN1: FEAT_DotProd Enable dot product support
+// CHECK-GENERIC-NN1: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-NN1: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-NN1: FEAT_FP16 Enable half-precision floating-point data processing
// CHECK-FEAT-NN1: FEAT_LOR Enable Armv8.1-A Limited Ordering Regions extension
@@ -23,23 +25,28 @@
// CHECK-FEAT-NN1: FEAT_SHA1, FEAT_SHA256 Enable SHA1 and SHA256 support
// CHECK-FEAT-NN1: FEAT_SPE Enable Statistical Profiling extension
// CHECK-FEAT-NN1: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit
+// CHECK-GENERIC-NN1: FEAT_TRBE Enable Trace Buffer Extension
// CHECK-FEAT-NN1: FEAT_UAO Enable Armv8.2-A UAO PState
// CHECK-FEAT-NN1: FEAT_VHE Enable Armv8.1-A Virtual Host extension
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/cortex-a57
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA57 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-CA57,CHECK-GENERIC-CA57 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-CA57: Extensions enabled for the given AArch64 target
// CHECK-FEAT-CA57-EMPTY:
// CHECK-FEAT-CA57: Architecture Feature(s) Description
// CHECK-FEAT-CA57: FEAT_AdvSIMD Enable Advanced SIMD instructions
// CHECK-FEAT-CA57: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
+// CHECK-GENERIC-CA57: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-CA57: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-CA57: FEAT_PMUv3 Enable Armv8.0-A PMUv3 Performance Monitors extension
+// CHECK-GENERIC-CA57: FEAT_TRBE Enable Trace Buffer Extension
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/cortex-a72
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA72 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-CA72,CHECK-GENERIC-CA72 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-CA72: Extensions enabled for the given AArch64 target
// CHECK-EMPTY:
@@ -47,12 +54,15 @@
// CHECK-FEAT-CA72: FEAT_AES, FEAT_PMULL Enable AES support
// CHECK-FEAT-CA72: FEAT_AdvSIMD Enable Advanced SIMD instructions
// CHECK-FEAT-CA72: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
+// CHECK-GENERIC-CA72: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-CA72: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-CA72: FEAT_PMUv3 Enable Armv8.0-A PMUv3 Performance Monitors extension
// CHECK-FEAT-CA72: FEAT_SHA1, FEAT_SHA256 Enable SHA1 and SHA256 support
+// CHECK-GENERIC-CA72: FEAT_TRBE Enable Trace Buffer Extension
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/cortex-a76
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA76 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-CA76,CHECK-GENERIC-CA76 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-CA76: Extensions enabled for the given AArch64 target
// CHECK-FEAT-CA76-EMPTY:
@@ -62,6 +72,7 @@
// CHECK-FEAT-CA76: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
// CHECK-FEAT-CA76: FEAT_DPB Enable Armv8.2-A data Cache Clean to Point of Persistence
// CHECK-FEAT-CA76: FEAT_DotProd Enable dot product support
+// CHECK-GENERIC-CA76: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-CA76: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-CA76: FEAT_FP16 Enable half-precision floating-point data processing
// CHECK-FEAT-CA76: FEAT_LOR Enable Armv8.1-A Limited Ordering Regions extension
@@ -74,5 +85,6 @@
// CHECK-FEAT-CA76: FEAT_RDM Enable Armv8.1-A Rounding Double Multiply Add/Subtract instructions
// CHECK-FEAT-CA76: FEAT_SHA1, FEAT_SHA256 Enable SHA1 and SHA256 support
// CHECK-FEAT-CA76: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit
+// CHECK-GENERIC-CA76: FEAT_TRBE Enable Trace Buffer Extension
// CHECK-FEAT-CA76: FEAT_UAO Enable Armv8.2-A UAO PState
// CHECK-FEAT-CA76: FEAT_VHE Enable Armv8.1-A Virtual Host extension
diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-grace.c b/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
index acb641e3b2c8d..cb7a2466a5fdc 100644
--- a/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
+++ b/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
@@ -1,6 +1,7 @@
// REQUIRES: aarch64-registered-target,aarch64-host,system-linux
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=grace | FileCheck --strict-whitespace --implicit-check-not=FEAT_ %s
// RUN: env LLVM_CPUINFO=%S/../Inputs/cpunative/grace %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --implicit-check-not=FEAT_ %s
+// RUN: env LLVM_CPUINFO=%S/../Inputs/cpunative/grace %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --implicit-check-not=FEAT_ %s
// CHECK: Extensions enabled for the given AArch64 target
// CHECK-EMPTY:
>From e9b54b045cf6c71fe2cc0000dd10d0d4b0b93447 Mon Sep 17 00:00:00 2001
From: Ricardo Jesus <rjj at nvidia.com>
Date: Thu, 22 Jan 2026 08:01:35 -0800
Subject: [PATCH 2/2] Also detect target-cpu with march=native.
---
clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 5 +++++
clang/test/Driver/aarch64-mcpu-native.c | 16 ++++------------
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 9ac070e5e16cd..4aa3743fb5cd5 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -35,6 +35,11 @@ std::string aarch64::getAArch64TargetCPU(const ArgList &Args,
if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
StringRef Mcpu = A->getValue();
CPU = Mcpu.split("+").first.lower();
+ } else if (const Arg *MArch = Args.getLastArg(options::OPT_march_EQ)) {
+ // Otherwise, use -march=native if specified.
+ StringRef MArchValue = MArch->getValue();
+ if (MArchValue.split("+").first.equals_insensitive("native"))
+ CPU = "native";
}
CPU = llvm::AArch64::resolveCPUAlias(CPU);
diff --git a/clang/test/Driver/aarch64-mcpu-native.c b/clang/test/Driver/aarch64-mcpu-native.c
index ee88ea6024e97..c62b5fd34eb49 100644
--- a/clang/test/Driver/aarch64-mcpu-native.c
+++ b/clang/test/Driver/aarch64-mcpu-native.c
@@ -1,7 +1,7 @@
// REQUIRES: aarch64-registered-target,system-linux,aarch64-host
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/neoverse-n1
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-NN1 --implicit-check-not=FEAT_ %s
-// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-NN1,CHECK-GENERIC-NN1 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-NN1 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-NN1: Extensions enabled for the given AArch64 target
// CHECK-FEAT-NN1-EMPTY:
@@ -11,7 +11,6 @@
// CHECK-FEAT-NN1: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
// CHECK-FEAT-NN1: FEAT_DPB Enable Armv8.2-A data Cache Clean to Point of Persistence
// CHECK-FEAT-NN1: FEAT_DotProd Enable dot product support
-// CHECK-GENERIC-NN1: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-NN1: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-NN1: FEAT_FP16 Enable half-precision floating-point data processing
// CHECK-FEAT-NN1: FEAT_LOR Enable Armv8.1-A Limited Ordering Regions extension
@@ -25,28 +24,25 @@
// CHECK-FEAT-NN1: FEAT_SHA1, FEAT_SHA256 Enable SHA1 and SHA256 support
// CHECK-FEAT-NN1: FEAT_SPE Enable Statistical Profiling extension
// CHECK-FEAT-NN1: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit
-// CHECK-GENERIC-NN1: FEAT_TRBE Enable Trace Buffer Extension
// CHECK-FEAT-NN1: FEAT_UAO Enable Armv8.2-A UAO PState
// CHECK-FEAT-NN1: FEAT_VHE Enable Armv8.1-A Virtual Host extension
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/cortex-a57
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA57 --implicit-check-not=FEAT_ %s
-// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-CA57,CHECK-GENERIC-CA57 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA57 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-CA57: Extensions enabled for the given AArch64 target
// CHECK-FEAT-CA57-EMPTY:
// CHECK-FEAT-CA57: Architecture Feature(s) Description
// CHECK-FEAT-CA57: FEAT_AdvSIMD Enable Advanced SIMD instructions
// CHECK-FEAT-CA57: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
-// CHECK-GENERIC-CA57: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-CA57: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-CA57: FEAT_PMUv3 Enable Armv8.0-A PMUv3 Performance Monitors extension
-// CHECK-GENERIC-CA57: FEAT_TRBE Enable Trace Buffer Extension
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/cortex-a72
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA72 --implicit-check-not=FEAT_ %s
-// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-CA72,CHECK-GENERIC-CA72 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA72 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-CA72: Extensions enabled for the given AArch64 target
// CHECK-EMPTY:
@@ -54,15 +50,13 @@
// CHECK-FEAT-CA72: FEAT_AES, FEAT_PMULL Enable AES support
// CHECK-FEAT-CA72: FEAT_AdvSIMD Enable Advanced SIMD instructions
// CHECK-FEAT-CA72: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
-// CHECK-GENERIC-CA72: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-CA72: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-CA72: FEAT_PMUv3 Enable Armv8.0-A PMUv3 Performance Monitors extension
// CHECK-FEAT-CA72: FEAT_SHA1, FEAT_SHA256 Enable SHA1 and SHA256 support
-// CHECK-GENERIC-CA72: FEAT_TRBE Enable Trace Buffer Extension
// RUN: export LLVM_CPUINFO=%S/Inputs/cpunative/cortex-a76
// RUN: %clang --target=aarch64 --print-enabled-extensions -mcpu=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA76 --implicit-check-not=FEAT_ %s
-// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefixes=CHECK-FEAT-CA76,CHECK-GENERIC-CA76 --implicit-check-not=FEAT_ %s
+// RUN: %clang --target=aarch64 --print-enabled-extensions -march=native | FileCheck --strict-whitespace --check-prefix=CHECK-FEAT-CA76 --implicit-check-not=FEAT_ %s
// CHECK-FEAT-CA76: Extensions enabled for the given AArch64 target
// CHECK-FEAT-CA76-EMPTY:
@@ -72,7 +66,6 @@
// CHECK-FEAT-CA76: FEAT_CRC32 Enable Armv8.0-A CRC-32 checksum instructions
// CHECK-FEAT-CA76: FEAT_DPB Enable Armv8.2-A data Cache Clean to Point of Persistence
// CHECK-FEAT-CA76: FEAT_DotProd Enable dot product support
-// CHECK-GENERIC-CA76: FEAT_ETE Enable Embedded Trace Extension
// CHECK-FEAT-CA76: FEAT_FP Enable Armv8.0-A Floating Point Extensions
// CHECK-FEAT-CA76: FEAT_FP16 Enable half-precision floating-point data processing
// CHECK-FEAT-CA76: FEAT_LOR Enable Armv8.1-A Limited Ordering Regions extension
@@ -85,6 +78,5 @@
// CHECK-FEAT-CA76: FEAT_RDM Enable Armv8.1-A Rounding Double Multiply Add/Subtract instructions
// CHECK-FEAT-CA76: FEAT_SHA1, FEAT_SHA256 Enable SHA1 and SHA256 support
// CHECK-FEAT-CA76: FEAT_SSBS, FEAT_SSBS2 Enable Speculative Store Bypass Safe bit
-// CHECK-GENERIC-CA76: FEAT_TRBE Enable Trace Buffer Extension
// CHECK-FEAT-CA76: FEAT_UAO Enable Armv8.2-A UAO PState
// CHECK-FEAT-CA76: FEAT_VHE Enable Armv8.1-A Virtual Host extension
More information about the cfe-commits
mailing list