public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra
@ 2024-01-07 16:08 sjames at gcc dot gnu.org
  2024-01-07 16:09 ` [Bug target/113257] " sjames at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-01-07 16:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257

            Bug ID: 113257
           Summary: -march=native or -mcpu=native are ineffective, but
                    -march=native -mcpu=native works on arm64 M2 Ultra
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

Created attachment 57002
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57002&action=edit
/proc/cpuinfo

On arm64 M2 Ultra (Apple Mac Studio (M2 Ultra, 2023)), -march=native or
-mcpu=native are ineffective, but -march=native -mcpu=native together works:
```
# gcc -v -E -x c /dev/null -o /dev/null -march=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64 -dumpbase null

# gcc -v -E -x c /dev/null -o /dev/null -mcpu=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64 -dumpbase null

# gcc -v -E -x c /dev/null -o /dev/null -march=native -mcpu=native 2>&1 | grep
/cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64
-march=armv8-a+crc+lse+rcpc+rdma+dotprod+aes+sha3+fp16fml+sb+ssbs+i8mm+bf16+flagm+pauth
-dumpbase null
```

```
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-unknown-linux-gnu/13/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with:
/tmp/portage/sys-devel/gcc-13.2.1_p20231216/work/gcc-13-20231216/configure
--host=aarch64-unknown-linux-gnu --build=aarch64-unknown-linux-gnu
--prefix=/usr --bindir=/usr/aarch64-unknown-linux-gnu/gcc-bin/13
--includedir=/usr/lib/gcc/aarch64-unknown-linux-gnu/13/include
--datadir=/usr/share/gcc-data/aarch64-unknown-linux-gnu/13
--mandir=/usr/share/gcc-data/aarch64-unknown-linux-gnu/13/man
--infodir=/usr/share/gcc-data/aarch64-unknown-linux-gnu/13/info
--with-gxx-include-dir=/usr/lib/gcc/aarch64-unknown-linux-gnu/13/include/g++-v13
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/aarch64-unknown-linux-gnu/13/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--disable-libunwind-exceptions --enable-checking=release
--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo
13.2.1_p20231216 p11' --with-gcc-major-version-only --enable-libstdcxx-time
--enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --disable-multilib
--disable-fixed-point --enable-libgomp --disable-libssp --disable-libada
--disable-cet --disable-systemtap --disable-valgrind-annotations
--disable-vtable-verify --disable-libvtv --without-zstd --without-isl
--enable-default-pie --enable-default-ssp --disable-bootstrap
--with-build-config=bootstrap-O3
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.1 20231216 (Gentoo 13.2.1_p20231216 p11) 
```

This came up first downstream at https://bugs.gentoo.org/830165#c11.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/113257] -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra
  2024-01-07 16:08 [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra sjames at gcc dot gnu.org
@ 2024-01-07 16:09 ` sjames at gcc dot gnu.org
  2024-01-08 10:49 ` rearnsha at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-01-07 16:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257

--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
FWIW, I did try a patch per
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110901#c4 as a quick hack in case
it's the same issue, but it didn't help:
```
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -1421,7 +1421,7 @@ extern const char *host_detect_local_cpu (int argc, const
char **argv);
   CONFIG_TUNE_SPEC

 #define MCPU_TO_MARCH_SPEC \
-   " %{mcpu=*:-march=%:rewrite_mcpu(%{mcpu=*:%*})}"
+   " %{!march=*:%{mcpu=*:-march=%:rewrite_mcpu(%{mcpu=*:%*})}}"

 extern const char *aarch64_rewrite_mcpu (int argc, const char **argv);
 #define MCPU_TO_MARCH_SPEC_FUNCTIONS \
```

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/113257] -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra
  2024-01-07 16:08 [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra sjames at gcc dot gnu.org
  2024-01-07 16:09 ` [Bug target/113257] " sjames at gcc dot gnu.org
@ 2024-01-08 10:49 ` rearnsha at gcc dot gnu.org
  2024-01-08 11:02 ` sjames at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2024-01-08 10:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257

--- Comment #2 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
For -mcpu=native, the manual says:

Additionally on native AArch64 GNU/Linux systems the value
@samp{native} tunes performance to the host system.  This option has no effect
if the compiler is unable to recognize the processor of the host system.

With similar working for -march=native

