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 10DFF384BC30 for ; Tue, 9 Mar 2021 17:26:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 10DFF384BC30 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 C9B98AEBD; Tue, 9 Mar 2021 17:26:13 +0000 (UTC) Date: Tue, 09 Mar 2021 18:26:13 +0100 User-Agent: K-9 Mail for Android In-Reply-To: <20210309154022.GR745611@tucnak> References: <20210309154022.GR745611@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH] phiopt: Fix up conditional_replacement [PR99305] To: Jakub Jelinek CC: gcc-patches@gcc.gnu.org From: Richard Biener Message-ID: <2FAB02BC-74B5-493B-A43B-21A5ECDB5B00@suse.de> X-Spam-Status: No, score=-5.4 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: Tue, 09 Mar 2021 17:26:16 -0000 On March 9, 2021 4:40:22 PM GMT+01:00, Jakub Jelinek w= rote: >Hi! > >Before my PR97690 changes, conditional_replacement would not set neg >when the nonzero arg was boolean true=2E >I've simplified the testing, so that it first finds the zero argument >and then checks the other argument for all the handled cases >(1, -1 and 1 << X, where the last case is what the patch added support >for)=2E >But, unfortunately I've placed the integer_all_onesp test first=2E >For unsigned precision 1 types such as bool integer_all_onesp, >integer_onep >and integer_pow2p can all be true and the code set neg to true in that >case, >which is undesirable=2E > >The following patch tests integer_pow2p first (which is trivially true >for integer_onep too and tree_log2 in that case gives shift =3D=3D 0) >and only if that isn't the case, integer_all_onesp=2E > >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Ok=2E=20 Richard=2E=20 >2021-03-09 Jakub Jelinek > > PR tree-optimization/99305 > * tree-ssa-phiopt=2Ec (conditional_replacement): Test integer_pow2p > before integer_all_onesp instead of vice versa=2E > > * g++=2Edg/opt/pr99305=2EC: New test=2E > >--- gcc/tree-ssa-phiopt=2Ec=2Ejj 2021-01-22 11:41:38=2E078708425 +0100 >+++ gcc/tree-ssa-phiopt=2Ec 2021-03-09 13:15:02=2E649094949 +0100 >@@ -808,14 +808,14 @@ conditional_replacement (basic_block con > nonzero_arg =3D arg0; > else > return false; >- if (integer_all_onesp (nonzero_arg)) >- neg =3D true; >- else if (integer_pow2p (nonzero_arg)) >+ if (integer_pow2p (nonzero_arg)) > { > shift =3D tree_log2 (nonzero_arg); > if (shift && POINTER_TYPE_P (TREE_TYPE (nonzero_arg))) > return false; > } >+ else if (integer_all_onesp (nonzero_arg)) >+ neg =3D true; > else > return false; >=20 >--- gcc/testsuite/g++=2Edg/opt/pr99305=2EC=2Ejj 2021-03-09 13:39:11=2E040= 957563 >+0100 >+++ gcc/testsuite/g++=2Edg/opt/pr99305=2EC 2021-03-09 13:39:44=2E06358969= 1 >+0100 >@@ -0,0 +1,26 @@ >+// PR tree-optimization/99305 >+// { dg-do compile } >+// { dg-options "-O3 -fno-ipa-icf -fdump-tree-optimized" } >+// { dg-final { scan-tree-dump-times " =3D \\\(unsigned char\\\) >c_\[0-9]*\\\(D\\\);" 3 "optimized" } } >+// { dg-final { scan-tree-dump-times " =3D \[^\n\r]* \\+ \[0-9]*;" 3 >"optimized" } } >+// { dg-final { scan-tree-dump-times " =3D \[^\n\r]* <=3D 9;" 3 >"optimized" } } >+// { dg-final { scan-tree-dump-not "if \\\(c_\[0-9]*\\\(D\\\) \[!=3D]=3D >0\\\)" "optimized" } } >+// { dg-final { scan-tree-dump-not " =3D PHI <" "optimized" } } >+ >+bool >+foo (char c) >+{ >+ return c >=3D 48 && c <=3D 57; >+} >+ >+bool >+bar (char c) >+{ >+ return c !=3D 0 && foo (c); >+} >+ >+bool >+baz (char c) >+{ >+ return c !=3D 0 && c >=3D 48 && c <=3D 57; >+} > > Jakub