From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 8AE3F3858018 for ; Fri, 27 Aug 2021 10:07:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8AE3F3858018 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZROlHaNG+xhPrjSGrABMJBUxBfVyVMrLjkvPwFp/jf4=; b=P3Q1VmRASJVjMqKX2J2fqQ/4Nb GZh7O/ZtNbtcrTThvQyycDwE6C1z6gUiw95TSRcvUS8a+XnZrQPN5M67nccB+gfiXeIVanCbl8B/h +FY8LCJvAm3TKNIPH0Kl2Clm0bqzVkRstnAl8MRpX6B9opl/bwJ4gQNX8jCeT9oZL7JvL6iVYCEC0 C7X463c3520/E9pLFOmBj4h2uSdAcCsNGjXX9+2THu+wZ9UKWTP0mjqZjf+B9CIEGXOhq7MofhC71 6AtZ0sthW8WgHx/5hk1ciZFDYeD1mkUTKaaJ1prKV7LVYcK4AyvwLKRm9lyuklvxe3c0Q1S2/zTZT 9NNW7MFw==; Received: from host86-163-217-120.range86-163.btcentralplus.com ([86.163.217.120]:53861 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mJYld-00029k-Rc; Fri, 27 Aug 2021 06:07:22 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] nvptx: Use cvt to perform sign-extension of truncation. Date: Fri, 27 Aug 2021 11:07:18 +0100 Message-ID: <000101d79b2b$5304ee10$f90eca30$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0002_01D79B33.B4CB2AD0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdebKtWxwrftKgJYTlWSRlQJZyuo2Q== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fri, 27 Aug 2021 10:07:32 -0000 This is a multipart message in MIME format. ------=_NextPart_000_0002_01D79B33.B4CB2AD0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch introduces some new define_insn rules to the nvptx backend, to perform sign-extension of a truncation (from and to the same mode), using a single cvt instruction. As an example, the following function int foo(int x) { return (char)x; } with -O2 currently generates: mov.u32 %r24, %ar0; mov.u32 %r26, %r24; cvt.s32.s8 %value, %r26; and with this patch, now generates: mov.u32 %r24, %ar0; cvt.s32.s8 %value, %r24; This patch has been tested on nvptx-none hosted by x86_64-pc-linux-gnu with a top-level "make" (including newlib) and a "make check" with no new regressions. Ok for mainline? 2021-08-27 Roger Sayle gcc/ChangeLog * config/nvptx/nvptx.md (*extend_trunc_2_qi, *extend_trunc_2_hi, *extend_trunc_di2_si): New insns. Use cvt to perform sign-extension of truncation in one step. gcc/testsuite/ChangeLog * gcc.target/nvptx/exttrunc.c: New test case. Roger -- ------=_NextPart_000_0002_01D79B33.B4CB2AD0 Content-Type: text/plain; name="patchz.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchz.txt" diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md=0A= index 108de1c..b7a0393 100644=0A= --- a/gcc/config/nvptx/nvptx.md=0A= +++ b/gcc/config/nvptx/nvptx.md=0A= @@ -401,6 +401,32 @@=0A= %.\\tst%A0.u%T0\\t%0, %1;"=0A= [(set_attr "subregs_ok" "true")])=0A= =0A= +;; Sign-extensions of truncations=0A= +=0A= +(define_insn "*extend_trunc_2_qi"=0A= + [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=3DR")=0A= + (sign_extend:HSDIM=0A= + (truncate:QI (match_operand:HSDIM 1 "nvptx_register_operand" "R"))))]=0A= + ""=0A= + "%.\\tcvt.s%T0.s8\\t%0, %1;"=0A= + [(set_attr "subregs_ok" "true")])=0A= +=0A= +(define_insn "*extend_trunc_2_hi"=0A= + [(set (match_operand:SDIM 0 "nvptx_register_operand" "=3DR")=0A= + (sign_extend:SDIM=0A= + (truncate:HI (match_operand:SDIM 1 "nvptx_register_operand" "R"))))]=0A= + ""=0A= + "%.\\tcvt.s%T0.s16\\t%0, %1;"=0A= + [(set_attr "subregs_ok" "true")])=0A= +=0A= +(define_insn "*extend_trunc_di2_si"=0A= + [(set (match_operand:DI 0 "nvptx_register_operand" "=3DR")=0A= + (sign_extend:DI=0A= + (truncate:SI (match_operand:DI 1 "nvptx_register_operand" "R"))))]=0A= + ""=0A= + "%.\\tcvt.s64.s32\\t%0, %1;"=0A= + [(set_attr "subregs_ok" "true")])=0A= +=0A= ;; Integer arithmetic=0A= =0A= (define_insn "add3"=0A= ------=_NextPart_000_0002_01D79B33.B4CB2AD0 Content-Type: text/plain; name="exttrunc.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="exttrunc.c" /* { dg-do compile } */=0A= /* { dg-options "-O2" } */=0A= =0A= short exttrunc_hi2_qi(short x)=0A= {=0A= return (char)x;=0A= }=0A= =0A= int exttrunc_si2_qi(int x)=0A= {=0A= return (char)x;=0A= }=0A= =0A= long exttrunc_di2_qi(long x)=0A= {=0A= return (char)x;=0A= }=0A= =0A= int exttrunc_si2_hi(int x)=0A= {=0A= return (short)x;=0A= }=0A= =0A= long exttrunc_di2_hi(long x)=0A= {=0A= return (short)x;=0A= }=0A= =0A= long exttrunc_di2_si(long x)=0A= {=0A= return (int)x;=0A= }=0A= =0A= /* { dg-final { scan-assembler-not "cvt.u16.u32" } } */=0A= /* { dg-final { scan-assembler-not "cvt.u16.u64" } } */=0A= /* { dg-final { scan-assembler-not "cvt.u32.u64" } } */=0A= =0A= ------=_NextPart_000_0002_01D79B33.B4CB2AD0--