From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14106 invoked by alias); 12 Jul 2011 12:21:56 -0000 Received: (qmail 14095 invoked by uid 22791); 12 Jul 2011 12:21:53 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_TM X-Spam-Check-By: sourceware.org Received: from mail-qy0-f175.google.com (HELO mail-qy0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Jul 2011 12:21:35 +0000 Received: by qyk30 with SMTP id 30so1981824qyk.20 for ; Tue, 12 Jul 2011 05:21:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.115.21 with SMTP id g21mr4409305qcq.230.1310473294532; Tue, 12 Jul 2011 05:21:34 -0700 (PDT) Received: by 10.229.38.195 with HTTP; Tue, 12 Jul 2011 05:21:34 -0700 (PDT) In-Reply-To: References: Date: Tue, 12 Jul 2011 12:25:00 -0000 Message-ID: Subject: Re: [patch tree-optimization]: [2 of 3]: Boolify compares & more From: Kai Tietz To: Richard Guenther 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/msg00903.txt.bz2 2011/7/12 Richard Guenther : > On Tue, Jul 12, 2011 at 11:48 AM, Kai Tietz wro= te: >> 2011/7/12 Richard Guenther : >>> On Mon, Jul 11, 2011 at 5:37 PM, Kai Tietz wr= ote: >>>> 2011/7/8 Richard Guenther : >>>>> On Fri, Jul 8, 2011 at 1:32 PM, Kai Tietz w= rote: >>>>>> 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 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 s= trictly >>>>>>>> necessary - as long as fold-const handles 1-bit precision bitwise-= expression >>>>>>>> with truth-logic - but it has shown to short-cut some expensier fo= lding. 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 exp= ected. >>>>>>>> >>>>>>>> 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 condit= ion >>>>>>>> equal to vector-type. >>>>>>>> But this is a subject for a different patch and not addressed by t= his series. >>>>>>>> >>>>>>>> There is a regressions in tree-ssa/vrp47.c, and the fix is address= ed >>>>>>>> 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 resu= lt >>>>>>>> =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): Add= 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 cond= ition >>>>>>>> =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 s= implify 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), ty= pe, >>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_O= PERAND (op0, 0), >>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_O= PERAND (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, op= 0, >>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_c= onvert (type, boolean_true_node), >>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_c= onvert (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_OPERAN= D (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 resul= ts. =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 v= alues, 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, TR= EE_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 oper= and type and doesn't >>>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 automatically uses boolean_type as res= ult, 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, TR= EE_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_O= PERAND (*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_T= YPE (*expr_p); >>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *expr_p =3D gimple_booli= fy (*expr_p); >>>>>>>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!useless_type_conver= sion_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= _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_mod= e_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_ty= pe))) >>>>>>>> - =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_PRECIS= ION (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= 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_T= YPE)) >>>>>>>> =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= (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 lim= its 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 he= re >>>> 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. Kai