From patchwork Fri Aug 27 21:57:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1521802 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=YiRSsdfH; 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 4GxD8y5Hkwz9sWd for ; Sat, 28 Aug 2021 07:57:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3104385783B for ; Fri, 27 Aug 2021 21:57:34 +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 B458F3858C60 for ; Fri, 27 Aug 2021 21:57:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B458F3858C60 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=7xkqafbfH5knpCon87VUlOJYwj0jrtWe2iv1NAjXNV4=; b=YiRSsdfH89yxyW90Xg9rZTfHAL cHNKCZCwEH0+w1MhO4IhwdFnsoEKluZPYK/rSpWFfYITOAmoMMqqlQUJXrglbswMqVT/ekyGjwknA MfSU8FHbyeJ7Kj5trAgxWdLnYS0zK0wePlINCU7WfnjGeRDVpNpRworpV1hNolXEIoYP6qaa/6mMi 5uUoD5iwyG1bHWAM1QM5Rmshglxl2jBQcp2faZ9wQGZCDeEejmqePXTuOMmP5EWWb9oYo8aH6oXL8 3gxKVzC208twJkkAAwRLVayKKIMty3y5wVu7nTZe5SDvjW6LYxPobX6DKKEcP5j6+j5a4WCqDueT6 tdK1Rqzw==; Received: from host86-163-217-120.range86-163.btcentralplus.com ([86.163.217.120]:49371 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 1mJjqb-0006c5-5O for gcc-patches@gcc.gnu.org; Fri, 27 Aug 2021 17:57:13 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Only simplify TRUNCATE to SUBREG on TRULY_NOOP_TRUNCATION targets Date: Fri, 27 Aug 2021 22:57:10 +0100 Message-ID: <000101d79b8e$7d7d6470$78782d50$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adebjgy1s9O+xAOwTB2LAsvNdUrd0w== 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.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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" As recently remarked by Jeff Law, SUBREGs are the "forever chemicals" of GCC's RTL; once created they persist in the environment. The problem, according to the comment on lines 5428-5438 of combine.c is that non-tieable SUBREGs interfere with reload/register allocation, so combine often doesn't touch/clean-up instructions containing a SUBREG. This is the first and simplest of two patches to tackle that problem, by teaching combine to avoid converting explicit TRUNCATEs into SUBREGs that it can't handle. Consider the following (hypothetical) sequence of instructions on a STORE_FLAG_VALUE=1 target, which stores a zero or one in an SI register, then uselessly truncates to QImode, then extends it again. (set (reg:SI 27) (ne:SI (reg:BI 28) (const_int 0))) (set (reg:QI 26) (truncate:QI (reg:SI 27))) (set (reg:SI 0) (zero_extend:SI (reg:QI 26))) which ideally (i.e. with this patch) combine would simplify to: (set (reg:SI 0) (ne:SI (reg:BI 28) (const_int 0))) Alas currently, during combine the middle TRUNCATE is converted into a lowpart SUBREG, which subst then turns into (clobber (const_int 0)), abandoning the attempted combination, that then never reaches recog. 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. But it only affects !TRULY_NOOP_TRUNCATION targets, and the motivating example above is derived from the behaviour of backend patches not yet in the tree [nvptx is currently a STORE_FLAG_VALUE=-1 target]. Ok for mainline? 2021-08-27 Roger Sayle gcc/ChangeLog * combine.c (combine_simplify_rtx): Avoid converting an explicit TRUNCATE into a lowpart SUBREG on !TRULY_NOOP_TRUNCATION targets. * simplify-rtx.c (simplify_unary_operation_1): Likewise. Roger diff --git a/gcc/combine.c b/gcc/combine.c index cb5fa40..290a366 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -5903,7 +5903,8 @@ combine_simplify_rtx (rtx x, machine_mode op0_mode, int in_dest, if (HWI_COMPUTABLE_MODE_P (mode) && (STORE_FLAG_VALUE & ~GET_MODE_MASK (mode)) == 0 && (temp = get_last_value (XEXP (x, 0))) - && COMPARISON_P (temp)) + && COMPARISON_P (temp) + && TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (XEXP (x, 0)))) return gen_lowpart (mode, XEXP (x, 0)); break; diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index c81e27e..e431e0c 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -1249,7 +1249,8 @@ simplify_context::simplify_unary_operation_1 (rtx_code code, machine_mode mode, than HOST_BITS_PER_WIDE_INT. */ if (HWI_COMPUTABLE_MODE_P (mode) && COMPARISON_P (op) - && (STORE_FLAG_VALUE & ~GET_MODE_MASK (mode)) == 0) + && (STORE_FLAG_VALUE & ~GET_MODE_MASK (mode)) == 0 + && TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (op))) { temp = rtl_hooks.gen_lowpart_no_emit (mode, op); if (temp)