From patchwork Fri Jun 19 20:42:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1313351 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com 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=eUvtUcsT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 49pW3J5VnPz9sT2 for ; Sat, 20 Jun 2020 06:43:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C317A3870869; Fri, 19 Jun 2020 20:42:59 +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 311D73858D34 for ; Fri, 19 Jun 2020 20:42:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 311D73858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=roger@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=dS82IyeyQxd6oxa27DH7Nsf/JnInjIviRWMBppkzS0Y=; b=eUvtUcsTU0bAEYamD9zLU6sWt1 yMWulTt6DNB19VOmqECyhaDkp0XKd19tgirSbE6S0FG1o+kQhauW5qtBpiglTOYSnCFFjZ+b0EA/A v23dd2B8n1HB3rjNb7Sxgi02+1N4Xh/M4D5ukxHZ/POYhueJp4wFuZ084Qp6F7xkTR5y9fNlesdlt PAQNbYFw/TWpQZgmtZc4EaOBp3IOmi/ZJpyGR/rqd6VRAK89wUUAy8u6GVOfMwS+Za2tPy88FcwIF 9AHWcp3bUmePkdyKh3f62Oyvkt8ltA35CTFEli4WLkCIe1S+Gngk0amFff9TTFQs5/eBiPktA2XBf wjG9ifjQ==; Received: from host86-137-89-56.range86-137.btcentralplus.com ([86.137.89.56]:50902 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jmNqi-0005Db-EV for gcc-patches@gcc.gnu.org; Fri, 19 Jun 2020 16:42:56 -0400 From: "Roger Sayle" To: Subject: [PATCH] simplify-rtx: Two easy pieces. Date: Fri, 19 Jun 2020 21:42:54 +0100 Message-ID: <008901d6467a$36155350$a23ff9f0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZGchcSqewIk7A7QkKwvHafhSW+qw== 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=-11.8 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" My recent patch to add scalar integer simplification unit tests to simplify_rtx_c_tests identified two "trivial" corner cases that could be improved in simplify-rtx.c. I don't believe that either case can currently be triggered from GCC current front-end/back-end combinations, but hopefully the reviewer agrees these changes are simple/safe enough. Although it makes no sense to ever see a BImode ROTATE, the current ordering of transformations in simplify_binary_operation_1 converts (rotate:bi (reg:bi) 0) to (rotatert:bi (reg:bi) 1), which then doesn't get simplified away. Rather than teach the middle-end that any hypothetical ROTATE or ROTATERT of a BImode value is a no-op, a more realistic invariant is that any rotate by const0_rtx is already canonical. Optimizing "parity of parity" matches the tree constant folding transformation pending review. Alas, the only mentions of PARITY in GCC's official backend machine descriptions are in expanders, so the middle-end's RTL optimizers never see a PARITY to simplify. A test can be added to test_scalar_int_ops once that patch is reviewed/approved. This patch has been tested with "make bootstrap" and "make -k check" on x86_64-pc-linux-gnu with no regressions. 2020-06-19 Roger Sayle * simplify-rtx.c (simplify_unary_operation_1): Simplify (parity (parity x)) as (parity x), i.e. PARITY is idempotent. (simplify_binary_operation_1): Don't canonicalize rotations by zero bits, these get simplified away. Thanks in advance, Roger --- Roger Sayle NextMove Software Cambridge, UK diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 28c2dc6..b856b02 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -1391,6 +1391,10 @@ simplify_unary_operation_1 (enum rtx_code code, machine_mode mode, rtx op) GET_MODE (XEXP (op, 0))); break; + case PARITY: + /* (parity (parity x)) -> parity (x). */ + return op; + default: break; } @@ -3649,7 +3653,8 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, if (CONST_INT_P (trueop1) && IN_RANGE (INTVAL (trueop1), GET_MODE_UNIT_PRECISION (mode) / 2 + (code == ROTATE), - GET_MODE_UNIT_PRECISION (mode) - 1)) + GET_MODE_UNIT_PRECISION (mode) - 1) + && trueop1 != CONST0_RTX (mode)) { int new_amount = GET_MODE_UNIT_PRECISION (mode) - INTVAL (trueop1); rtx new_amount_rtx = gen_int_shift_amount (mode, new_amount);