From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17900 invoked by alias); 21 Oct 2011 09:24:40 -0000 Received: (qmail 17860 invoked by uid 22791); 21 Oct 2011 09:24:37 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 Oct 2011 09:22:34 +0000 Received: by ywf9 with SMTP id 9so1408213ywf.20 for ; Fri, 21 Oct 2011 02:22:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.44.9 with SMTP id a9mr920646obm.61.1319188953641; Fri, 21 Oct 2011 02:22:33 -0700 (PDT) Received: by 10.182.12.202 with HTTP; Fri, 21 Oct 2011 02:22:33 -0700 (PDT) In-Reply-To: References: <7d649d85-73fa-4c37-bd6e-d3527500196b@zmail14.collab.prod.int.phx2.redhat.com> Date: Fri, 21 Oct 2011 09:52:00 -0000 Message-ID: Subject: Re: [patch tree-optimization]: allow branch-cost optimization for truth-and/or on mode-expanded simple boolean-operands From: Richard Guenther To: Kai Tietz Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg01940.txt.bz2 On Thu, Oct 20, 2011 at 3:08 PM, Kai Tietz wrote: > Hello, > > this patch re-enables the branch-cost optimization on simple boolean-type= d operands, which are casted to a wider integral type. =A0This happens due = casts from > boolean-types are preserved, but FE might expands simple-expression to wi= der mode. > > I added two tests for already working branch-cost optimization for IA-arc= hitecture and > two for explicit checking for boolean-type. > > ChangeLog > > 2011-10-20 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* fold-const.c (simple_operand_p_2): Handle integral > =A0 =A0 =A0 =A0casts from boolean-operands. > > 2011-10-20 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* gcc.target/i386/branch-cost1.c: New test. > =A0 =A0 =A0 =A0* gcc.target/i386/branch-cost2.c: New test. > =A0 =A0 =A0 =A0* gcc.target/i386/branch-cost3.c: New test. > =A0 =A0 =A0 =A0* gcc.target/i386/branch-cost4.c: New test. > > Bootstrapped and regression tested on x86_64-unknown-linux-gnu for all la= nguages including Ada and Obj-C++. =A0Ok for apply? > > Regards, > Kai > > Index: gcc-head/gcc/testsuite/gcc.target/i386/branch-cost2.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /dev/null > +++ gcc-head/gcc/testsuite/gcc.target/i386/branch-cost2.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-gimple -mbranch-cost=3D2" } */ > + > +extern int doo (void); > + > +int > +foo (int a, int b) > +{ > + =A0if (a && b) > + =A0 return doo (); > + =A0return 0; > +} > + > +/* { dg-final { scan-tree-dump-times "if " 1 "gimple" } } */ > +/* { dg-final { scan-tree-dump-times " & " 1 "gimple" } } */ > +/* { dg-final { cleanup-tree-dump "gimple" } } */ > Index: gcc-head/gcc/testsuite/gcc.target/i386/branch-cost3.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /dev/null > +++ gcc-head/gcc/testsuite/gcc.target/i386/branch-cost3.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-gimple -mbranch-cost=3D2" } */ > + > +extern int doo (void); > + > +int > +foo (_Bool a, _Bool b) > +{ > + =A0if (a && b) > + =A0 return doo (); > + =A0return 0; > +} > + > +/* { dg-final { scan-tree-dump-times "if " 1 "gimple" } } */ > +/* { dg-final { scan-tree-dump-times " & " 1 "gimple" } } */ > +/* { dg-final { cleanup-tree-dump "gimple" } } */ > Index: gcc-head/gcc/testsuite/gcc.target/i386/branch-cost4.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /dev/null > +++ gcc-head/gcc/testsuite/gcc.target/i386/branch-cost4.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-gimple -mbranch-cost=3D0" } */ > + > +extern int doo (void); > + > +int > +foo (_Bool a, _Bool b) > +{ > + =A0if (a && b) > + =A0 return doo (); > + =A0return 0; > +} > + > +/* { dg-final { scan-tree-dump-times "if " 2 "gimple" } } */ > +/* { dg-final { scan-tree-dump-not " & " "gimple" } } */ > +/* { dg-final { cleanup-tree-dump "gimple" } } */ > Index: gcc-head/gcc/fold-const.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc-head.orig/gcc/fold-const.c > +++ gcc-head/gcc/fold-const.c > @@ -3706,6 +3706,19 @@ simple_operand_p_2 (tree exp) > =A0 /* Strip any conversions that don't change the machine mode. =A0*/ > =A0 STRIP_NOPS (exp); > > + =A0/* Handle integral widening casts from boolean-typed > + =A0 =A0 expressions as simple. =A0This happens due casts from > + =A0 =A0 boolean-types are preserved, but FE might expands > + =A0 =A0 simple-expression to wider mode. =A0*/ > + =A0if (INTEGRAL_TYPE_P (TREE_TYPE (exp)) > + =A0 =A0 =A0&& CONVERT_EXPR_P (exp) > + =A0 =A0 =A0&& TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) > + =A0 =A0 =A0 =A0=3D=3D BOOLEAN_TYPE) > + =A0 =A0{ > + =A0 =A0 =A0exp =3D TREE_OPERAND (exp, 0); > + =A0 =A0 =A0STRIP_NOPS (exp); > + =A0 =A0} > + Huh, well. I think the above is just too special and you instead should replace the existing STRIP_NOPS by while (CONVERT_EXPR_P (exp)) exp =3D TREE_OPERAND (exp, 0); with a comment that conversions are considered simple. Ok with that change, if it bootstraps & tests ok. Richard. > =A0 code =3D TREE_CODE (exp); > > =A0 if (TREE_SIDE_EFFECTS (exp) > Index: gcc-head/gcc/testsuite/gcc.target/i386/branch-cost1.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- /dev/null > +++ gcc-head/gcc/testsuite/gcc.target/i386/branch-cost1.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-gimple -mbranch-cost=3D0" } */ > + > +extern int doo (void); > + > +int > +foo (int a, int b) > +{ > + =A0if (a && b) > + =A0 return doo (); > + =A0return 0; > +} > + > +/* { dg-final { scan-tree-dump-times "if " 2 "gimple" } } */ > +/* { dg-final { scan-tree-dump-not " & " "gimple" } } */ > +/* { dg-final { cleanup-tree-dump "gimple" } } */ >