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 1122C385E445 for ; Sat, 5 Dec 2020 12:51:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1122C385E445 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 F0894AC2F; Sat, 5 Dec 2020 12:51:36 +0000 (UTC) Date: Sat, 05 Dec 2020 13:51:35 +0100 User-Agent: K-9 Mail for Android In-Reply-To: <20201205105746.GZ3788@tucnak> References: <20201205091025.GX3788@tucnak> <20201205105746.GZ3788@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH] match.pd: Improve conditional_replacement for x ? 0 : -1 [PR796232] To: Jakub Jelinek CC: gcc-patches@gcc.gnu.org From: Richard Biener Message-ID: X-Spam-Status: No, score=-5.2 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, 05 Dec 2020 12:51:39 -0000 On December 5, 2020 11:57:46 AM GMT+01:00, Jakub Jelinek wrote: >On Sat, Dec 05, 2020 at 11:20:11AM +0100, Richard Biener wrote: >> >As mentioned in the PR, for boolean x we currently optimize >> >in phiopt x ? 0 : -1 into -(int)!x but it can be optimized as >> >(int) x - 1 which is one less operation both in GIMPLE and in x86 >> >assembly=2E >> > >> >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? >> > >> >And/or, shall we have a match=2Epd optimization to turn that -(type)!x >> >for BOOLEAN_TYPE (or other 1 bit unsigned precision values) into >> >(type) - 1=2E >>=20 >> I think that would make sense=2E Does that then cover the phiopt case >directly?=20 > >That would be the following then=2E Seems it works for that case=2E >Ok for trunk if it passes bootstrap/regtest? Ok=2E=20 Richard=2E=20 >2020-12-05 Jakub Jelinek > > PR tree-optimization/96232 > * match=2Epd (-(type)!A -> (type)A - 1): New optimization=2E > > * gcc=2Edg/tree-ssa/pr96232-1=2Ec: New test=2E > >--- gcc/match=2Epd=2Ejj 2020-12-02 11:20:24=2E765486816 +0100 >+++ gcc/match=2Epd 2020-12-05 11:46:00=2E554518927 +0100 >@@ -3812,6 +3812,16 @@ (define_operator_list COND_TERNARY > (cnd (logical_inverted_value truth_valued_p@0) @1 @2) > (cnd @0 @2 @1))) >=20 >+/* -(type)!A -> (type)A - 1=2E */ >+(simplify >+ (negate (convert?:s (logical_inverted_value:s @0))) >+ (if (INTEGRAL_TYPE_P (type) >+ && TREE_CODE (type) !=3D BOOLEAN_TYPE >+ && TYPE_PRECISION (type) > 1 >+ && TREE_CODE (@0) =3D=3D SSA_NAME >+ && ssa_name_has_boolean_range (@0)) >+ (plus (convert:type @0) { build_all_ones_cst (type); }))) >+ >/* A + (B vcmp C ? 1 : 0) -> A - (B vcmp C ? -1 : 0), since vector >comparisons > return all -1 or all 0 results=2E */ >/* ??? We could instead convert all instances of the vec_cond to >negate, >--- gcc/testsuite/gcc=2Edg/tree-ssa/pr96232-1=2Ec=2Ejj 2020-12-05 >11:37:27=2E804332875 +0100 >+++ gcc/testsuite/gcc=2Edg/tree-ssa/pr96232-1=2Ec 2020-12-05 >11:37:27=2E804332875 +0100 >@@ -0,0 +1,11 @@ >+/* PR tree-optimization/96232 */ >+/* { dg-do compile } */ >+/* { dg-options "-O2 -fdump-tree-optimized" } */ >+/* { dg-final { scan-tree-dump " \\+ -1;" "optimized" } } */ >+/* { dg-final { scan-tree-dump-not "~x_\[0-9]*\\\(D\\\)" "optimized" } >} */ >+ >+int >+foo (_Bool x) >+{ >+ return x ? 0 : -1; >+} > > > Jakub