From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id A5D203858C1F for ; Thu, 15 Jun 2023 01:12:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5D203858C1F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.20.4.52]) by gateway (Coremail) with SMTP id _____8CxtOiFZYpknlsFAA--.1034S3; Thu, 15 Jun 2023 09:12:37 +0800 (CST) Received: from [10.20.4.52] (unknown [10.20.4.52]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxCOWEZYpkZkIbAA--.12017S2; Thu, 15 Jun 2023 09:12:37 +0800 (CST) Subject: Re: [PATCH] LoongArch: Set default alignment for functions and labels with -mtune To: Xi Ruoyao , gcc-patches@gcc.gnu.org Cc: WANG Xuerui , Chenghua Xu References: <20230614004316.546426-1-xry111@xry111.site> From: Lulu Cheng Message-ID: <3c0a8cf7-c027-fe0f-a7aa-48ab1b00b07b@loongson.cn> Date: Thu, 15 Jun 2023 09:12:36 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20230614004316.546426-1-xry111@xry111.site> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8CxCOWEZYpkZkIbAA--.12017S2 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxZr1fArW7tFykZw18Kr1DXFc_yoWruF1fpr ZrZwnxAr48GrnFgryDt34rXw4DX3y7Kr12v3W3ta48CF47XryUZFn5tr9rWFyDWws8GryI qr1Fg3WYva1UAacCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUv0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzV AYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8czVUUU UUU== X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,MIME_CHARSET_FARAWAY,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: LGTM! Thanks! ÔÚ 2023/6/14 ÉÏÎç8:43, Xi Ruoyao дµÀ: > The LA464 micro-architecture is sensitive to alignment of code. The > Loongson team has benchmarked various combinations of function, the > results [1] show that 16-byte label alignment together with 32-byte > function alignment gives best results in terms of SPEC score. > > Add a mtune-based table-driven mechanism to set the default of > -falign-{functions,labels}. As LA464 is the first (and the only for > now) uarch supported by GCC, the same setting is also used for > the "generic" -mtune=loongarch64. In the future we may set different > settings for LA{2,3,6}64 once we add the support for them. > > Bootstrapped and regtested on loongarch64-linux-gnu. Ok for trunk? > > gcc/ChangeLog: > > * config/loongarch/loongarch-tune.h (loongarch_align): New > struct. > * config/loongarch/loongarch-def.h (loongarch_cpu_align): New > array. > * config/loongarch/loongarch-def.c (loongarch_cpu_align): Define > the array. > * config/loongarch/loongarch.cc > (loongarch_option_override_internal): Set the value of > -falign-functions= if -falign-functions is enabled but no value > is given. Likewise for -falign-labels=. > --- > gcc/config/loongarch/loongarch-def.c | 12 ++++++++++++ > gcc/config/loongarch/loongarch-def.h | 1 + > gcc/config/loongarch/loongarch-tune.h | 8 ++++++++ > gcc/config/loongarch/loongarch.cc | 6 ++++++ > 4 files changed, 27 insertions(+) > > diff --git a/gcc/config/loongarch/loongarch-def.c b/gcc/config/loongarch/loongarch-def.c > index fc4ebbefede..6729c857f7c 100644 > --- a/gcc/config/loongarch/loongarch-def.c > +++ b/gcc/config/loongarch/loongarch-def.c > @@ -72,6 +72,18 @@ loongarch_cpu_cache[N_TUNE_TYPES] = { > }, > }; > > +struct loongarch_align > +loongarch_cpu_align[N_TUNE_TYPES] = { > + [CPU_LOONGARCH64] = { > + .function = "32", > + .label = "16", > + }, > + [CPU_LA464] = { > + .function = "32", > + .label = "16", > + }, > +}; > + > /* The following properties cannot be looked up directly using "cpucfg". > So it is necessary to provide a default value for "unknown native" > tune targets (i.e. -mtune=native while PRID does not correspond to > diff --git a/gcc/config/loongarch/loongarch-def.h b/gcc/config/loongarch/loongarch-def.h > index 778b1409956..fb8bb88eb52 100644 > --- a/gcc/config/loongarch/loongarch-def.h > +++ b/gcc/config/loongarch/loongarch-def.h > @@ -144,6 +144,7 @@ extern int loongarch_cpu_issue_rate[]; > extern int loongarch_cpu_multipass_dfa_lookahead[]; > > extern struct loongarch_cache loongarch_cpu_cache[]; > +extern struct loongarch_align loongarch_cpu_align[]; > extern struct loongarch_rtx_cost_data loongarch_cpu_rtx_cost_data[]; > > #ifdef __cplusplus > diff --git a/gcc/config/loongarch/loongarch-tune.h b/gcc/config/loongarch/loongarch-tune.h > index ba31c4f08c3..5c03262daff 100644 > --- a/gcc/config/loongarch/loongarch-tune.h > +++ b/gcc/config/loongarch/loongarch-tune.h > @@ -48,4 +48,12 @@ struct loongarch_cache { > int simultaneous_prefetches; /* number of parallel prefetch */ > }; > > +/* Alignment for functions and labels for best performance. For new uarchs > + the value should be measured via benchmarking. See the documentation for > + -falign-functions and -falign-labels in invoke.texi for the format. */ > +struct loongarch_align { > + const char *function; /* default value for -falign-functions */ > + const char *label; /* default value for -falign-labels */ > +}; > + > #endif /* LOONGARCH_TUNE_H */ > diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc > index eb73d11b869..5b8b93eb24b 100644 > --- a/gcc/config/loongarch/loongarch.cc > +++ b/gcc/config/loongarch/loongarch.cc > @@ -6249,6 +6249,12 @@ loongarch_option_override_internal (struct gcc_options *opts) > && !opts->x_optimize_size) > opts->x_flag_prefetch_loop_arrays = 1; > > + if (opts->x_flag_align_functions && !opts->x_str_align_functions) > + opts->x_str_align_functions = loongarch_cpu_align[LARCH_ACTUAL_TUNE].function; > + > + if (opts->x_flag_align_labels && !opts->x_str_align_labels) > + opts->x_str_align_labels = loongarch_cpu_align[LARCH_ACTUAL_TUNE].label; > + > if (TARGET_DIRECT_EXTERN_ACCESS && flag_shlib) > error ("%qs cannot be used for compiling a shared library", > "-mdirect-extern-access");