From patchwork Fri Aug 27 10:07:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1521628 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=P3Q1VmRA; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GwwQ671Mtz9sRN for ; Fri, 27 Aug 2021 20:07:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 371FC385AC24 for ; Fri, 27 Aug 2021 10:07:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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 --- /* { dg-do compile } */ /* { dg-options "-O2" } */ short exttrunc_hi2_qi(short x) { return (char)x; } int exttrunc_si2_qi(int x) { return (char)x; } long exttrunc_di2_qi(long x) { return (char)x; } int exttrunc_si2_hi(int x) { return (short)x; } long exttrunc_di2_hi(long x) { return (short)x; } long exttrunc_di2_si(long x) { return (int)x; } /* { dg-final { scan-assembler-not "cvt.u16.u32" } } */ /* { dg-final { scan-assembler-not "cvt.u16.u64" } } */ /* { dg-final { scan-assembler-not "cvt.u32.u64" } } */ diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index 108de1c..b7a0393 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -401,6 +401,32 @@ %.\\tst%A0.u%T0\\t%0, %1;" [(set_attr "subregs_ok" "true")]) +;; Sign-extensions of truncations + +(define_insn "*extend_trunc_2_qi" + [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R") + (sign_extend:HSDIM + (truncate:QI (match_operand:HSDIM 1 "nvptx_register_operand" "R"))))] + "" + "%.\\tcvt.s%T0.s8\\t%0, %1;" + [(set_attr "subregs_ok" "true")]) + +(define_insn "*extend_trunc_2_hi" + [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R") + (sign_extend:SDIM + (truncate:HI (match_operand:SDIM 1 "nvptx_register_operand" "R"))))] + "" + "%.\\tcvt.s%T0.s16\\t%0, %1;" + [(set_attr "subregs_ok" "true")]) + +(define_insn "*extend_trunc_di2_si" + [(set (match_operand:DI 0 "nvptx_register_operand" "=R") + (sign_extend:DI + (truncate:SI (match_operand:DI 1 "nvptx_register_operand" "R"))))] + "" + "%.\\tcvt.s64.s32\\t%0, %1;" + [(set_attr "subregs_ok" "true")]) + ;; Integer arithmetic (define_insn "add3"