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: 1904074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xry111.site header.i=@xry111.site header.a=rsa-sha256 header.s=default header.b=Q5Cuhoia; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tjnj051bnz23qD for ; Mon, 26 Feb 2024 15:30:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C3703858C35 for ; Mon, 26 Feb 2024 04:30:10 +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+incoming=patchwork.ozlabs.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); +}