From patchwork Fri May 26 18:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1786654 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=IA8/wC1C; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QSYjg6dFrz20Pb for ; Sat, 27 May 2023 04:44:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A63E385700C for ; Fri, 26 May 2023 18:44:04 +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 714753858C5F for ; Fri, 26 May 2023 18:43:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 714753858C5F 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=V1jCIRpHYzFQjumUWMiJqn8QYjcj4Zdu7BLqPmrk+vQ=; b=IA8/wC1CfNwliu3XuaHkm7tnzA nFk+3X7aIA2FKrGARcQXCA0z0+yvd6Vq5aQbqJYhI+lvhVQob9VuWkYW6uR6YgbhjPe0swG+2JUlc 3v87DMBSbjJCL8rjMyqqA7jZntK5spvk875zLPShvW4+G3+Pb8SkG1fBhFGgFxpUlSNqskavQ6qUZ ZWdbh12IP4L+Iq4z7g2tCQFjMZGblMNPzuh6rMR4kb3j46D7nUuIw0ehN3uRBDdL3XancrdRiIzJs 9sAtFh0jpKEYt3Lu3UbHen3RFCWJZa1K6PSbdLI7KKyRAK48xwPNQjhYGVq8JqZMuQl0YPydLBX/0 qtcBuToQ==; Received: from host86-169-41-81.range86-169.btcentralplus.com ([86.169.41.81]:50716 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1q2cPl-0008Tr-27; Fri, 26 May 2023 14:43:49 -0400 From: "Roger Sayle" To: Cc: Subject: [PATCH] Replace a HWI_COMPUTABLE_MODE_P with wide-int in simplify-rtx.cc. Date: Fri, 26 May 2023 19:43:47 +0100 Message-ID: <021601d99002$02fe60e0$08fb22a0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdmQATH2p1o3SXRDT++QdfRsXbrUNQ== 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.8 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, 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.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 enhances one of the optimizations in simplify_binary_operation_1 to allow it to simplify RTL expressions in modes than HOST_WIDE_INT by replacing a use of HWI_COMPUTABLE_MODE_P and UINTVAL with wide_int. The motivating example is a pending x86_64 backend patch that produces the following RTL in combine: (and:TI (zero_extend:TI (reg:DI 89)) (const_wide_int 0x0ffffffffffffffff)) where the AND is redundant, as the mask, ~0LL, is DImode's MODE_MASK. There's already an optimization that catches this for narrower modes, transforming (and:HI (zero_extend:HI (reg:QI x)) (const_int 0xff)) into (zero_extend:HI (reg:QI x)), but this currently only handles CONST_INT not CONST_WIDE_INT. Fixed by upgrading this transformation to use wide_int, specifically rtx_mode_t and wi::mask. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2023-05-23 Roger Sayle gcc/ChangeLog * simplify-rtx.cc (simplify_binary_operation_1) : Use wide-int instead of HWI_COMPUTABLE_MODE_P and UINTVAL in transformation of (and (extend X) C) as (zero_extend (and X C)), to also optimize modes wider than HOST_WIDE_INT. Thanks in advance, Roger diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index d4aeebc..8dc880b 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -3826,15 +3826,16 @@ simplify_context::simplify_binary_operation_1 (rtx_code code, there are no nonzero bits of C outside of X's mode. */ if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND) - && CONST_INT_P (trueop1) - && HWI_COMPUTABLE_MODE_P (mode) - && (~GET_MODE_MASK (GET_MODE (XEXP (op0, 0))) - & UINTVAL (trueop1)) == 0) + && CONST_SCALAR_INT_P (trueop1) + && is_a (mode, &int_mode) + && is_a (GET_MODE (XEXP (op0, 0)), &inner_mode) + && (wi::mask (GET_MODE_PRECISION (inner_mode), true, + GET_MODE_PRECISION (int_mode)) + & rtx_mode_t (trueop1, mode)) == 0) { machine_mode imode = GET_MODE (XEXP (op0, 0)); - tem = simplify_gen_binary (AND, imode, XEXP (op0, 0), - gen_int_mode (INTVAL (trueop1), - imode)); + tem = immed_wide_int_const (rtx_mode_t (trueop1, mode), imode); + tem = simplify_gen_binary (AND, imode, XEXP (op0, 0), tem); return simplify_gen_unary (ZERO_EXTEND, mode, tem, imode); }