From patchwork Mon Feb 26 04:28:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 86356 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C065A3858C98 for ; Mon, 26 Feb 2024 04:29:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id D6DFC3858D1E for ; Mon, 26 Feb 2024 04:28:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D6DFC3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D6DFC3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708921733; cv=none; b=aIvE2VfJRlrfwLH9bTsc1/jMaKWKGXJFpjk0ranVfZCaPn1JLvCHOUm9VaSNRgKjayAoGXAMIgs3YiENdvo9vSEe4/PrB1MtZ7/eXt6DKTvs0O549vlnp30xKhT1Dr+PsyHCRjxifdJGSplUFyz/ND9Gl3/RqysQGknWMnA6YCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708921733; c=relaxed/simple; bh=g6GMKkUPGweH8M0CUgJcZmGF1qt/qKQ2Oo0PTRFAHM4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eHvB/ebnRzduesP4QedJbro5nXuxSphoo8j34gmfAEQkD7O3idd1tEY9CCDKjZ12MQpYsDofSq7dRO0jhnvh6RUtx/xUC2rikxybYEBy/apxRLr+2P65CtvheX5BxKGXOY8g5zOY/sDxtsActreoebBW5b2nZfLoIHRc2vK8V4Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1708921728; bh=g6GMKkUPGweH8M0CUgJcZmGF1qt/qKQ2Oo0PTRFAHM4=; h=From:To:Cc:Subject:Date:From; b=R34s3QZ5DnQnmJZjK8WdDZnIKrCiv/nc1a12r3j/2pu+5b/pv7FThHVWfHdy81Yj+ lEw2WRvWq2dpY7zYMhgymLC624nyx80rawHI+cw1n3c1QmPy73TNgCvV1HW8p25Ytt ghUwTxCpg1ECB6Ymgo0BCbKr9jld37jEZPqg+v+0= Received: from stargazer.. (unknown [IPv6:240e:358:11b4:ae00: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 0716F66E1A; Sun, 25 Feb 2024 23:28:45 -0500 (EST) From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: chenglulu , i@xen0n.name, xuchenghua@loongson.cn, Xi Ruoyao Subject: [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines Date: Mon, 26 Feb 2024 12:28:03 +0800 Message-ID: <20240226042830.6927-1-xry111@xry111.site> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.2 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Introduce an iterator for UNSPEC_CRC and UNSPEC_CRCC to make the next change easier. gcc/ChangeLog: * config/loongarch/loongarch.md (CRC): New define_int_iterator. (crc): New define_int_attr. (loongarch_crc_w__w, loongarch_crcc_w__w): Unify into ... (loongarch__w__w): ... here. --- gcc/config/loongarch/loongarch.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 2ce7a151880..4ded1b3a117 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -4251,24 +4251,16 @@ (define_peephole2 (define_mode_iterator QHSD [QI HI SI DI]) +(define_int_iterator CRC [UNSPEC_CRC UNSPEC_CRCC]) +(define_int_attr crc [(UNSPEC_CRC "crc") (UNSPEC_CRCC "crcc")]) -(define_insn "loongarch_crc_w__w" +(define_insn "loongarch__w__w" [(set (match_operand:SI 0 "register_operand" "=r") (unspec:SI [(match_operand:QHSD 1 "register_operand" "r") (match_operand:SI 2 "register_operand" "r")] - UNSPEC_CRC))] + CRC))] "" - "crc.w..w\t%0,%1,%2" - [(set_attr "type" "unknown") - (set_attr "mode" "")]) - -(define_insn "loongarch_crcc_w__w" - [(set (match_operand:SI 0 "register_operand" "=r") - (unspec:SI [(match_operand:QHSD 1 "register_operand" "r") - (match_operand:SI 2 "register_operand" "r")] - UNSPEC_CRCC))] - "" - "crcc.w..w\t%0,%1,%2" + ".w..w\t%0,%1,%2" [(set_attr "type" "unknown") (set_attr "mode" "")]) From patchwork Mon Feb 26 04:28:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 86357 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEEDD3858CDB for ; Mon, 26 Feb 2024 04:30:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 97A623858D3C for ; Mon, 26 Feb 2024 04:28:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97A623858D3C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 97A623858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708921735; cv=none; b=TKtJVHOmkNgQ+/Ay8LFmcm3wwyOdsm89RJy7nUQbHPeHGHr73VIRLU4+4kUOP1Q4l2eW8DLLQM1H+x2nvjQcusfaCtCmptVXOas33eZ8kw6rREzQe7lJonxxFlbJ7uHWosgD/zwOjdR7TTwVFmgXadvCmNaVTt8pZudAUdOrB2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708921735; c=relaxed/simple; bh=t7fBobg3raCcQkX5TY736pz3bYtLu+n12XlUGHlcKHo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=N/UHdjGqaSV7ieiuHnu5/bN0+AVHf2FUOmuxvTar7C7KoNc+6LeTPbKlReEDxKE7bW5YgTSFhusEZwLLF7ZKulwbCCWhb0t1uDArycHVDq9Y1fwFV3128l4Usr4kbQxXkA0y7pPQ2U2A6tmvK2eINfidmB9Acb8BmKgiSlSRaXs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1708921732; bh=t7fBobg3raCcQkX5TY736pz3bYtLu+n12XlUGHlcKHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q5CuhoiaMqrpkC/XGEP9+sICaAouK9jtN6huL5NSa55zeIYrUJNoDFvIN6uC9BBw1 bS2iZTy+1ZTDrhrCDxEWxgguhje1V2+LSXHyrhkJuUvAYLPJMF5jrHK6UlgRYFItd1 Y/o+5VNyawVrOEsMlyfHSDz6NXfOLBKYWASO8xuA= Received: from stargazer.. (unknown [IPv6:240e:358:11b4:ae00: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 4C02866E1B; Sun, 25 Feb 2024 23:28:48 -0500 (EST) From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: chenglulu , i@xen0n.name, xuchenghua@loongson.cn, Xi Ruoyao Subject: [PATCH 2/2] LoongArch: Remove unneeded sign extension after crc/crcc instructions Date: Mon, 26 Feb 2024 12:28:04 +0800 Message-ID: <20240226042830.6927-2-xry111@xry111.site> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240226042830.6927-1-xry111@xry111.site> References: <20240226042830.6927-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org The specification of crc/crcc instructions is clear that the output is sign-extended to GRLEN. Add a define_insn to tell the compiler this fact and allow it to remove the unneeded sign extension on crc/crcc output. As crc/crcc instructions are usually used in a tight loop, this should produce a significant performance gain. gcc/ChangeLog: * config/loongarch/loongarch.md (loongarch__w__w_extended): New define_insn. gcc/testsuite/ChangeLog: * gcc.target/loongarch/crc-sext.c: New test; --- Bootstrapped and regtested on loongarch64-linux-gnu. Ok for trunk? gcc/config/loongarch/loongarch.md | 11 +++++++++++ gcc/testsuite/gcc.target/loongarch/crc-sext.c | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gcc.target/loongarch/crc-sext.c diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 4ded1b3a117..525e1e82183 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -4264,6 +4264,17 @@ (define_insn "loongarch__w__w" [(set_attr "type" "unknown") (set_attr "mode" "")]) +(define_insn "loongarch__w__w_extended" + [(set (match_operand:DI 0 "register_operand" "=r") + (sign_extend:DI + (unspec:SI [(match_operand:QHSD 1 "register_operand" "r") + (match_operand:SI 2 "register_operand" "r")] + CRC)))] + "TARGET_64BIT" + ".w..w\t%0,%1,%2" + [(set_attr "type" "unknown") + (set_attr "mode" "")]) + ;; With normal or medium code models, if the only use of a pc-relative ;; address is for loading or storing a value, then relying on linker ;; relaxation is not better than emitting the machine instruction directly. diff --git a/gcc/testsuite/gcc.target/loongarch/crc-sext.c b/gcc/testsuite/gcc.target/loongarch/crc-sext.c new file mode 100644 index 00000000000..9ade5a8e4ca --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/crc-sext.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=loongarch64" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +/* +**my_crc: +** crc.w.d.w \$r4,\$r4,\$r5 +** jr \$r1 +*/ +int my_crc(long long dword, int crc) +{ + return __builtin_loongarch_crc_w_d_w(dword, crc); +}