]> git.ipfire.org Git - thirdparty/gcc.git/commit
AArch64: Suppress default options when march or mcpu used is not affected by it.
authorTamar Christina <tamar.christina@arm.com>
Fri, 29 Nov 2024 13:01:11 +0000 (13:01 +0000)
committerTamar Christina <tamar.christina@arm.com>
Fri, 29 Nov 2024 13:04:16 +0000 (13:04 +0000)
commit5b0e4ed3081e6648460661ff5013e9f03e318505
treef7348267f0843f7075e546bc36317c1c71717fb2
parent7028b1b368a688a3a29f37b9977f238f03fd2d03
AArch64: Suppress default options when march or mcpu used is not affected by it.

This patch makes it so that when you use any of the Cortex-A53 errata
workarounds but have specified an -march or -mcpu we know is not affected by it
that we suppress the errata workaround.

This is a driver only patch as the linker invocation needs to be changed as
well.  The linker and cc SPECs are different because for the linker we didn't
seem to add an inversion flag for the option.  That said, it's also not possible
to configure the linker with it on by default.  So not passing the flag is
sufficient to turn it off.

For the compilers however we have an inversion flag using -mno-, which is needed
to disable the workarounds when the compiler has been configured with it by
default.

In case it's unclear how the patch does what it does (it took me a while to
figure out the syntax):

  * Early matching will replace any -march=native or -mcpu=native with their
    expanded forms and erases the native arguments from the buffer.
  * Due to the above if we ensure we handle the new code after this erasure then
    we only have to handle the expanded form.
  * The expanded form needs to handle -march=<arch>+extensions and
    -mcpu=<cpu>+extensions and so we can't use normal string matching but
    instead use strstr with a custom driver function that's common between
    native and non-native builds.
  * For the compilers we output -mno-<workaround> and for the linker we just
  erase the --fix-<workaround> option.
  * The extra internal matching, e.g. the duplicate match of mcpu inside:
  mcpu=*:%{%:is_local_not_armv8_base(%{mcpu=*:%*}) is so we can extract the glob
  using %* because the outer match would otherwise reset at the %{.  The reason
  for the outer glob at all is to skip the block early if no matches are found.

The workaround has the effect of suppressing certain inlining and multiply-add
formation which leads to about ~1% SPECCPU 2017 Intrate regression on modern
cores.  This patch is needed because most distros configure GCC with the
workaround enabled by default.

Expected output:

> gcc -mcpu=neoverse-v1 -mfix-cortex-a53-835769 -xc - -O3 -o - < /dev/null -### 2>&1 | grep "\-mfix" | wc -l
0

> gcc -mfix-cortex-a53-835769 -xc - -O3 -o - < /dev/null -### 2>&1 | grep "\-mfix" | wc -l
5

> gcc -mfix-cortex-a53-835769 -march=armv8-a -xc - -O3 -o - < /dev/null -### 2>&1 | grep "\-mfix" | wc -l
5

> gcc -mfix-cortex-a53-835769 -march=armv8.1-a -xc - -O3 -o - < /dev/null -### 2>&1 | grep "\-mfix" | wc -l
0

> gcc -mfix-cortex-a53-835769 -march=armv8.1-a -xc - -O3 -o - < /dev/null -### 2>&1 | grep "\-\-fix" | wc -l
0

> gcc -mfix-cortex-a53-835769 -march=armv8-a -xc - -O3 -o - < /dev/null -### 2>&1 | grep "\-\-fix" | wc -l
1

> -gcc -mfix-cortex-a53-835769 -xc - -O3 -o - < /dev/null -### 2>&1 | grep "\-\-fix" | wc -l
1

gcc/ChangeLog:

* config/aarch64/aarch64-errata.h (TARGET_SUPPRESS_OPT_SPEC,
TARGET_TURN_OFF_OPT_SPEC, CA53_ERR_835769_COMPILE_SPEC,
CA53_ERR_843419_COMPILE_SPEC): New.
(CA53_ERR_835769_SPEC, CA53_ERR_843419_SPEC): Use them.
* config/aarch64/aarch64-elf-raw.h (CC1_SPEC, CC1PLUS_SPEC): Add
AARCH64_ERRATA_COMPILE_SPEC.
* config/aarch64/aarch64-freebsd.h (CC1_SPEC, CC1PLUS_SPEC): Likewise.
* config/aarch64/aarch64-gnu.h (CC1_SPEC, CC1PLUS_SPEC): Likewise.
* config/aarch64/aarch64-linux.h (CC1_SPEC, CC1PLUS_SPEC): Likewise.
* config/aarch64/aarch64-netbsd.h (CC1_SPEC, CC1PLUS_SPEC): Likewise.
* common/config/aarch64/aarch64-common.cc
(is_host_cpu_not_armv8_base): New.
* config/aarch64/driver-aarch64.cc: Remove extra newline
* config/aarch64/aarch64.h (is_host_cpu_not_armv8_base): New.
(MCPU_TO_MARCH_SPEC_FUNCTIONS): Add is_local_not_armv8_base.
(EXTRA_SPEC_FUNCTIONS): Add is_local_cpu_armv8_base.
* doc/invoke.texi: Document it.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/cpunative/info_30: New test.
* gcc.target/aarch64/cpunative/info_31: New test.
* gcc.target/aarch64/cpunative/info_32: New test.
* gcc.target/aarch64/cpunative/info_33: New test.
* gcc.target/aarch64/cpunative/native_cpu_30.c: New test.
* gcc.target/aarch64/cpunative/native_cpu_31.c: New test.
* gcc.target/aarch64/cpunative/native_cpu_32.c: New test.
* gcc.target/aarch64/cpunative/native_cpu_33.c: New test.
* gcc.target/aarch64/erratas_opt_0.c: New test.
* gcc.target/aarch64/erratas_opt_1.c: New test.
* gcc.target/aarch64/erratas_opt_10.c: New test.
* gcc.target/aarch64/erratas_opt_11.c: New test.
* gcc.target/aarch64/erratas_opt_12.c: New test.
* gcc.target/aarch64/erratas_opt_13.c: New test.
* gcc.target/aarch64/erratas_opt_14.c: New test.
* gcc.target/aarch64/erratas_opt_15.c: New test.
* gcc.target/aarch64/erratas_opt_2.c: New test.
* gcc.target/aarch64/erratas_opt_3.c: New test.
* gcc.target/aarch64/erratas_opt_4.c: New test.
* gcc.target/aarch64/erratas_opt_5.c: New test.
* gcc.target/aarch64/erratas_opt_6.c: New test.
* gcc.target/aarch64/erratas_opt_7.c: New test.
* gcc.target/aarch64/erratas_opt_8.c: New test.
* gcc.target/aarch64/erratas_opt_9.c: New test.
34 files changed:
gcc/common/config/aarch64/aarch64-common.cc
gcc/config/aarch64/aarch64-elf-raw.h
gcc/config/aarch64/aarch64-errata.h
gcc/config/aarch64/aarch64-freebsd.h
gcc/config/aarch64/aarch64-gnu.h
gcc/config/aarch64/aarch64-linux.h
gcc/config/aarch64/aarch64-netbsd.h
gcc/config/aarch64/aarch64.h
gcc/config/aarch64/driver-aarch64.cc
gcc/doc/invoke.texi
gcc/testsuite/gcc.target/aarch64/cpunative/info_30 [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/cpunative/info_31 [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/cpunative/info_32 [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/cpunative/info_33 [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_30.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_31.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_32.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/cpunative/native_cpu_33.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_0.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_10.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_11.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_12.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_13.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_14.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_15.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/erratas_opt_9.c [new file with mode: 0644]