From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 184AF3858D28 for ; Thu, 7 Jul 2022 02:23:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 184AF3858D28 Received: from [IPv6:240e:358:1139:6500:dc73:854d:832e:4] (unknown [IPv6:240e:358:1139:6500:dc73:854d:832e:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) 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 E6201669DF; Wed, 6 Jul 2022 22:23:31 -0400 (EDT) Message-ID: <535ed6eaa19df38309a773f9bf2542c65f715b6b.camel@xry111.site> Subject: [PATCH 0/2] loongarch: improve code generation for integer division From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: Lulu Cheng , Chenghua Xu , Wang Xuerui Date: Thu, 07 Jul 2022 10:23:18 +0800 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.3 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_SUSPICIOUS_NTLD, FROM_SUSPICIOUS_NTLD_FP, KAM_SHORT, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP, T_PDS_OTHER_BAD_TLD, T_SCC_BODY_TEXT_LINE autolearn=no 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-List-Received-Date: Thu, 07 Jul 2022 02:23:38 -0000 We were generating some unnecessary instructions for integer division. These two patches improve the code generation to compile template T div(T a, T b) { return a / b; } into a single division instruction (along with a return instruction of course) as we expected for T in {int32_t, uint32_t, int64_t}. Bootstrapped and regtested on loongarch64-linux-gnu. Ok for trunk? Xi Ruoyao (2): loongarch: add alternatives for idiv insns to improve code generation loongarch: avoid unnecessary sign-extend after 32-bit division gcc/config/loongarch/loongarch-protos.h | 1 + gcc/config/loongarch/loongarch.cc | 2 +- gcc/config/loongarch/loongarch.md | 34 ++++++++++++++++------ gcc/testsuite/gcc.target/loongarch/div-1.c | 9 ++++++ gcc/testsuite/gcc.target/loongarch/div-2.c | 9 ++++++ gcc/testsuite/gcc.target/loongarch/div-3.c | 9 ++++++ gcc/testsuite/gcc.target/loongarch/div-4.c | 9 ++++++ 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/div-1.c create mode 100644 gcc/testsuite/gcc.target/loongarch/div-2.c create mode 100644 gcc/testsuite/gcc.target/loongarch/div-3.c create mode 100644 gcc/testsuite/gcc.target/loongarch/div-4.c --=20 2.37.0