From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1816) id 992243858D37; Wed, 21 Sep 2022 09:11:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 992243858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663751504; bh=4ivO9IqEmEgtCLdTSEzuH9VgHVKX22irr6xRbYZoil0=; h=From:To:Subject:Date:From; b=VuDeFwj/KUULxVCTLgTFF0U6wjsr7C1JfYzGLXeAeDlx/yVO8LVzTeXjMU6xwueYK +FZEgymxezNPczV2MOwtnYNm0W8O71o9FijNqNnyJHKFNRvKftm1ngs5Au98Exomfb IqPk6etxAcoeyxpgnuHQc6F0HSgkarsWopX+Fh9w= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kyrylo Tkachov To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2757] aarch64: Rewrite -march=native to -mcpu if no other -mcpu or -mtune is given X-Act-Checkin: gcc X-Git-Author: Kyrylo Tkachov X-Git-Refname: refs/heads/master X-Git-Oldrev: d2278da1c3cb7bf8b3d96c86dbef2982bf4cc54a X-Git-Newrev: dd9e5f4db2debf1429feab7f785962ccef6e0dbd Message-Id: <20220921091144.992243858D37@sourceware.org> Date: Wed, 21 Sep 2022 09:11:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:dd9e5f4db2debf1429feab7f785962ccef6e0dbd commit r13-2757-gdd9e5f4db2debf1429feab7f785962ccef6e0dbd Author: Kyrylo Tkachov Date: Wed Sep 21 10:10:21 2022 +0100 aarch64: Rewrite -march=native to -mcpu if no other -mcpu or -mtune is given We have received requests to improve the out-of-the box experience and performance of AArch64 GCC users, particularly those porting software from other architectures. This has many aspects. One such aspect are apps built natively with an -march=native used as a tuning flag in the Makefile. On AArch64 this selects the right architecture features on GNU+Linux for the host system but tunes for the "generic" CPU target. This patch makes GCC also tune for the host CPU, as well as selecting its architecture. That is, it translates -march=native into -mcpu=native. This maintains the documentation that it "causes the compiler to pick the architecture of the host system" since -mcpu=native does that, but it also gives a better performance experience for the user. If the user explicitly asked for a particular CPU tuning through -mcpu or -mtune then we don't do this rewriting so that the user option is honoured. This would have been a one-line patch if it wasn't for --with-tune configure-time arguments. When GCC is configured with --with-tune= the OPTION_DEFAULT_SPECS will insert an -mtune= in the options if no other -mcpu or -mtune options were given. This will spook the aforementioned desired rewriting of -march=native into -mcpu=native, though I'd argue that we want to do the rewrite even then. Therefore, this patch moves some specs in aarch64.h around and refactors the --with-tune rewriting into CONFIG_TUNE_SPEC so that the materialization of the implicit -mtune= does not happen if -march=native is used. Bootstrapped and tested on aarch64-none-linux-gnu and checked with the output of -### from the driver that the option rewriting works as expected on aarch64-linux-gnu. gcc/ChangeLog: * config/aarch64/aarch64.h (HAVE_LOCAL_CPU_DETECT, EXTRA_SPEC_FUNCTIONS, MCPU_MTUNE_NATIVE_SPECS): Move definitions up before OPTION_DEFAULT_SPECS. (MCPU_MTUNE_NATIVE_SPECS): Pass "cpu" to local_cpu_detect when rewriting -march=native and no -mcpu or -mtune is given. (CONFIG_TUNE_SPEC): Define. (OPTION_DEFAULT_SPECS): Use CONFIG_TUNE_SPEC for "tune". Diff: --- gcc/config/aarch64/aarch64.h | 50 ++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h index 2eed6e8f6f0..6f6bb70fde9 100644 --- a/gcc/config/aarch64/aarch64.h +++ b/gcc/config/aarch64/aarch64.h @@ -1260,14 +1260,44 @@ extern enum aarch64_code_model aarch64_cmodel; #define ENDIAN_LANE_N(NUNITS, N) \ (BYTES_BIG_ENDIAN ? NUNITS - 1 - N : N) +/* Extra specs when building a native AArch64-hosted compiler. + Option rewriting rules based on host system. */ +#if defined(__aarch64__) +extern const char *host_detect_local_cpu (int argc, const char **argv); +#define HAVE_LOCAL_CPU_DETECT +# define EXTRA_SPEC_FUNCTIONS \ + { "local_cpu_detect", host_detect_local_cpu }, \ + MCPU_TO_MARCH_SPEC_FUNCTIONS + +/* Rewrite -m{arch,cpu,tune}=native based on the host system information. + When rewriting -march=native convert it into an -mcpu option if no other + -mcpu or -mtune was given. */ +# define MCPU_MTUNE_NATIVE_SPECS \ + " %{march=native:%