From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13955 invoked by alias); 13 Jul 2011 10:43:40 -0000 Received: (qmail 13943 invoked by uid 22791); 13 Jul 2011 10:43:39 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_TM X-Spam-Check-By: sourceware.org Received: from mail-gw0-f47.google.com (HELO mail-gw0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Jul 2011 10:43:23 +0000 Received: by gwb11 with SMTP id 11so2672547gwb.20 for ; Wed, 13 Jul 2011 03:43:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.151.148.1 with SMTP id a1mr1031224ybo.194.1310553802792; Wed, 13 Jul 2011 03:43:22 -0700 (PDT) Received: by 10.151.144.19 with HTTP; Wed, 13 Jul 2011 03:43:22 -0700 (PDT) In-Reply-To: References: Date: Wed, 13 Jul 2011 10:51:00 -0000 Message-ID: Subject: Re: [patch tree-optimization]: Normalize compares X ==/!= 1 -> X !=/== 0 for truth valued X From: Richard Guenther To: Kai Tietz Cc: GCC Patches 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-07/txt/msg01020.txt.bz2 On Wed, Jul 13, 2011 at 11:00 AM, Kai Tietz wrote: > Hello, > > this patch fixes that for replaced uses, we call fold_stmt_inplace. Addit= ionally > it adds to fold_gimple_assign the canonical form for X !=3D/=3D=3D 1 -> X= =3D=3D/!=3D 0 for > X with one-bit precision type. > > ChangeLog gcc/ > > 2011-07-13 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* gimple-fold.c (fold_gimple_assign): Add normalization > =A0 =A0 =A0 =A0for compares of 1-bit integer precision operands. > =A0 =A0 =A0 =A0* tree-ssa-propagate.c (replace_uses_in): Call > =A0 =A0 =A0 =A0fold_stmt_inplace on modified statement. err - sure not. The caller already does that. Breakpoint 5, substitute_and_fold (get_value_fn=3D0xc269ae , fold_fn=3D0, do_dce=3D1 '\001') at /space/rguenther/src/svn/trunk/gcc/tree-ssa-propagate.c:1134 1134 if (get_value_fn) D.2696_8 =3D a_1(D) !=3D D.2704_10; (gdb) n 1135 did_replace |=3D replace_uses_in (stmt, get_value_fn); (gdb) 1138 if (did_replace) (gdb) call debug_gimple_stmt (stmt) D.2696_8 =3D a_1(D) !=3D 1; (gdb) p did_replace $1 =3D 1 '\001' (gdb) n 1139 fold_stmt (&oldi); so figure out why fold_stmt does not do its work instead. Which I quickly checked in gdb and it dispatches to fold_binary with boolean-typed arguments as a_1 !=3D 1 where you can see the canonical form for this is !(int) a_1 because of a bug I think. /* bool_var !=3D 1 becomes !bool_var. */ if (TREE_CODE (TREE_TYPE (arg0)) =3D=3D BOOLEAN_TYPE && integer_onep = (arg1) && code =3D=3D NE_EXPR) return fold_build1_loc (loc, TRUTH_NOT_EXPR, type, fold_convert_loc (loc, type, arg0)); at least I don't see why we need to convert arg0 to the type of the comparison. You need to improve your debugging skills and see why existing transformations are not working before adding new ones. Richard. > ChangeLog gcc/testsuite > > 2011-07-13 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* gcc.dg/tree-ssa/fold-1.c: New test. > > Bootstrapped and regression tested for x86_64-pc-linux-gnu. =A0Ok for app= ly? > > Regards, > Kai > > Index: gcc/gcc/gimple-fold.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.orig/gcc/gimple-fold.c =A02011-07-13 10:37:32.000000000 +0200 > +++ gcc/gcc/gimple-fold.c =A0 =A0 =A0 2011-07-13 10:39:05.100843400 +0200 > @@ -815,6 +815,17 @@ fold_gimple_assign (gimple_stmt_iterator > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 gimple_assign_rhs2 (stmt)); > =A0 =A0 =A0 =A0} > > + =A0 =A0 =A0if (!result && (subcode =3D=3D EQ_EXPR || subcode =3D=3D NE_= EXPR) > + =A0 =A0 =A0 =A0 && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (stmt= ))) > + =A0 =A0 =A0 =A0 && TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt)= )) =3D=3D 1 > + =A0 =A0 =A0 =A0 && integer_onep (gimple_assign_rhs2 (stmt))) > + =A0 =A0 =A0 result =3D build2_loc (loc, (subcode =3D=3D EQ_EXPR ? NE_EX= PR : EQ_EXPR), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TREE_TYPE (gimpl= e_assign_lhs (stmt)), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gimple_assign_rh= s1 (stmt), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0fold_convert_loc= (loc, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_TYPE (= gimple_assign_rhs1 (stmt)), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 integer_zer= o_node)); > + > =A0 =A0 =A0 if (!result) > =A0 =A0 =A0 =A0 result =3D fold_binary_loc (loc, subcode, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_TYPE (gi= mple_assign_lhs (stmt)), > Index: gcc/gcc/testsuite/gcc.dg/tree-ssa/fold-1.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 =A0 1970-01-01 00:00:00.000000000 +0000 > +++ gcc/gcc/testsuite/gcc.dg/tree-ssa/fold-1.c =A02011-07-13 > 10:50:38.294367800 +0200 > @@ -0,0 +1,9 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > + > +int foo (_Bool a, _Bool b) > +{ > + =A0return a !=3D ((b | !b)); > +} > +/* { dg-final { scan-tree-dump-not " !=3D 1" "optimized" } } */ > +/* { dg-final { cleanup-tree-dump "optimized" } } */ > Index: gcc/gcc/tree-ssa-propagate.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.orig/gcc/tree-ssa-propagate.c =A0 2011-07-13 10:37:42.000000000 += 0200 > +++ gcc/gcc/tree-ssa-propagate.c =A0 =A0 =A0 =A02011-07-13 10:40:25.68857= 6800 +0200 > @@ -904,6 +904,8 @@ replace_uses_in (gimple stmt, ssa_prop_g > > =A0 =A0 =A0 propagate_value (use, val); > > + =A0 =A0 =A0fold_stmt_inplace (stmt); > + > =A0 =A0 =A0 replaced =3D true; > =A0 =A0 } >