Since nobody has contributed patches to recognize the Apple Silicon cores, I
suspect that is the source of the problem.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/113257] -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra
  2024-01-07 16:08 [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra sjames at gcc dot gnu.org
  2024-01-07 16:09 ` [Bug target/113257] " sjames at gcc dot gnu.org
  2024-01-08 10:49 ` rearnsha at gcc dot gnu.org
@ 2024-01-08 11:02 ` sjames at gcc dot gnu.org
  2024-01-08 11:35 ` rearnsha at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-01-08 11:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257

--- Comment #3 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Richard Earnshaw from comment #2)
I'm missing why the combination then works though?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/113257] -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra
  2024-01-07 16:08 [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra sjames at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-01-08 11:02 ` sjames at gcc dot gnu.org
@ 2024-01-08 11:35 ` rearnsha at gcc dot gnu.org
  2024-02-22 18:35 ` tnfchris at gcc dot gnu.org
  2024-02-26 16:48 ` sjames at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2024-01-08 11:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257

--- Comment #4 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
I'm not sure.  My understanding was that -march=native started by looking up
the CPU ID first and then using the internal mapping of that CPU to the
architecture (which can't work if we don't recognize the CPU), but perhaps we
try a bit harder when both are specified.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/113257] -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra
  2024-01-07 16:08 [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra sjames at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-01-08 11:35 ` rearnsha at gcc dot gnu.org
@ 2024-02-22 18:35 ` tnfchris at gcc dot gnu.org
  2024-02-26 16:48 ` sjames at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2024-02-22 18:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257

--- Comment #5 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
(In reply to Sam James from comment #3)
> (In reply to Richard Earnshaw from comment #2)
> I'm missing why the combination then works though?

So we've made several changes here over time.

-mcpu=native does attempt to find the core id to know what it is, but since
GCC-12 we also enable extensions that don't have a requirement on an
architecture.

So for instance on an SVE capable core we would enable it, but we of course
can't enable a tuning model.

But between GCC 13 and GCC 14 many things have changes.  It looks like GCC-14
works as expected:

> ./install/bin/gcc -xc -S -o - - -march=native < /dev/null
        .arch
armv8-a+flagm+dotprod+rdma+lse+crc+aes+sha3+fp16fml+rcpc+i8mm+bf16+sb+ssbs+pauth
        .file   "<stdin>"
        .text
        .ident  "GCC: (GNU) 14.0.1 20240129 (experimental)"                    
                                                                               
                                                                               
                                     .section       
.note.GNU-stack,"",@progbits

> ./install/bin/gcc -xc -S -o - - -mcpu=native < /dev/null
        .arch
armv8-a+flagm+dotprod+rdma+lse+crc+aes+sha3+fp16fml+rcpc+i8mm+bf16+sb+ssbs+pauth
        .file   "<stdin>"
        .text
        .ident  "GCC: (GNU) 14.0.1 20240129 (experimental)"                    
                                                                               
                                                                               
                                     .section       
.note.GNU-stack,"",@progbits

> ./install/bin/gcc -xc -S -o - - -mcpu=native -march=native < /dev/null
        .arch
armv8-a+flagm+dotprod+rdma+lse+crc+aes+sha3+fp16fml+rcpc+i8mm+bf16+sb+ssbs+pauth
        .file   "<stdin>"
        .text
        .ident  "GCC: (GNU) 14.0.1 20240129 (experimental)"                    
                                                                               
                                                                               
                                     .section       
.note.GNU-stack,"",@progbits

So first question is, can you confirm it does for GCC-14 for you too?

In the meantime I'll try GCC-13

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/113257] -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra
  2024-01-07 16:08 [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra sjames at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-02-22 18:35 ` tnfchris at gcc dot gnu.org
@ 2024-02-26 16:48 ` sjames at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-02-26 16:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257

--- Comment #6 from Sam James <sjames at gcc dot gnu.org> ---
Created attachment 57546
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57546&action=edit
gcc 14 test results

$ gcc-13 --version
gcc-13 (Gentoo 13.2.1_p20240210 p13) 13.2.1 20240210
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc-13 -v -E -x c /dev/null -o /dev/null -march=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64 -dumpbase null

$ gcc-13 -v -E -x c /dev/null -o /dev/null -mcpu=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64 -dumpbase null

$ gcc-13 -v -E -x c /dev/null -o /dev/null -march=native -mcpu=native 2>&1 |
grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64
-march=armv8-a+crc+lse+rcpc+rdma+dotprod+aes+sha3+fp16fml+sb+ssbs+i8mm+bf16+flagm+pauth
-dumpbase null

$ gcc-14 --version
gcc-14 (Gentoo 14.0.1_pre20240211-r1 p22) 14.0.1 20240211 (experimental)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc-14 -v -E -x c /dev/null -o /dev/null -march=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/14/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64 -dumpbase null

$ gcc-14 -v -E -x c /dev/null -o /dev/null -mcpu=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/14/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64 -dumpbase null

$ gcc-14 -v -E -x c /dev/null -o /dev/null -march=native -mcpu=native 2>&1 |
grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/14/cc1 -E -quiet -v /dev/null -o
/dev/null -mlittle-endian -mabi=lp64
-march=armv8-a+flagm+dotprod+rdma+lse+crc+aes+sha3+fp16fml+rcpc+i8mm+bf16+sb+ssbs+pauth
-dumpbase null

Still hosed :(

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-26 16:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-07 16:08 [Bug target/113257] New: -march=native or -mcpu=native are ineffective, but -march=native -mcpu=native works on arm64 M2 Ultra sjames at gcc dot gnu.org
2024-01-07 16:09 ` [Bug target/113257] " sjames at gcc dot gnu.org
2024-01-08 10:49 ` rearnsha at gcc dot gnu.org
2024-01-08 11:02 ` sjames at gcc dot gnu.org
2024-01-08 11:35 ` rearnsha at gcc dot gnu.org
2024-02-22 18:35 ` tnfchris at gcc dot gnu.org
2024-02-26 16:48 ` sjames at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).