From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14946 invoked by alias); 12 May 2011 18:20:18 -0000 Received: (qmail 14932 invoked by uid 22791); 12 May 2011 18:20:15 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST 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; Thu, 12 May 2011 18:19:59 +0000 Received: by qyk35 with SMTP id 35so3175752qyk.20 for ; Thu, 12 May 2011 11:19:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.76.82 with SMTP id b18mr471050qak.121.1305224397740; Thu, 12 May 2011 11:19:57 -0700 (PDT) Received: by 10.229.33.209 with HTTP; Thu, 12 May 2011 11:19:57 -0700 (PDT) In-Reply-To: References: <201105111153.28024.ebotcazou@adacore.com> Date: Thu, 12 May 2011 21:33:00 -0000 Message-ID: Subject: Re: [patch gimplifier]: Boolify more strict conditional expressions and transform simple form to binary From: Kai Tietz To: Richard Guenther Cc: Eric Botcazou , gcc-patches@gcc.gnu.org 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-05/txt/msg00923.txt.bz2 2011/5/12 Richard Guenther : > On Thu, May 12, 2011 at 3:29 PM, Kai Tietz wrot= e: >> While testing some other issues with C++'s __java_boolean type >> occurred. So I adjusted check in test-cfg.c as you suggested. >> Additionally due the fact that we are now boolifying conditions for >> even BOOLEAN_TYPE'ed cases (for making sure inner arms are boolified, >> too), we possibly would alter here truth-type provided by FE. To >> restore original type (for types !=3D boolean-type), we do type >> conversion always back to FE's used type for truth-AND/OR/XOR/etc as >> result. > > boolean_type_node is the only BOOLEAN_TYPE node we have, > so please remove the !=3D/=3D=3D boolean_type_node checks again, or, > if you want more visual consistency with the adjustment gimple_boolify > makes replace them with !=3D/=3D=3D boolean_type_node comparisons > completely. > > Ok with either change. > > Thanks, > Richard. > >> Patch bootstrapped with all languages on x86_64-pc-linux-gnu >> (multilib). Ok for apply? >> >> Regards, >> Kai >> >> Index: gcc/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.orig/gcc/gimplify.c =A0 =A0 2011-05-12 09:02:58.946243000 +0200 >> +++ gcc/gcc/gimplify.c =A02011-05-12 15:13:59.534550700 +0200 >> @@ -2824,9 +2824,6 @@ gimple_boolify (tree expr) >> =A0 =A0 =A0 =A0} >> =A0 =A0 } >> >> - =A0if (TREE_CODE (type) =3D=3D BOOLEAN_TYPE) >> - =A0 =A0return expr; >> - >> =A0 switch (TREE_CODE (expr)) >> =A0 =A0 { >> =A0 =A0 case TRUTH_AND_EXPR: >> @@ -2851,6 +2848,9 @@ gimple_boolify (tree expr) >> =A0 =A0 default: >> =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 mode. =A0*/ >> + =A0 =A0 =A0if (TREE_CODE (type) =3D=3D BOOLEAN_TYPE >> + =A0 =A0 =A0 =A0 =A0&& type =3D=3D boolean_type_node) >> + =A0 =A0 =A0 return expr; >> =A0 =A0 =A0 return fold_convert_loc (loc, boolean_type_node, expr); >> =A0 =A0 } >> =A0} >> @@ -4695,31 +4695,6 @@ gimplify_scalar_mode_aggregate_compare ( >> =A0 return GS_OK; >> =A0} >> >> -/* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. =A0EXPR_P >> - =A0 points to the expression to gimplify. >> - >> - =A0 Expressions of the form 'a && b' are gimplified to: >> - >> - =A0 =A0 =A0 a && b ? true : false >> - >> - =A0 LOCUS is the source location to be put on the generated COND_EXPR. >> - =A0 gimplify_cond_expr will do the rest. =A0*/ >> - >> -static enum gimplify_status >> -gimplify_boolean_expr (tree *expr_p, location_t locus) >> -{ >> - =A0/* Preserve the original type of the expression. =A0*/ >> - =A0tree type =3D TREE_TYPE (*expr_p); >> - >> - =A0*expr_p =3D build3 (COND_EXPR, type, *expr_p, >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_convert_loc (locus, type, boo= lean_true_node), >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_convert_loc (locus, type, boo= lean_false_node)); >> - >> - =A0SET_EXPR_LOCATION (*expr_p, locus); >> - >> - =A0return GS_OK; >> -} >> - >> =A0/* Gimplify an expression sequence. =A0This function gimplifies each >> =A0 =A0expression and rewrites the original expression with the last >> =A0 =A0expression of the sequence in GIMPLE form. >> @@ -6762,12 +6737,26 @@ gimplify_expr (tree *expr_p, gimple_seq >> >> =A0 =A0 =A0 =A0case TRUTH_ANDIF_EXPR: >> =A0 =A0 =A0 =A0case TRUTH_ORIF_EXPR: >> - =A0 =A0 =A0 =A0 /* Pass the source location of the outer expression. = =A0*/ >> - =A0 =A0 =A0 =A0 ret =3D gimplify_boolean_expr (expr_p, saved_location); >> - =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 =A0 /* Preserve the original type of the expression an= d the >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0source location of the outer expression. = =A0*/ >> + =A0 =A0 =A0 =A0 =A0 tree org_type =3D TREE_TYPE (*expr_p); >> + =A0 =A0 =A0 =A0 =A0 *expr_p =3D gimple_boolify (*expr_p); >> + =A0 =A0 =A0 =A0 =A0 *expr_p =3D build3_loc (saved_location, COND_EXPR, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 org_ty= pe, *expr_p, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_c= onvert_loc >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (s= aved_location, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0org_type, boolean_true_node), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fold_c= onvert_loc >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (s= aved_location, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0org_type, boolean_false_node)); >> + =A0 =A0 =A0 =A0 =A0 ret =3D GS_OK; >> + =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 =A0 } >> >> =A0 =A0 =A0 =A0case TRUTH_NOT_EXPR: >> - =A0 =A0 =A0 =A0 if (TREE_CODE (TREE_TYPE (*expr_p)) !=3D BOOLEAN_TYPE) >> + =A0 =A0 =A0 =A0 if (TREE_CODE (TREE_TYPE (*expr_p)) !=3D BOOLEAN_TYPE >> + =A0 =A0 =A0 =A0 =A0 =A0 || TREE_CODE (TREE_TYPE (*expr_p)) !=3D boolea= n_type_node) >> =A0 =A0 =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0tree type =3D TREE_TYPE (*expr_p); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0*expr_p =3D fold_convert (type, gimple_boolif= y (*expr_p)); >> @@ -7203,6 +7192,24 @@ gimplify_expr (tree *expr_p, gimple_seq >> =A0 =A0 =A0 =A0case TRUTH_AND_EXPR: >> =A0 =A0 =A0 =A0case TRUTH_OR_EXPR: >> =A0 =A0 =A0 =A0case TRUTH_XOR_EXPR: >> + =A0 =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 =A0 tree org_type =3D TREE_TYPE (*expr_p); >> + >> + =A0 =A0 =A0 =A0 =A0 *expr_p =3D gimple_boolify (*expr_p); >> + >> + =A0 =A0 =A0 =A0 =A0 /* This shouldn't happen, but due fold-const (and = here especially >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0fold_truth_not_expr) happily uses operand t= ype and doesn't >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0automatically uses boolean_type as result, = we need to keep >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0orignal type. =A0*/ >> + =A0 =A0 =A0 =A0 =A0 if (TREE_CODE (org_type) !=3D BOOLEAN_TYPE >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 || TREE_CODE (TREE_TYPE (org_type)) !=3D b= oolean_type_node) >> + =A0 =A0 =A0 =A0 =A0 =A0 { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *expr_p =3D fold_convert (org_type, *expr_= p); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D GS_OK; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 =A0 =A0 =A0 } >> + =A0 =A0 =A0 =A0 } >> + >> =A0 =A0 =A0 =A0 =A0/* Classified as tcc_expression. =A0*/ >> =A0 =A0 =A0 =A0 =A0goto expr_2; >> >> Index: gcc/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.orig/gcc/tree-cfg.c =A0 =A0 2011-05-12 09:02:58.989243000 +0200 >> +++ gcc/gcc/tree-cfg.c =A02011-05-12 14:50:19.656249100 +0200 >> @@ -3541,10 +3541,10 @@ do_pointer_plus_expr_check: >> =A0 =A0 case TRUTH_OR_EXPR: >> =A0 =A0 case TRUTH_XOR_EXPR: >> =A0 =A0 =A0 { >> - =A0 =A0 =A0 /* We allow any kind of integral typed argument and result= . =A0*/ >> - =A0 =A0 =A0 if (!INTEGRAL_TYPE_P (rhs1_type) >> - =A0 =A0 =A0 =A0 =A0 || !INTEGRAL_TYPE_P (rhs2_type) >> - =A0 =A0 =A0 =A0 =A0 || !INTEGRAL_TYPE_P (lhs_type)) >> + =A0 =A0 =A0 /* We allow only boolean typed or compatible argument and = result. =A0*/ >> + =A0 =A0 =A0 if (!useless_type_conversion_p (boolean_type_node, =A0rhs1= _type) >> + =A0 =A0 =A0 =A0 =A0 || !useless_type_conversion_p (boolean_type_node, = =A0rhs2_type) >> + =A0 =A0 =A0 =A0 =A0 || !useless_type_conversion_p (boolean_type_node, = =A0lhs_type)) >> =A0 =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0error ("type mismatch in binary truth expression"= ); >> =A0 =A0 =A0 =A0 =A0 =A0debug_generic_expr (lhs_type); >> > Committed at revision 173711 with removing check for !=3D/=3D=3D boolean_ty= pe_node. Thanks, Kai