From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 9AA083860C2D for ; Sat, 16 Jan 2021 07:49:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9AA083860C2D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4EE29AB7A; Sat, 16 Jan 2021 07:49:49 +0000 (UTC) Date: Sat, 16 Jan 2021 08:49:48 +0100 User-Agent: K-9 Mail for Android In-Reply-To: <20210116005950.GW1034503@tucnak> References: <20210115183835.GN1034503@tucnak> <3A093C96-8989-4882-B774-AD39DDEBCAA4@suse.de> <20210115200358.GP1034503@tucnak> <40E7C042-A3A3-4E55-B521-14B5E1100FA3@suse.de> <20210116005950.GW1034503@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH] match.pd: Optimize ((cst << x) & 1) [PR96669] To: Jakub Jelinek CC: gcc-patches@gcc.gnu.org From: Richard Biener Message-ID: <893AC5F9-4707-4E91-BB11-63DE1954E5FE@suse.de> X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: , X-List-Received-Date: Sat, 16 Jan 2021 07:49:52 -0000 On January 16, 2021 1:59:50 AM GMT+01:00, Jakub Jelinek wrote: >On Fri, Jan 15, 2021 at 09:21:07PM +0100, Richard Biener wrote: >> >BTW, I've tried to also fix what the PR wanted primarily by adding >> >/* Simplify (CST << x) & 1 to 0 if CST is even or to x =3D=3D 0 if it = is >> >odd=2E / >> >(simplify >> > (bit_and (lshift INTEGER_CST@1 @0) integer_onep) >> > (if ((wi::to_wide (@1) & 1) !=3D 0) >> > (eq @0 { build_zero_cst (TREE_TYPE (@0)); }) >> > ({ build_zero_cst (type); }))) >> >simplifier before this one, but genmatch=2Ec doesn't seem to put it >into >> >the >> >resulting files=2E Is there a way to figure out what is going on? > >Actually, it was a PEBKAC, it helps when the comment termination is */ >rather than just / alone=2E > >The following works fine, no need to stick it into an unrelated >pattern=2E > >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Ok=2E=20 Richard=2E=20 >2021-01-15 Jakub Jelinek > > PR tree-optimization/96669 > * match=2Epd ((CST << x) & 1 -> x =3D=3D 0): New simplification=2E > > * gcc=2Edg/tree-ssa/pr96669-1=2Ec: Adjust regexp=2E > * gcc=2Edg/tree-ssa/pr96669-2=2Ec: New test=2E > >--- gcc/match=2Epd=2Ejj 2021-01-15 21:12:07=2E656060308 +0100 >+++ gcc/match=2Epd 2021-01-15 23:51:34=2E038119715 +0100 >@@ -3117,6 +3117,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (op @0 { build_int_cst (TREE_TYPE (@1), low); }))))))) >=20 >=20 >+/* Simplify (CST << x) & 1 to 0 if CST is even or to x =3D=3D 0 if it is >odd=2E */ >+(simplify >+ (bit_and (lshift INTEGER_CST@1 @0) integer_onep) >+ (if ((wi::to_wide (@1) & 1) !=3D 0) >+ (convert (eq:boolean_type_node @0 { build_zero_cst (TREE_TYPE >(@0)); })) >+ { build_zero_cst (type); })) >+ >/* Simplify ((C << x) & D) !=3D 0 where C and D are power of two >constants, > either to false if D is smaller (unsigned comparison) than C, or to > x =3D=3D log2 (D) - log2 (C)=2E Similarly for right shifts=2E */ >--- gcc/testsuite/gcc=2Edg/tree-ssa/pr96669-1=2Ec=2Ejj 2021-01-15 >22:03:18=2E089279035 +0100 >+++ gcc/testsuite/gcc=2Edg/tree-ssa/pr96669-1=2Ec 2021-01-16 >01:55:42=2E800379400 +0100 >@@ -1,7 +1,7 @@ > /* PR tree-optimization/96669 */ > /* { dg-do compile } */ > /* { dg-options "-O2 -fdump-tree-original" } */ >-/* { dg-final { scan-tree-dump "return a =3D=3D 0;" "original" } } */ >+/* { dg-final { scan-tree-dump "a =3D=3D 0" "original" } } */ > /* { dg-final { scan-tree-dump "return 1;" "original" } } */ > /* { dg-final { scan-tree-dump "return c =3D=3D 3;" "original" } } */ > /* { dg-final { scan-tree-dump "return d !=3D 1;" "original" } } */ >--- gcc/testsuite/gcc=2Edg/tree-ssa/pr96669-2=2Ec=2Ejj 2021-01-15 >22:03:47=2E075951818 +0100 >+++ gcc/testsuite/gcc=2Edg/tree-ssa/pr96669-2=2Ec 2021-01-16 >01:56:02=2E859156051 +0100 >@@ -0,0 +1,30 @@ >+/* PR tree-optimization/96669 */ >+/* { dg-do compile } */ >+/* { dg-options "-O2 -fdump-tree-original" } */ >+/* { dg-final { scan-tree-dump "a =3D=3D 0" "original" } } */ >+/* { dg-final { scan-tree-dump-times "return 0;" 2 "original" } } */ >+/* { dg-final { scan-tree-dump "c =3D=3D 0" "original" } } */ >+ >+int >+f1 (int a) >+{ >+ return ((1 << a) & 1); >+} >+ >+int >+f2 (int b) >+{ >+ return ((2 << b) & 1); >+} >+ >+int >+f3 (int c) >+{ >+ return ((35 << c) & 1); >+} >+ >+int >+f4 (int d) >+{ >+ return ((42 << d) & 1); >+} > > > Jakub