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 24BEF3858038 for ; Sat, 24 Jul 2021 09:44:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24BEF3858038 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=eQYAWnCCX4v/KA7/p1lv1SIdEhlgigxZt2s5TuP22S4=; b=haeZI73TN14ZaAzYR2ohAES1KC Ypm2ZVkC3a5ckpnNDxPSqo/zmzlmlcqm73ilvbJnZyZPbk9XBB6E2Snjm+MHDikjIw6oA8q48wQWd vRlpk/CQG/Ps1WIozHwU9sWS1OpDDHL5o8V1tXbV5KtjbBqCQKJzcnWbtuiRtTYyp75y1QFxDQtIE oXmLzpZ4YEcdACoWSxPLhXQ87LsrJob0NPvq9YYaSUkvIt6Ti1Nc6baAux9cYV4D5KgtMkjTGHEoC pIfb5RvRjYwMNALlgtCGevNwOy8Dj9VzxSQ+nOsh/RBcN7AxykQXTYrvETUacNDgOCuMjLZoN8YUN iMd8fGvg==; Received: from host109-154-46-127.range109-154.btcentralplus.com ([109.154.46.127]:60476 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 1m7ECW-0000gs-6h; Sat, 24 Jul 2021 05:44:08 -0400 From: "Roger Sayle" To: "'GCC Patches'" Cc: "'Marc Glisse'" , "'Richard Biener'" Subject: [PATCH take 2] Fold bswap32(x) != 0 to x != 0 (and related transforms) Date: Sat, 24 Jul 2021 10:44:04 +0100 Message-ID: <087b01d78070$7299bf10$57cd3d30$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_087C_01D78078.D45E2710" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdeAbpW/gonRJFYKQ86EH6sIywRTeQ== 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.6 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: , X-List-Received-Date: Sat, 24 Jul 2021 09:44:10 -0000 This is a multipart message in MIME format. ------=_NextPart_000_087C_01D78078.D45E2710 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit My apologies for the short delay. Thanks for explaining why these transforms don't usually require explicit tests for side-effects (but occasionally do). This does simplify things; please find attached the shorter revised patch. This patch has been retested on x86_64-pc-linux-gnu with a make bootstrap and make -k check with no new failures. Ok for mainline? 2010-07-24 Roger Sayle Marc Glisse gcc/ChangeLog * match.pd (rotate): Simplify equality/inequality of rotations. (bswap): Simplify equality/inequality tests of byte swapping. gcc/testsuite/ChangeLog * gcc.dg/fold-eqrotate-1.c: New test case. * gcc.dg/fold-eqbswap-1.c: New test case. Roger -- -----Original Message----- From: Marc Glisse Sent: 18 July 2021 23:03 To: Roger Sayle Cc: 'GCC Patches' Subject: Re: [PATCH] Fold bswap32(x) != 0 to x != 0 (and related transforms) On Sun, 18 Jul 2021, Roger Sayle wrote: > + (if (GIMPLE || !TREE_SIDE_EFFECTS (@0)) I don't think you need to worry about that, the general genmatch machinery is already supposed to take care of it. All the existing cases in match.pd are about cond_expr, where counting the occurrences of each @i is not reliable. -- Marc Glisse ------=_NextPart_000_087C_01D78078.D45E2710 Content-Type: text/plain; name="patchc2.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchc2.txt" diff --git a/gcc/match.pd b/gcc/match.pd=0A= index beb8d27..4d41b70 100644=0A= --- a/gcc/match.pd=0A= +++ b/gcc/match.pd=0A= @@ -3312,6 +3312,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)=0A= { tree rotate_type =3D TREE_TYPE (@0); }=0A= (convert (rotate (convert:rotate_type @1) @2))))))=0A= =0A= +(for cmp (eq ne)=0A= + (for rotate (lrotate rrotate)=0A= + invrot (rrotate lrotate)=0A= + /* (X >>r Y) cmp (Z >>r Y) may simplify to X cmp Y. */=0A= + (simplify=0A= + (cmp (rotate @1 @0) (rotate @2 @0))=0A= + (cmp @1 @2))=0A= + /* (X >>r C1) cmp C2 may simplify to X cmp C3. */=0A= + (simplify=0A= + (cmp (rotate @0 INTEGER_CST@1) INTEGER_CST@2)=0A= + (cmp @0 { const_binop (invrot, TREE_TYPE (@0), @2, @1); }))=0A= + /* (X >>r Y) cmp C where C is 0 or ~0, may simplify to X cmp C. */=0A= + (simplify=0A= + (cmp (rotate @0 @1) INTEGER_CST@2)=0A= + (if (integer_zerop (@2) || integer_all_onesp (@2))=0A= + (cmp @0 @2)))))=0A= +=0A= /* Simplifications of conversions. */=0A= =0A= /* Basic strip-useless-type-conversions / strip_nops. */=0A= @@ -3622,6 +3639,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)=0A= (simplify=0A= (bswap (bitop:c (bswap @0) @1))=0A= (bitop @0 (bswap @1))))=0A= + (for cmp (eq ne)=0A= + (simplify=0A= + (cmp (bswap @0) (bswap @1))=0A= + (cmp @0 @1))=0A= + (simplify=0A= + (cmp (bswap @0) INTEGER_CST@1)=0A= + (cmp @0 (bswap @1))))=0A= /* (bswap(x) >> C1) & C2 can sometimes be simplified to (x >> C3) & = C2. */=0A= (simplify=0A= (bit_and (convert1? (rshift@0 (convert2? (bswap@4 @1)) INTEGER_CST@2))=0A= ------=_NextPart_000_087C_01D78078.D45E2710 Content-Type: text/plain; name="fold-eqbswap-1.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fold-eqbswap-1.c" /* { dg-do compile } */=0A= /* { dg-options "-O2 -fdump-tree-optimized" } */=0A= =0A= int test1(int x, int y)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= return __builtin_bswap32(x) =3D=3D __builtin_bswap32(y);=0A= #else=0A= return x =3D=3D y;=0A= #endif=0A= }=0A= =0A= int test2(int x, int y)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= return __builtin_bswap32(x) !=3D __builtin_bswap32(y);=0A= #else=0A= return x !=3D y;=0A= #endif=0A= }=0A= =0A= int test3(int x)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= return __builtin_bswap32(x) =3D=3D 12345;=0A= #else=0A= return x;=0A= #endif=0A= }=0A= =0A= int test4(int x)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= return __builtin_bswap32(x) !=3D 12345;=0A= #else=0A= return x;=0A= #endif=0A= }=0A= =0A= int test1ll(long long x, long long y)=0A= {=0A= #if __SIZEOF_LONG_LONG__ =3D=3D 8=0A= return __builtin_bswap64(x) =3D=3D __builtin_bswap64(y);=0A= #else=0A= return x =3D=3D y;=0A= #endif=0A= }=0A= =0A= int test2ll(long long x, long long y)=0A= {=0A= #if __SIZEOF_LONG_LONG__ =3D=3D 8=0A= return __builtin_bswap64(x) !=3D __builtin_bswap64(y);=0A= #else=0A= return x !=3D y;=0A= #endif=0A= }=0A= =0A= int test3ll(long long x)=0A= {=0A= #if __SIZEOF_LONG_LONG__ =3D=3D 8=0A= return __builtin_bswap64(x) =3D=3D 12345;=0A= #else=0A= return (int)x;=0A= #endif=0A= }=0A= =0A= int test4ll(long long x)=0A= {=0A= #if __SIZEOF_LONG_LONG__ =3D=3D 8=0A= return __builtin_bswap64(x) !=3D 12345;=0A= #else=0A= return (int)x;=0A= #endif=0A= }=0A= =0A= int test1s(short x, short y)=0A= {=0A= #if __SIZEOF_SHORT__ =3D=3D 2=0A= return __builtin_bswap16(x) =3D=3D __builtin_bswap16(y);=0A= #else=0A= return x =3D=3D y;=0A= #endif=0A= }=0A= =0A= int test2s(short x, short y)=0A= {=0A= #if __SIZEOF_SHORT__ =3D=3D 2=0A= return __builtin_bswap16(x) !=3D __builtin_bswap16(y);=0A= #else=0A= return x !=3D y;=0A= #endif=0A= }=0A= =0A= int test3s(short x)=0A= {=0A= #if __SIZEOF_SHORT__ =3D=3D 2=0A= return __builtin_bswap16(x) =3D=3D 12345;=0A= #else=0A= return (int)x;=0A= #endif=0A= }=0A= =0A= int test4s(short x)=0A= {=0A= #if __SIZEOF_SHORT__ =3D=3D 2=0A= return __builtin_bswap16(x) !=3D 12345;=0A= #else=0A= return (int)x;=0A= #endif=0A= }=0A= =0A= /* { dg-final { scan-tree-dump-times "__builtin_bswap" 0 "optimized" } } = */=0A= =0A= ------=_NextPart_000_087C_01D78078.D45E2710 Content-Type: text/plain; name="fold-eqrotate-1.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fold-eqrotate-1.c" /* { dg-do compile } */=0A= /* { dg-options "-O2 -fdump-tree-optimized" } */=0A= =0A= int test1(unsigned int x, unsigned int y)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= unsigned int r1 =3D (x << 16) | (x >> 16);=0A= unsigned int r2 =3D (y << 16) | (y >> 16);=0A= return r1 =3D=3D r2;=0A= #else=0A= return x =3D=3D y;=0A= #endif=0A= }=0A= =0A= int test2(unsigned int x)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= unsigned int r1 =3D (x << 16) | (x >> 16);=0A= return r1 =3D=3D 12345;=0A= #else=0A= return x =3D=3D 12345;=0A= #endif=0A= }=0A= =0A= int test3(unsigned int x)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= unsigned int r1 =3D (x << 16) | (x >> 16);=0A= return r1 =3D=3D 0;=0A= #else=0A= return x =3D=3D 0;=0A= #endif=0A= }=0A= =0A= int test4(unsigned int x)=0A= {=0A= #if __SIZEOF_INT__ =3D=3D 4=0A= unsigned int r1 =3D (x << 16) | (x >> 16);=0A= return r1 =3D=3D ~0;=0A= #else=0A= return x =3D=3D ~0;=0A= #endif=0A= }=0A= =0A= /* { dg-final { scan-tree-dump-times "r>>" 0 "optimized" } } */=0A= =0A= ------=_NextPart_000_087C_01D78078.D45E2710--