From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id BBD623858D1E for ; Sun, 1 Jan 2023 15:55:33 +0000 (GMT) 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=Hkswn6OkbeSo1Pij49/iqMhlEcU6ShsUnhFS0zjNdD8=; b=sZ9PvlhGssCNXmj970AJrGjfU2 5yrDlOm237Wu3BYzSWgMmwhUOTzuv2WD0KIgsIdQCHZeC3uVuE6X2zIXXBJAsx1qr23m5hNSljpI9 ROHLZKKG32SUZ4bzkjC4m+GHM51IcIZZleYHl7JSvw+GmBRLDbs5+S04lYu3CCBY/Py6ftI0N1+Px kETSZlFtlzky+ah08SMlVmPAiY/nXqJMg1emLXOpiv7MkDh0c9jeu9K1IxaLxzrGp9J28H/2xLraU FCKObm+RvpjUorjnu1lsdqX3jBAtPrqSoCcYPIKXqFSZNVPp4fAurBjAaMCTl16SVCAUxtJwuQNUA YexThreQ==; Received: from [185.62.158.67] (port=59270 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pC0gN-0006QL-Bx; Sun, 01 Jan 2023 10:55:31 -0500 From: "Roger Sayle" To: "'GCC Patches'" Cc: "'Segher Boessenkool'" Subject: [PATCH] Fix RTL simplifications of FFS, POPCOUNT and PARITY. Date: Sun, 1 Jan 2023 15:55:26 -0000 Message-ID: <002e01d91df9$79df2670$6d9d7350$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_002F_01D91DF9.79DF7490" X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adkd9/i0dLBeRmvBRJ+alVvfufOlXw== 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.5 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multipart message in MIME format. ------=_NextPart_000_002F_01D91DF9.79DF7490 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In 2011, the rtl.texi documentation was updated to reflect that the modes of the RTX unary operations FFS, POPCOUNT and PARITY must match those of their operands. Unfortunately, some of the transformations in simplify-rtx.cc predate this tightening of RTL semantics, and have not (until now) been updated/fixed. i.e. The POPCOUNT and PARITY optimizations were "correct" when I originally added them back in 2007. Segher requested that I split this piece out from a fix for PR 106594 in https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601501.html 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-01-01 Roger Sayle gcc/ChangeLog * gcc/simplify-rtx.cc (simplify_unary_operation_1) : Avoid generating FFS with mismatched operand and result modes, by using an explicit SIGN_EXTEND/ZERO_EXTEND instead. : Likewise, for POPCOUNT of ZERO_EXTEND. : Likewise, for PARITY of {ZERO,SIGN}_EXTEND. Thanks in advance, Roger -- ------=_NextPart_000_002F_01D91DF9.79DF7490 Content-Type: text/plain; name="patchaa4.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchaa4.txt" diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc=0A= index fc0d6c3..698ca6e 100644=0A= --- a/gcc/simplify-rtx.cc=0A= +++ b/gcc/simplify-rtx.cc=0A= @@ -1404,22 +1404,32 @@ simplify_context::simplify_unary_operation_1 = (rtx_code code, machine_mode mode,=0A= break;=0A= =0A= case FFS:=0A= - /* (ffs (*_extend )) =3D (ffs ) */=0A= + /* (ffs (*_extend )) =3D (*_extend (ffs )). */=0A= if (GET_CODE (op) =3D=3D SIGN_EXTEND=0A= || GET_CODE (op) =3D=3D ZERO_EXTEND)=0A= - return simplify_gen_unary (FFS, mode, XEXP (op, 0),=0A= - GET_MODE (XEXP (op, 0)));=0A= + {=0A= + temp =3D simplify_gen_unary (FFS, GET_MODE (XEXP (op, 0)),=0A= + XEXP (op, 0), GET_MODE (XEXP (op, 0)));=0A= + return simplify_gen_unary (GET_CODE (op), mode, temp,=0A= + GET_MODE (temp));=0A= + }=0A= break;=0A= =0A= case POPCOUNT:=0A= switch (GET_CODE (op))=0A= {=0A= case BSWAP:=0A= - case ZERO_EXTEND:=0A= - /* (popcount (zero_extend )) =3D (popcount ) */=0A= + /* (popcount (bswap )) =3D (popcount ). */=0A= return simplify_gen_unary (POPCOUNT, mode, XEXP (op, 0),=0A= GET_MODE (XEXP (op, 0)));=0A= =0A= + case ZERO_EXTEND:=0A= + /* (popcount (zero_extend )) =3D (zero_extend (popcount )). */=0A= + temp =3D simplify_gen_unary (POPCOUNT, GET_MODE (XEXP (op, 0)),=0A= + XEXP (op, 0), GET_MODE (XEXP (op, 0)));=0A= + return simplify_gen_unary (ZERO_EXTEND, mode, temp,=0A= + GET_MODE (temp));=0A= +=0A= case ROTATE:=0A= case ROTATERT:=0A= /* Rotations don't affect popcount. */=0A= @@ -1438,11 +1448,16 @@ simplify_context::simplify_unary_operation_1 = (rtx_code code, machine_mode mode,=0A= {=0A= case NOT:=0A= case BSWAP:=0A= - case ZERO_EXTEND:=0A= - case SIGN_EXTEND:=0A= return simplify_gen_unary (PARITY, mode, XEXP (op, 0),=0A= GET_MODE (XEXP (op, 0)));=0A= =0A= + case ZERO_EXTEND:=0A= + case SIGN_EXTEND:=0A= + temp =3D simplify_gen_unary (PARITY, GET_MODE (XEXP (op, 0)),=0A= + XEXP (op, 0), GET_MODE (XEXP (op, 0)));=0A= + return simplify_gen_unary (GET_CODE (op), mode, temp,=0A= + GET_MODE (temp));=0A= +=0A= case ROTATE:=0A= case ROTATERT:=0A= /* Rotations don't affect parity. */=0A= ------=_NextPart_000_002F_01D91DF9.79DF7490--