From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12005 invoked by alias); 20 Jul 2011 13:15:25 -0000 Received: (qmail 11990 invoked by uid 22791); 20 Jul 2011 13:15:23 -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,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, 20 Jul 2011 13:14:35 +0000 Received: by gwb11 with SMTP id 11so518151gwb.20 for ; Wed, 20 Jul 2011 06:14:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.67.21 with SMTP id p21mr4385069yba.273.1311167674375; Wed, 20 Jul 2011 06:14:34 -0700 (PDT) Received: by 10.150.205.2 with HTTP; Wed, 20 Jul 2011 06:14:34 -0700 (PDT) In-Reply-To: References: Date: Wed, 20 Jul 2011 13:41:00 -0000 Message-ID: Subject: Re: [patch tree-optimization]: [2 of 3]: Boolify compares & more 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/msg01622.txt.bz2 On Wed, Jul 20, 2011 at 3:05 PM, Kai Tietz wrote: > Hello, > > this is the revised version of the partial pre-approved patch for preserv= ing > type-casts from/to boolean-types. =A0It fixes additionally the regression= in > tree-ssa/builtin-expect-5.c testcase, which was caused by fold_builtin_ex= pect. > Additionally there was a regression in gcc.dg/pr28685-1.c, which is fixed= by > the change in tree-ssa-forwprop.c's function simplify_bitwise_binary. =A0= This > is just temporary necessary. =A0As soon as we are boolifying comparisons = in > gimplifier, the pattern-matching in tree-ssa-reassoc will match for 2 > branched cases > again and we can remove the hunk from forward-propagation again. Hm, if we can't apply this pieces without regressions we shouldn't. They can then wait for the boolification patch. Can you explain the fold_builtin_expect change? I'm lost in the maze of inner/inner_arg0/arg0 renaming game. It looks as if the patch only moves stuff - but that can't possibly be the case. So, what's going on there? Thanks, Richard. > 2011-07-20 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* fold-const.c (fold_unary_loc): Preserve > =A0 =A0 =A0 =A0non-boolean-typed casts. > =A0 =A0 =A0 =A0* tree-ssa.c (useless_type_conversion_p): Preserve incompa= tible > =A0 =A0 =A0 =A0casts from/to boolean, > =A0 =A0 =A0 =A0* builtins.c (fold_builtin_expect): See through the cast > =A0 =A0 =A0 =A0from truthvalue_type_node to long. > =A0 =A0 =A0 =A0* tree-ssa-forwprop.c (simplify_bitwise_binary): Add > =A0 =A0 =A0 =A0simplification for CMP bitwise-binary CMP. > > > Bootstrapped and regression tested for all standard languages plus Ada > and Obj-C++ on > host x86_64-pc-linux-gnu. Ok for apply? > > > 2011-07-20 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* gcc.dg/binop-xor1.c: Mark it as expected fail. > =A0 =A0 =A0 =A0* gcc.dg/binop-xor3.c: Likewise. > > Index: gcc-head/gcc/builtins.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/builtins.c > +++ gcc-head/gcc/builtins.c > @@ -6264,13 +6264,22 @@ build_builtin_expect_predicate (location > =A0static tree > =A0fold_builtin_expect (location_t loc, tree arg0, tree arg1) > =A0{ > - =A0tree inner, fndecl; > + =A0tree inner, fndecl, inner_arg0; > =A0 enum tree_code code; > > + =A0/* Distribute the expected value over short-circuiting operators. > + =A0 =A0 See through the cast from truthvalue_type_node to long. =A0*/ > + =A0inner_arg0 =3D arg0; > + =A0while (TREE_CODE (inner_arg0) =3D=3D NOP_EXPR > + =A0 =A0 =A0 =A0&& INTEGRAL_TYPE_P (TREE_TYPE (inner_arg0)) > + =A0 =A0 =A0 =A0&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (inner_arg0,= 0)))) > + =A0 =A0inner_arg0 =3D TREE_OPERAND (inner_arg0, 0); > + > =A0 /* If this is a builtin_expect within a builtin_expect keep the > =A0 =A0 =A0inner one. =A0See through a comparison against a constant. =A0= It > =A0 =A0 =A0might have been added to create a thruthvalue. =A0*/ > - =A0inner =3D arg0; > + =A0inner =3D inner_arg0; > + > =A0 if (COMPARISON_CLASS_P (inner) > =A0 =A0 =A0 && TREE_CODE (TREE_OPERAND (inner, 1)) =3D=3D INTEGER_CST) > =A0 =A0 inner =3D TREE_OPERAND (inner, 0); > @@ -6281,14 +6290,7 @@ fold_builtin_expect (location_t loc, tre > =A0 =A0 =A0 && DECL_FUNCTION_CODE (fndecl) =3D=3D BUILT_IN_EXPECT) > =A0 =A0 return arg0; > > - =A0/* Distribute the expected value over short-circuiting operators. > - =A0 =A0 See through the cast from truthvalue_type_node to long. =A0*/ > - =A0inner =3D arg0; > - =A0while (TREE_CODE (inner) =3D=3D NOP_EXPR > - =A0 =A0 =A0 =A0&& INTEGRAL_TYPE_P (TREE_TYPE (inner)) > - =A0 =A0 =A0 =A0&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (inner, 0)))) > - =A0 =A0inner =3D TREE_OPERAND (inner, 0); > - > + =A0inner =3D inner_arg0; > =A0 code =3D TREE_CODE (inner); > =A0 if (code =3D=3D TRUTH_ANDIF_EXPR || code =3D=3D TRUTH_ORIF_EXPR) > =A0 =A0 { > @@ -6303,13 +6305,13 @@ fold_builtin_expect (location_t loc, tre > =A0 =A0 } > > =A0 /* If the argument isn't invariant then there's nothing else we can d= o. =A0*/ > - =A0if (!TREE_CONSTANT (arg0)) > + =A0if (!TREE_CONSTANT (inner_arg0)) > =A0 =A0 return NULL_TREE; > > =A0 /* If we expect that a comparison against the argument will fold to > =A0 =A0 =A0a constant return the constant. =A0In practice, this means a t= rue > =A0 =A0 =A0constant or the address of a non-weak symbol. =A0*/ > - =A0inner =3D arg0; > + =A0inner =3D inner_arg0; > =A0 STRIP_NOPS (inner); > =A0 if (TREE_CODE (inner) =3D=3D ADDR_EXPR) > =A0 =A0 { > 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 > @@ -7665,11 +7665,11 @@ fold_unary_loc (location_t loc, enum tre > =A0 =A0 =A0 =A0 =A0 =A0 non-integral type. > =A0 =A0 =A0 =A0 =A0 =A0 Do not fold the result as that would not simplify= further, also > =A0 =A0 =A0 =A0 =A0 =A0 folding again results in recursions. =A0*/ > - =A0 =A0 =A0 =A0 if (INTEGRAL_TYPE_P (type)) > + =A0 =A0 =A0 =A0 if (TREE_CODE (type) =3D=3D BOOLEAN_TYPE) > =A0 =A0 =A0 =A0 =A0 =A0return build2_loc (loc, TREE_CODE (op0), type, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_OPERAND = (op0, 0), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_OPERAND = (op0, 1)); > - =A0 =A0 =A0 =A0 else > + =A0 =A0 =A0 =A0 else if (!INTEGRAL_TYPE_P (type)) > =A0 =A0 =A0 =A0 =A0 =A0return build3_loc (loc, COND_EXPR, type, op0, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_convert = (type, boolean_true_node), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_convert = (type, boolean_false_node)); > Index: gcc-head/gcc/tree-ssa.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/tree-ssa.c > +++ gcc-head/gcc/tree-ssa.c > @@ -1306,10 +1306,10 @@ useless_type_conversion_p (tree outer_ty > =A0 =A0 =A0 =A0 =A0|| TYPE_PRECISION (inner_type) !=3D TYPE_PRECISION (ou= ter_type)) > =A0 =A0 =A0 =A0return false; > > - =A0 =A0 =A0/* Preserve conversions to BOOLEAN_TYPE if it is not of prec= ision > - =A0 =A0 =A0 =A0 one. =A0*/ > - =A0 =A0 =A0if (TREE_CODE (inner_type) !=3D BOOLEAN_TYPE > - =A0 =A0 =A0 =A0 && TREE_CODE (outer_type) =3D=3D BOOLEAN_TYPE > + =A0 =A0 =A0/* Preserve conversions to/from BOOLEAN_TYPE if types are not > + =A0 =A0 =A0 =A0of precision one. =A0*/ > + =A0 =A0 =A0if (((TREE_CODE (inner_type) =3D=3D BOOLEAN_TYPE) > + =A0 =A0 =A0 =A0 =A0!=3D (TREE_CODE (outer_type) =3D=3D BOOLEAN_TYPE)) > =A0 =A0 =A0 =A0 =A0&& TYPE_PRECISION (outer_type) !=3D 1) > =A0 =A0 =A0 =A0return false; > > Index: gcc-head/gcc/testsuite/gcc.dg/binop-xor1.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/testsuite/gcc.dg/binop-xor1.c > +++ gcc-head/gcc/testsuite/gcc.dg/binop-xor1.c > @@ -7,8 +7,5 @@ foo (int a, int b, int c) > =A0 return ((a && !b && c) || (!a && b && c)); > =A0} > > -/* We expect to see ""; confirm that, so that we know to count > - =A0 it in the real test. =A0*/ > -/* { dg-final { scan-tree-dump-times "\]*>" 5 "optimized" } } */ > -/* { dg-final { scan-tree-dump-times "\\\^" 1 "optimized" } } */ > +/* { dg-final { scan-tree-dump-times "\\\^" 1 "optimized" { xfail > *-*-* } } } */ > =A0/* { dg-final { cleanup-tree-dump "optimized" } } */ > Index: gcc-head/gcc/testsuite/gcc.dg/binop-xor3.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/testsuite/gcc.dg/binop-xor3.c > +++ gcc-head/gcc/testsuite/gcc.dg/binop-xor3.c > @@ -7,8 +7,5 @@ foo (int a, int b) > =A0 return ((a && !b) || (!a && b)); > =A0} > > -/* We expect to see ""; confirm that, so that we know to count > - =A0 it in the real test. =A0*/ > -/* { dg-final { scan-tree-dump-times "\]*>" 1 "optimized" } } */ > -/* { dg-final { scan-tree-dump-times "\\\^" 1 "optimized" } } */ > +/* { dg-final { scan-tree-dump-times "\\\^" 1 "optimized" { xfail > *-*-* } } } */ > =A0/* { dg-final { cleanup-tree-dump "optimized" } } */ > Index: gcc-head/gcc/tree-ssa-forwprop.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/tree-ssa-forwprop.c > +++ gcc-head/gcc/tree-ssa-forwprop.c > @@ -1874,6 +1874,50 @@ simplify_bitwise_binary (gimple_stmt_ite > =A0 =A0 =A0 return true; > =A0 =A0 } > > + =A0/* See if we can combine comparisons for & or |. =A0*/ > + =A0if (TREE_CODE_CLASS (def1_code) =3D=3D tcc_comparison > + =A0 =A0 =A0&& TREE_CODE_CLASS (def2_code) =3D=3D tcc_comparison) > + =A0 =A0{ > + =A0 =A0 =A0if (code =3D=3D BIT_AND_EXPR) > + =A0 =A0 =A0 res =3D maybe_fold_and_comparisons (def1_code, def1_arg1, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 gimple_assign_rhs2 (def1), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 def2_code, def2_arg1, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 gimple_assign_rhs2 (def2)); > + =A0 =A0 =A0else if (code =3D=3D BIT_IOR_EXPR) > + =A0 =A0 =A0 res =3D maybe_fold_or_comparisons (def1_code, def1_arg1, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 gimple_assign_rhs2 (def1), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 def2_code, def2_arg1, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 gimple_assign_rhs2 (def2)); > + > + =A0 =A0 =A0/* We handle here only constant results and > + =A0 =A0 =A0 =A0 cases (X cmp-1 Y) | (X cmp-2 Y) -> X cmp-3 Y. =A0*/ > + =A0 =A0 =A0if (res && TREE_CODE (res) !=3D INTEGER_CST > + =A0 =A0 =A0 =A0 && (TREE_CODE_CLASS (TREE_CODE (res)) !=3D tcc_comparis= on > + =A0 =A0 =A0 =A0 =A0 =A0 || TREE_OPERAND (res, 0) !=3D def1_arg1 > + =A0 =A0 =A0 =A0 =A0 =A0 || TREE_OPERAND (res, 1) !=3D gimple_assign_rhs= 2 (def1))) > + =A0 =A0 =A0 res =3D NULL_TREE; > + =A0 =A0 =A0if (res) > + =A0 =A0 =A0 =A0{ > + =A0 =A0 =A0 =A0 /* maybe_fold_and_comparisons and maybe_fold_or_compari= sons > + =A0 =A0 =A0 =A0 =A0 =A0always give us a boolean_type_node value back. = =A0If the original > + =A0 =A0 =A0 =A0 =A0 =A0BIT_AND_EXPR or BIT_IOR_EXPR was of a wider inte= ger type, > + =A0 =A0 =A0 =A0 =A0 =A0we need to convert. =A0*/ > + =A0 =A0 =A0 =A0 if (TREE_CODE (res) =3D=3D INTEGER_CST) > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 if (!useless_type_conversion_p (TREE_TYPE (arg1= ), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 TREE_TYPE (res))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 res =3D fold_convert (TREE_TYPE (arg1), res= ); > + =A0 =A0 =A0 =A0 =A0 =A0 gimple_assign_set_rhs_from_tree (gsi, res); > + =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 else > + =A0 =A0 =A0 =A0 =A0 gimple_assign_set_rhs_with_ops (gsi, TREE_CODE (res= ), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 TREE_OPERAND (res, 0), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 TREE_OPERAND (res, 1)); > + > + =A0 =A0 =A0 =A0 update_stmt (gsi_stmt (*gsi)); > + =A0 =A0 =A0 =A0 return true; > + =A0 =A0 =A0 } > + =A0 =A0} > =A0 return false; > =A0} >