From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18693 invoked by alias); 12 Jul 2011 14:10:36 -0000 Received: (qmail 18679 invoked by uid 22791); 12 Jul 2011 14:10:34 -0000 X-SWARE-Spam-Status: No, hits=-2.2 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-yx0-f175.google.com (HELO mail-yx0-f175.google.com) (209.85.213.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Jul 2011 14:10:13 +0000 Received: by yxi19 with SMTP id 19so2263452yxi.20 for ; Tue, 12 Jul 2011 07:10:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.151.149.4 with SMTP id b4mr114281ybo.365.1310479812346; Tue, 12 Jul 2011 07:10:12 -0700 (PDT) Received: by 10.151.144.19 with HTTP; Tue, 12 Jul 2011 07:10:12 -0700 (PDT) In-Reply-To: References: Date: Tue, 12 Jul 2011 14:38: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/msg00915.txt.bz2 On Tue, Jul 12, 2011 at 2:21 PM, Kai Tietz wrote: > 2011/7/12 Richard Guenther : >> On Tue, Jul 12, 2011 at 11:48 AM, Kai Tietz wr= ote: >>> 2011/7/12 Richard Guenther : >>>> On Mon, Jul 11, 2011 at 5:37 PM, Kai Tietz w= rote: >>>>> 2011/7/8 Richard Guenther : >>>>>> On Fri, Jul 8, 2011 at 1:32 PM, Kai Tietz = wrote: >>>>>>> 2011/7/8 Richard Guenther : >>>>>>>> On Thu, Jul 7, 2011 at 6:07 PM, Kai Tietz wrote: >>>>>>>>> Hello, >>>>>>>>> >>>>>>>>> This patch - second of series - adds boolification of comparision= s in >>>>>>>>> gimplifier. =A0For this >>>>>>>>> casts from/to boolean are marked as not-useless. And in fold_unar= y_loc >>>>>>>>> casts to non-boolean integral types are preserved. >>>>>>>>> The hunk in tree-ssa-forwprop.c in combine_cond-expr_cond is not = strictly >>>>>>>>> necessary - as long as fold-const handles 1-bit precision bitwise= -expression >>>>>>>>> with truth-logic - but it has shown to short-cut some expensier f= olding. So >>>>>>>>> I kept it within this patch. >>>>>>>> >>>>>>>> Please split it out. =A0Also ... >>>>>>>> >>>>>>>>> >>>>>>>>> The adjusted testcase gcc.dg/uninit-15.c indicates that due >>>>>>>>> optimization we loose >>>>>>>>> in this case variables declaration. =A0But this might be to be ex= pected. >>>>>>>>> >>>>>>>>> In vectorization we have a regression in gcc.dg/vect/vect-cond-3.c >>>>>>>>> test-case. =A0It's caused >>>>>>>>> by always having boolean-type on conditions. =A0So vectorizer sees >>>>>>>>> different types, which >>>>>>>>> aren't handled by vectorizer right now. =A0Maybe this issue could= be >>>>>>>>> special-cased for >>>>>>>>> boolean-types in tree-vect-loop, by making operand for used condi= tion >>>>>>>>> equal to vector-type. >>>>>>>>> But this is a subject for a different patch and not addressed by = this series. >>>>>>>>> >>>>>>>>> There is a regressions in tree-ssa/vrp47.c, and the fix is addres= sed >>>>>>>>> by the 3rd patch of this >>>>>>>>> series. >>>>>>>>> >>>>>>>>> Bootstrapped and regression tested for all standard-languages (pl= us >>>>>>>>> Ada and Obj-C++) on host x86_64-pc-linux-gnu. >>>>>>>>> >>>>>>>>> Ok for apply? >>>>>>>>> >>>>>>>>> Regards, >>>>>>>>> Kai >>>>>>>>> >>>>>>>>> >>>>>>>>> ChangeLog >>>>>>>>> >>>>>>>>> 2011-07-07 =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* gimplify.c (gimple_boolify): Handle boolification >>>>>>>>> =A0 =A0 =A0 =A0of comparisons. >>>>>>>>> =A0 =A0 =A0 =A0(gimplify_expr): Boolifiy non aggregate-typed >>>>>>>>> =A0 =A0 =A0 =A0comparisons. >>>>>>>>> =A0 =A0 =A0 =A0* tree-cfg.c (verify_gimple_comparison): Check res= ult >>>>>>>>> =A0 =A0 =A0 =A0type of comparison expression. >>>>>>>>> =A0 =A0 =A0 =A0* tree-ssa.c (useless_type_conversion_p): Preserve= incompatible >>>>>>>>> =A0 =A0 =A0 =A0casts from/to boolean, >>>>>>>>> =A0 =A0 =A0 =A0* tree-ssa-forwprop.c (combine_cond_expr_cond): Ad= d simplification >>>>>>>>> =A0 =A0 =A0 =A0support for one-bit-precision typed X for cases X = !=3D 0 and X =3D=3D 0. >>>>>>>>> =A0 =A0 =A0 =A0(forward_propagate_comparison): Adjust test of con= dition >>>>>>>>> =A0 =A0 =A0 =A0result. >>>>>>>>> >>>>>>>>> >>>>>>>>> =A0 =A0 =A0 =A0* gcc.dg/tree-ssa/builtin-expect-5.c: Adjusted. >>>>>>>>> =A0 =A0 =A0 =A0* gcc.dg/tree-ssa/pr21031.c: Likewise. >>>>>>>>> =A0 =A0 =A0 =A0* gcc.dg/tree-ssa/pr30978.c: Likewise. >>>>>>>>> =A0 =A0 =A0 =A0* gcc.dg/tree-ssa/ssa-fre-6.c: Likewise. >>>>>>>>> =A0 =A0 =A0 =A0* gcc.dg/binop-xor1.c: Mark it as expected fail. >>>>>>>>> =A0 =A0 =A0 =A0* gcc.dg/binop-xor3.c: Likewise. >>>>>>>>> =A0 =A0 =A0 =A0* gcc.dg/uninit-15.c: Adjust reported message. >>>>>>>>> >>>>>>>>> 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), t= ype, >>>>>>>>> =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, o= p0, >>>>>>>>> =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/gimplify.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/gimplify.c >>>>>>>>> +++ gcc-head/gcc/gimplify.c >>>>>>>>> @@ -2842,18 +2842,23 @@ gimple_boolify (tree expr) >>>>>>>>> >>>>>>>>> =A0 =A0 case TRUTH_NOT_EXPR: >>>>>>>>> =A0 =A0 =A0 TREE_OPERAND (expr, 0) =3D gimple_boolify (TREE_OPERA= ND (expr, 0)); >>>>>>>>> - =A0 =A0 =A0/* FALLTHRU */ >>>>>>>>> >>>>>>>>> - =A0 =A0case EQ_EXPR: case NE_EXPR: >>>>>>>>> - =A0 =A0case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR: >>>>>>>>> =A0 =A0 =A0 /* These expressions always produce boolean results. = =A0*/ >>>>>>>>> - =A0 =A0 =A0TREE_TYPE (expr) =3D boolean_type_node; >>>>>>>>> + =A0 =A0 =A0if (TREE_CODE (type) !=3D BOOLEAN_TYPE) >>>>>>>>> + =A0 =A0 =A0 TREE_TYPE (expr) =3D boolean_type_node; >>>>>>>>> =A0 =A0 =A0 return expr; >>>>>>>>> >>>>>>>>> =A0 =A0 default: >>>>>>>>> + =A0 =A0 =A0if (COMPARISON_CLASS_P (expr)) >>>>>>>>> + =A0 =A0 =A0 { >>>>>>>>> + =A0 =A0 =A0 =A0 /* There expressions always prduce boolean resu= lts. =A0*/ >>>>>>>>> + =A0 =A0 =A0 =A0 if (TREE_CODE (type) !=3D BOOLEAN_TYPE) >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 TREE_TYPE (expr) =3D boolean_type_node; >>>>>>>>> + =A0 =A0 =A0 =A0 return expr; >>>>>>>>> + =A0 =A0 =A0 } >>>>>>>>> =A0 =A0 =A0 /* Other expressions that get here must have boolean = values, but >>>>>>>>> =A0 =A0 =A0 =A0 might need to be converted to the appropriate mod= e. =A0*/ >>>>>>>>> - =A0 =A0 =A0if (type =3D=3D boolean_type_node) >>>>>>>>> + =A0 =A0 =A0if (TREE_CODE (type) =3D=3D BOOLEAN_TYPE) >>>>>>>>> =A0 =A0 =A0 =A0return expr; >>>>>>>>> =A0 =A0 =A0 return fold_convert_loc (loc, boolean_type_node, expr= ); >>>>>>>>> =A0 =A0 } >>>>>>>>> @@ -6763,7 +6768,7 @@ gimplify_expr (tree *expr_p, gimple_seq >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0tree org_type =3D TREE_TYPE (*expr_p); >>>>>>>>> >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0*expr_p =3D gimple_boolify (*expr_p); >>>>>>>>> - =A0 =A0 =A0 =A0 =A0 if (org_type !=3D boolean_type_node) >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 if (!useless_type_conversion_p (org_type, T= REE_TYPE (*expr_p))) >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0{ >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*expr_p =3D fold_convert (org_type= , *expr_p); >>>>>>>> >>>>>>>> Use fold_convert_loc with saved_location >>>>>>> >>>>>>> Oh, good catch. Yes, I will adjust that. >>>>>>> >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D GS_OK; >>>>>>>>> @@ -7208,7 +7213,7 @@ gimplify_expr (tree *expr_p, gimple_seq >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_truth_not_expr) happily uses ope= rand type and doesn't >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 automatically uses boolean_type as re= sult, we need to keep >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 orignal type. =A0*/ >>>>>>>>> - =A0 =A0 =A0 =A0 =A0 if (org_type !=3D boolean_type_node) >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 if (!useless_type_conversion_p (org_type, T= REE_TYPE (*expr_p))) >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0{ >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*expr_p =3D fold_convert (org_type= , *expr_p); >>>>>>>> >>>>>>>> Likewise. =A0Maybe this fixes the diagnostic regression. >>>>>>>> >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D GS_OK; >>>>>>>>> @@ -7288,7 +7293,19 @@ gimplify_expr (tree *expr_p, gimple_seq >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0tree type =3D TREE_TYPE (TREE_= OPERAND (*expr_p, 1)); >>>>>>>>> >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!AGGREGATE_TYPE_P (type)) >>>>>>>>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto expr_2; >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 { >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tree org_type =3D TREE_= TYPE (*expr_p); >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *expr_p =3D gimple_bool= ify (*expr_p); >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!useless_type_conve= rsion_p (org_type, >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_TYPE (*expr_p))) >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 { >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *expr_p =3D fol= d_convert_loc (saved_location, >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 org_type, *expr_p); >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D GS_OK; >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto expr_2; >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else if (TYPE_MODE (type) !=3D= BLKmode) >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D gimplify_scalar_mo= de_aggregate_compare (expr_p); >>>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else >>>>>>>>> Index: gcc-head/gcc/tree-cfg.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-cfg.c >>>>>>>>> +++ gcc-head/gcc/tree-cfg.c >>>>>>>>> @@ -3203,7 +3203,9 @@ verify_gimple_comparison (tree type, tre >>>>>>>>> =A0 =A0 =A0 =A0&& (!POINTER_TYPE_P (op0_type) >>>>>>>>> =A0 =A0 =A0 =A0 =A0 || !POINTER_TYPE_P (op1_type) >>>>>>>>> =A0 =A0 =A0 =A0 =A0 || TYPE_MODE (op0_type) !=3D TYPE_MODE (op1_t= ype))) >>>>>>>>> - =A0 =A0 =A0|| !INTEGRAL_TYPE_P (type)) >>>>>>>>> + =A0 =A0 =A0|| !INTEGRAL_TYPE_P (type) >>>>>>>>> + =A0 =A0 =A0|| (TREE_CODE (type) !=3D BOOLEAN_TYPE >>>>>>>>> + =A0 =A0 =A0 =A0 && TYPE_PRECISION (type) !=3D 1)) >>>>>>>>> =A0 =A0 { >>>>>>>>> =A0 =A0 =A0 error ("type mismatch in comparison expression"); >>>>>>>>> =A0 =A0 =A0 debug_generic_expr (type); >>>>>>>>> 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_PRECI= SION (outer_type)) >>>>>>>>> =A0 =A0 =A0 =A0return false; >>>>>>>>> >>>>>>>>> - =A0 =A0 =A0/* Preserve conversions to BOOLEAN_TYPE if it is not= of precision >>>>>>>>> - =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 type= s 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/tree-ssa/builtin-expect-5.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/tree-ssa/builtin-expect-5.c >>>>>>>>> +++ gcc-head/gcc/testsuite/gcc.dg/tree-ssa/builtin-expect-5.c >>>>>>>>> @@ -11,5 +11,5 @@ f (int i, float j) >>>>>>>>> >>>>>>>>> =A0/* { dg-final { scan-tree-dump-times { if } 2 "forwprop1"} } */ >>>>>>>>> =A0/* { dg-final { scan-tree-dump {builtin_expect[^\n]*, 0\);\n[^= \n]*if} >>>>>>>>> "forwprop1"} } */ >>>>>>>>> -/* { dg-final { scan-tree-dump {builtin_expect[^\n]*, 1\);\n[^\n= ]*if} >>>>>>>>> "forwprop1"} } */ >>>>>>>>> +/* { dg-final { scan-tree-dump-not {builtin_expect[^\n]*, >>>>>>>>> 1\);\n[^\n]*if} "forwprop1"} } */ >>>>>>>> >>>>>>>> Hm? =A0Why that? >>>>>>>> >>>>>>>>> =A0/* { dg-final { cleanup-tree-dump "forwprop?" } } */ >>>>>>>>> Index: gcc-head/gcc/testsuite/gcc.dg/tree-ssa/pr21031.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/tree-ssa/pr21031.c >>>>>>>>> +++ gcc-head/gcc/testsuite/gcc.dg/tree-ssa/pr21031.c >>>>>>>>> @@ -16,5 +16,5 @@ foo (int a) >>>>>>>>> =A0 =A0 return 0; >>>>>>>>> =A0} >>>>>>>>> >>>>>>>>> -/* { dg-final { scan-tree-dump-times "Replaced" 2 "forwprop1"} }= */ >>>>>>>>> +/* { dg-final { scan-tree-dump-times "Replaced" 1 "forwprop1"} }= */ >>>>>>>>> =A0/* { dg-final { cleanup-tree-dump "forwprop1" } } */ >>>>>>>>> Index: gcc-head/gcc/testsuite/gcc.dg/tree-ssa/pr30978.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/tree-ssa/pr30978.c >>>>>>>>> +++ gcc-head/gcc/testsuite/gcc.dg/tree-ssa/pr30978.c >>>>>>>>> @@ -10,5 +10,5 @@ int foo(int a) >>>>>>>>> =A0 return e; >>>>>>>>> =A0} >>>>>>>>> >>>>>>>>> -/* { dg-final { scan-tree-dump "e_. =3D a_..D. > 0;" "optimized"= } } */ >>>>>>>>> +/* { dg-final { scan-tree-dump " =3D a_..D. > 0;" "optimized" } = } */ >>>>>>>>> =A0/* { dg-final { cleanup-tree-dump "optimized" } } */ >>>>>>>>> Index: gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-6.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/tree-ssa/ssa-fre-6.c >>>>>>>>> +++ gcc-head/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-6.c >>>>>>>>> @@ -2,5 +2,5 @@ >>>>>>>>> =A0/* { dg-options "-O -fdump-tree-fre1-details" } */ >>>>>>>>> >>>>>>>>> =A0int i; int foo(void) { i =3D 2; int j =3D i * 2; int k =3D i += 2; return j =3D=3D k; } >>>>>>>>> -/* { dg-final { scan-tree-dump-times "Replaced " 5 "fre1" } } */ >>>>>>>>> +/* { dg-final { scan-tree-dump-times "Replaced " 6 "fre1" } } */ >>>>>>>>> =A0/* { dg-final { cleanup-tree-dump "fre1" } } */ >>>>>>>>> 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 >>>>>>>>> @@ -367,9 +367,61 @@ combine_cond_expr_cond (location_t loc, >>>>>>>>> =A0 gcc_assert (TREE_CODE_CLASS (code) =3D=3D tcc_comparison); >>>>>>>>> >>>>>>>>> =A0 t =3D fold_binary_loc (loc, code, type, op0, op1); >>>>>>>>> + >>>>>>>>> + =A0if (!t && INTEGRAL_TYPE_P (TREE_TYPE (op1)) >>>>>>>>> + =A0 =A0 =A0&& TYPE_PRECISION (TREE_TYPE (op1)) =3D=3D 1 >>>>>>>>> + =A0 =A0 =A0&& (code =3D=3D EQ_EXPR || code =3D=3D NE_EXPR)) >>>>>>>>> + =A0 =A0{ >>>>>>>>> + =A0 =A0 =A0if (TREE_CODE (op1) =3D=3D INTEGER_CST) >>>>>>>>> + =A0 =A0 =A0 =A0{ >>>>>>>>> + =A0 =A0 =A0 =A0 if (integer_onep (op1)) >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 { >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 op1 =3D fold_convert_loc (loc, TREE_TYP= E (op1), integer_zero_node); >>>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 code =3D (code =3D=3D NE_EXPR ? EQ_EXPR= : NE_EXPR); >>>>>>>> >>>>>>>> So you change truthvalue !=3D/=3D=3D 1 to truthvalue =3D=3D/!=3D 0= and then >>>>>>>> recurse ... that doesn't make sense to me and is super-ugly. >>>>>>>> What's the testcase that made you add all this code? >>>>>>> >>>>>>> Well, the convert from truthvalue !=3D/=3D=3D 1 to !=3D/=3D=3D 0 li= mits the amount >>>>>>> of cases to handle. As for truthvalued X the we have then just to >>>>>>> handle two cases. X !=3D 0 -> X, and X =3D=3D 0 -> (X ^ 1). >>>>>>> The recursion is someting I saw as existing pattern (for the same >>>>>>> thing) in truth-op folding in fold-const. >>>>>>> >>>>>>> Actual I can remove this optimization here, as it should be convered >>>>>>> by VRP already (when VRP handles 1-bit precision bitwise ops proper= ). >>>>>> >>>>>> We should have a canonical form for those compares and change >>>>>> them accordingly, best in fold_stmt. >>>>>> >>>>>> Richard. >>>>> >>>>> Hmm, I tried to add this code-pattern to fold_stmt, but for this kind >>>>> of branch it seems not to be invoked at all. At least not now without >>>>> boolification of compares. =A0One nit I found for GIMPLE_BINARY, as h= ere >>>>> just patterns getting replaced, which have fewer number of ops then >>>>> original statement. This check looks a bit bogus. >>>>> For getting this normalization right now in a consistant way, >>>>> fold-const might be right now the better place to handle this. >>>> >>>> It gets invoked (well, should get invoked) when anyone changes the >>>> statement. =A0If it is present in that form from the beginning then we >>>> lack canonicalization in fold and/or gimplification. >>>> >>>> I suppose you have a testcase? >>>> >>>> Richard. >>>> >>>>> Regards, >>>>> Kai >>>>> >>> >>> Yes, testcase looks like this: >>> >>> int foo (_Bool a, _Bool b) >>> { >>> =A0return a !=3D ((b | !b)); >>> } >>> >>> while reduces to >>> ... >>> return a !=3D 1; =A0right now, and not a =3D=3D 0 (as a is boolean) >> >> fold_stmt should be called when copyprop produces a !=3D 1 >> via substitute_and_fold: >> >> =A0 =A0 =A0 =A0 =A0/* Replace real uses in the statement. =A0*/ >> =A0 =A0 =A0 =A0 =A0if (get_value_fn) >> =A0 =A0 =A0 =A0 =A0 =A0did_replace |=3D replace_uses_in (stmt, get_value= _fn); >> >> =A0 =A0 =A0 =A0 =A0/* If we made a replacement, fold the statement. =A0*/ >> =A0 =A0 =A0 =A0 =A0if (did_replace) >> =A0 =A0 =A0 =A0 =A0 =A0fold_stmt (&oldi); > > Well, I added this transformation for test in fold-const s > fold_comparison function and still it doesn't get converted. > I assume this caused by the fact that we do this optimization in > forwprop on argument's of the comparison, so no try to fold statement > happens here at this place. The non-canonical comparison appears after copyprop for me. Richard. > Kai >