From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10607 invoked by alias); 12 Jul 2011 09:22:53 -0000 Received: (qmail 10592 invoked by uid 22791); 12 Jul 2011 09:22:48 -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 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; Tue, 12 Jul 2011 09:22:31 +0000 Received: by ywa12 with SMTP id 12so2144995ywa.20 for ; Tue, 12 Jul 2011 02:22:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.12.19 with SMTP id 19mr4919628ybl.251.1310462549961; Tue, 12 Jul 2011 02:22:29 -0700 (PDT) Received: by 10.151.144.19 with HTTP; Tue, 12 Jul 2011 02:22:29 -0700 (PDT) In-Reply-To: References: Date: Tue, 12 Jul 2011 09:29: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/msg00880.txt.bz2 On Mon, Jul 11, 2011 at 5:37 PM, Kai Tietz wrote: > 2011/7/8 Richard Guenther : >> On Fri, Jul 8, 2011 at 1:32 PM, Kai Tietz wrot= e: >>> 2011/7/8 Richard Guenther : >>>> On Thu, Jul 7, 2011 at 6:07 PM, Kai Tietz wr= ote: >>>>> Hello, >>>>> >>>>> This patch - second of series - adds boolification of comparisions in >>>>> gimplifier. =A0For this >>>>> casts from/to boolean are marked as not-useless. And in fold_unary_loc >>>>> casts to non-boolean integral types are preserved. >>>>> The hunk in tree-ssa-forwprop.c in combine_cond-expr_cond is not stri= ctly >>>>> necessary - as long as fold-const handles 1-bit precision bitwise-exp= ression >>>>> with truth-logic - but it has shown to short-cut some expensier foldi= ng. 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 expect= ed. >>>>> >>>>> 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 condition >>>>> 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 addressed >>>>> by the 3rd patch of this >>>>> series. >>>>> >>>>> Bootstrapped and regression tested for all standard-languages (plus >>>>> 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 result >>>>> =A0 =A0 =A0 =A0type of comparison expression. >>>>> =A0 =A0 =A0 =A0* tree-ssa.c (useless_type_conversion_p): Preserve inc= ompatible >>>>> =A0 =A0 =A0 =A0casts from/to boolean, >>>>> =A0 =A0 =A0 =A0* tree-ssa-forwprop.c (combine_cond_expr_cond): Add si= mplification >>>>> =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 conditi= on >>>>> =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 simp= lify 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_OPER= AND (op0, 0), >>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_OPER= AND (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_conv= ert (type, boolean_true_node), >>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_conv= ert (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_OPERAND (= 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 results.= =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 valu= es, but >>>>> =A0 =A0 =A0 =A0 might need to be converted to the appropriate mode. = =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, TREE_= 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, *e= xpr_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 operand= type and doesn't >>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 automatically uses boolean_type as result= , 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, TREE_= 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, *e= xpr_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_OPER= AND (*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_boolify = (*expr_p); >>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!useless_type_conversio= n_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 fold_co= nvert_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 BLK= mode) >>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D gimplify_scalar_mode_a= ggregate_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_type)= )) >>>>> - =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_PRECISION= (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 types ar= e 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_TYPE (o= p1), integer_zero_node); >>>>> + =A0 =A0 =A0 =A0 =A0 =A0 code =3D (code =3D=3D NE_EXPR ? EQ_EXPR : N= E_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 limits= 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 here > 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. If 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 >