From patchwork Sun Sep 5 22:28:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1524796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=s4EhRoA7; dkim-atps=neutral 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=) 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 4H2mR051jXz9sRN for ; Mon, 6 Sep 2021 08:28:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B7BA385800E for ; Sun, 5 Sep 2021 22:28:56 +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 498D73858408 for ; Sun, 5 Sep 2021 22:28:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 498D73858408 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:To:From:Sender:Reply-To:Cc: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=tKxfBe68iBccY2DqMSWEdzfUXvwXsuTeOwD+Z2pGqMs=; b=s4EhRoA7F320GPg5RLa06LKCAt ZuDoFutHACU+bBrUX0VoC5f7pCwtYAZq940PtRZR9Bp7WKrXAm2wvOZm/O/rPnGQ6eFFZxgIn374Y eBuh9LzEsaq6op+/lv4fO13slKvPBsXqqFEYu9TuoGWGMrLkHwOudsUOjFEojqxDxp+wpIubhw01T c8yvzWyrmx+qlzGnO+i7cX7jn1TkuIm0bRMq8t9YmWkPYKSocWY6v9asBZvaULRWuFjTL5aWwrBPn NmVZB9m2TQDZ4+aWat237SnfRcmJR/6XD7zBn/llD0MqguMsnk/ioCOuC+L2Gv4awBFFWoaJUEqwq MemAKsUQ==; Received: from host86-168-251-41.range86-168.btcentralplus.com ([86.168.251.41]:52552 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 1mN0cq-0004wT-Ov for gcc-patches@gcc.gnu.org; Sun, 05 Sep 2021 18:28:32 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Simplify paradoxical subreg extensions of TRUNCATE Date: Sun, 5 Sep 2021 23:28:30 +0100 Message-ID: <001401d7a2a5$5bf07db0$13d17910$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdeipE7z4KbfEpGkRCa/xlPb0wQ1kA== 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=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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 simplifies the RTX (subreg:HI (truncate:QI (reg:SI))) as (truncate:HI (reg:SI)), and closely related variants. In RTL, a paradoxical SUBREG where the outermode is wider than the innermode is like the extensions zero_extend or sign_extend, but where we don't care about the contents of the extended bits. Hence, in the above case, it's convenient to eliminate the SUBREG by tweaking the explicit TRUNCATE to include more bits from the original REG. There are three possibilities: as above where outermode < origmode, where we can eliminate the paradoxical SUBREG using a wider TRUNCATE; secondly when outermode == origmode, we can eliminate both the SUBREG and the TRUNCATE, so (subreg:SI (truncate:QI (reg:SI))) becomes just (reg:SI); and finally when outermode > origmode, we can eliminate the TRUNCATE, and generate a paradoxical subreg from the original source, so (subreg:DI (truncate:QI (reg:SI))) becomes the simpler (subreg:DI (reg:SI)). An example benefit of this simplification is that on nvptx-none, int foo(char x, char y) { return (x=='x') && (y=='y'); } shrinks from 17 instructions to 13 instructions. This patch has been tested on x86_64-pc-linux-gnu with "make bootstrap" and "make -k check" with no new failures, and also on nvptx-none with no new failures. Ok for mainline? 2021-09-05 Roger Sayle gcc/ChangeLog * simplify-rtx.c (simplify_subreg): Optimize paradoxical subreg extensions of TRUNCATE. Roger diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index ebad5cb..3040136 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -7403,13 +7403,34 @@ simplify_context::simplify_subreg (machine_mode outermode, rtx op, return immed_wide_int_const (val, int_outermode); } - if (GET_MODE_PRECISION (int_outermode) - < GET_MODE_PRECISION (int_innermode)) + unsigned int outerprec = GET_MODE_PRECISION (int_outermode); + unsigned int innerprec = GET_MODE_PRECISION (int_innermode); + if (outerprec < innerprec) { rtx tem = simplify_truncation (int_outermode, op, int_innermode); if (tem) return tem; } + else if (outerprec > innerprec + && GET_CODE (op) == TRUNCATE) + { + /* Optimize paradoxial subreg extension of a truncate, where + we can eliminate the truncation, or widen the truncation + to the desired mode. */ + scalar_int_mode int_origmode; + rtx orig = XEXP (op, 0); + if (is_a (GET_MODE (orig), &int_origmode)) + { + unsigned int origprec = GET_MODE_PRECISION (int_origmode); + if (outerprec < origprec) + return simplify_gen_unary (TRUNCATE, outermode, orig, + GET_MODE (orig)); + else if (outerprec > origprec) + return lowpart_subreg (int_outermode, orig, int_origmode); + else if (outermode == GET_MODE (orig)) + return orig; + } + } } /* If OP is a vector comparison and the subreg is not changing the