From patchwork Wed Jun 14 00:43:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 107635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp915608vqr; Tue, 13 Jun 2023 17:44:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7UkoB2v9jfGclpqEx0Jn+GDqc6ULkI8UokJJoBMTS1d3pFbu7NCoZGKjFhSgnqhzNaCiQ7 X-Received: by 2002:a17:907:3f1e:b0:975:3037:b7bc with SMTP id hq30-20020a1709073f1e00b009753037b7bcmr15244555ejc.30.1686703462598; Tue, 13 Jun 2023 17:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686703462; cv=none; d=google.com; s=arc-20160816; b=GKPq1Ve58TAAu/yXDfQMMWTQhaXxdE2d6yjVd7QRaUMl0mJFegpK/KvALZ0N8kF0Gu CI2qok4texp9FoDNYlX4Vwyj3NCOOn+ae72880F/7v9AVZmgxBBIc61DX+BB1/TNCS0o ERU6FQVVijq0FQmdGFNhjB4x2IHWiPWs3/H+bqJgVnV0dN9o2eb4ZgCu96dFstHtmA/L WK4zOSBpHWgUssJMlzIGaFweuXK3IFVYwrVzzm0QhHNbu1P1KhyX+aHsCzidCTohh1ZF EcAU/hxlSWMew89wr0ghmSCRDWKgaUlfWMFxU9fJbmdKMLhBCn/iBZUAj6V2tlLQRVVB wOvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=tngWnHhFLh94paNAKtBNZfcEmfHhsKojWnzleZYgM2g=; b=ltipq26nxCO5BhUuCcUVrdfeB4FSjexQ2WCT0a+vIOb1sXWwgvuajcSRX/JmPIQR1Z 7mB+ITJk6nyjO6MRuM6IoNbogU1pimkmjdSEPp1kgFqRQ0SjQHdqQ5J4B2+55bvtDhOh 4jXElEM7Co0xVWjsKnEDgzywQyrUSgqo0nwApIK0d/nVnOPM4Ol+9bCZZuILa/8Sr18n Zet5rVw330fEu6eKWvMfqgMmIWeC+pXE+r4fQ/pHg+8AI3GjW5I66LO1uXCLe1kZj4Iy 4Y+KdiOn2gKuKboSth4sQiTaHp3gWU5nXzyll7CfGW9vR1RUPmxH8sfZeloortEGaKF1 VHXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jOtg19Ou; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k19-20020a17090646d300b009786e7e398dsi7589105ejs.216.2023.06.13.17.44.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 17:44:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jOtg19Ou; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4596A3858C62 for ; Wed, 14 Jun 2023 00:44:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4596A3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686703461; bh=tngWnHhFLh94paNAKtBNZfcEmfHhsKojWnzleZYgM2g=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jOtg19OukTTgmhWHBOdVaCUcbR8O6Jor8L9fP4YzmBeKAdG2JRnuMF6KO/NXamMru lOqTIuf4c0P7um0esR8g14BVhATYOgFZKXVzO4l768MUe9TKJYttH3QUHz8GPKQIdb mh3R3GeZm4nmfT0D6aehU//OopaPmY9ls/eFEUkQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 6B8FA3858D38 for ; Wed, 14 Jun 2023 00:43:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B8FA3858D38 Received: from stargazer.. (unknown [IPv6:240e:358:11bc:7000:dc73:854d:832e:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 3B58965CD4; Tue, 13 Jun 2023 20:43:29 -0400 (EDT) To: gcc-patches@gcc.gnu.org Cc: Lulu Cheng , WANG Xuerui , Chenghua Xu , Xi Ruoyao Subject: [PATCH] LoongArch: Set default alignment for functions and labels with -mtune Date: Wed, 14 Jun 2023 08:43:16 +0800 Message-ID: <20230614004316.546426-1-xry111@xry111.site> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, SPF_HELO_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768636769904055819?= X-GMAIL-MSGID: =?utf-8?q?1768636769904055819?= 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");