[PATCH] aarch64: Fix -march=native when -mtune is used [PR124629]
Alice Carlotti <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
Handling of -march=native for recognised cores was broken by
r13-2937-g00c22ba69d8e73, which added "V" to ARCH_IDENT values and
filtered it out in some locations. This causes a lookup by stringified
ARCH_IDENT values to fail. If no -mtune or -mcpu option is used, then
we avoid this bug by upgrading -march=native to -mcpu=native.
Fix this by removing the '+ 1' string offset, so that the ident strings
match again. It would be marginally more efficient to use enum values
here, but I've stuck with this simpler fix instead.
This is the alternative fix I suggested in my review of Cutie Deng's patch [1],
with an added test case.
Ok for master and backport to all open branches?
[1] https://gcc.gnu.org/pipermail/gcc-patches/2026-March/711748.html
gcc/ChangeLog:
PR target/124629
* config/aarch64/driver-aarch64.cc (AARCH64_ARCH):
Don't skip first character of #ARCH_IDENT.
gcc/testsuite/ChangeLog:
PR target/124629
* gcc.target/aarch64/cpunative/info_36: New test file.
* gcc.target/aarch64/cpunative/native_cpu_36.c: New test.
diff --git a/gcc/config/aarch64/driver-aarch64.cc b/gcc/config/aarch64/driver-aarch64.cc
index 278f26c92194801739c57862de097a3093487de2..300cdceca63c3c98440637258bd85a212b300952 100644
--- a/gcc/config/aarch64/driver-aarch64.cc
+++ b/gcc/config/aarch64/driver-aarch64.cc
@@ -81,7 +81,7 @@ struct aarch64_arch_driver_info
/* Skip the leading "V" in the architecture name. */
#define AARCH64_ARCH(NAME, CORE, ARCH_IDENT, ARCH_REV, FLAGS) \
- { #ARCH_IDENT + 1, NAME, feature_deps::ARCH_IDENT ().enable },
+ { #ARCH_IDENT, NAME, feature_deps::ARCH_IDENT ().enable },
static constexpr const aarch64_arch_driver_info aarch64_arches[] =
{
diff --git a/gcc/testsuite/gcc.target/aarch64/cpunative/info_36 b/gcc/testsuite/gcc.target/aarch64/cpunative/info_36
new file mode 100644
index 0000000000000000000000000000000000000000..620340fdfaeb8d0bdf943a5563603bc04ab88ce4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/cpunative/info_36
@@ -0,0 +1,9 @@
+processor : 0
+BogoMIPS : 100.00
+Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 asimddp sve sve2 fphp asimdhp fcma
+CPU implementer : 0x41
+CPU architecture: 8
+CPU variant : 0x0
+CPU part : 0xd08
+CPU revision : 2
+
diff --git a/gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_36.c b/gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_36.c
new file mode 100644
index 0000000000000000000000000000000000000000..04af5b04ba5f9c2193fd4725ad3aa67d185461ea
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_36.c
@@ -0,0 +1,10 @@
+/* { dg-do compile { target { { aarch64*-*-linux*} && native } } } */
+/* { dg-set-compiler-env-var GCC_CPUINFO "$srcdir/gcc.target/aarch64/cpunative/info_36" } */
+/* { dg-additional-options "-march=native -mtune=cortex-a34" } */
+
+int main()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler {\.arch armv8-a\+dotprod\+crc\+crypto\+sve2\n} } } */