From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9907 invoked by alias); 20 Jul 2011 17:12:17 -0000 Received: (qmail 9867 invoked by uid 22791); 20 Jul 2011 17:12:12 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-qw0-f47.google.com (HELO mail-qw0-f47.google.com) (209.85.216.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Jul 2011 17:11:53 +0000 Received: by qwh5 with SMTP id 5so273927qwh.20 for ; Wed, 20 Jul 2011 10:11:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.7.212 with SMTP id e20mr7001428qce.192.1311181912176; Wed, 20 Jul 2011 10:11:52 -0700 (PDT) Received: by 10.229.38.195 with HTTP; Wed, 20 Jul 2011 10:11:52 -0700 (PDT) In-Reply-To: References: Date: Wed, 20 Jul 2011 17:43: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/msg01655.txt.bz2 2011/7/20 Richard Guenther : > On Wed, Jul 20, 2011 at 3:31 PM, Kai Tietz wrot= e: >> 2011/7/20 Richard Guenther : >>> On Wed, Jul 20, 2011 at 3:05 PM, Kai Tietz wr= ote: >>>> Hello, >>>> >>>> this is the revised version of the partial pre-approved patch for pres= erving >>>> type-casts from/to boolean-types. =A0It fixes additionally the regress= ion in >>>> tree-ssa/builtin-expect-5.c testcase, which was caused by fold_builtin= _expect. >>>> Additionally there was a regression in gcc.dg/pr28685-1.c, which is fi= xed by >>>> the change in tree-ssa-forwprop.c's function simplify_bitwise_binary. = =A0This >>>> is just temporary necessary. =A0As soon as we are boolifying compariso= ns 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. =A0= They >>> can then wait for the boolification patch. >>> >>> Can you explain the fold_builtin_expect change? =A0I'm lost in the maze >>> of inner/inner_arg0/arg0 renaming game. =A0It looks as if the patch only >>> moves stuff - but that can't possibly be the case. =A0So, what's going = on >>> there? >> >> Well, the issue is here that fold_builtin_expect checks here for a >> comparison. =A0If this comparison was created initially with a >> boolean-type, the cast to 'long' will be in tree arg0 =3D (long) >> CMP-with-boolean-type, as we are preserving here casts from >> boolean-types (see the fold-const change). So we need to see through >> this casts to match the compare and call cases. So I moved this "see >> through" part before first pattern-match and introduced here a >> helper-variable inner_arg0 to avoid double while-loop. The "inner" >> variable might get invalid >> ... >> =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); >> ... >> >> These are those "prefixed casts" you were asking in the other patch abou= t. > > I see. =A0So, if the builtin.c parts bootstrap & test ok then they are ok > to commit separately. > > Thanks, > Richard. > >> Regards, >> Kai >> Hello, 2011-07-20 Kai Tietz * builtins.c (fold_builtin_expect): See through the cast from truthvalue_type_node to long. Bootstrapped and regression tested for all languages (including Ada and Obj-C++) on host x86_64-pc-linux-gnu. Applied as pre-approved. Regards, Kai 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 static tree fold_builtin_expect (location_t loc, tree arg0, tree arg1) { - tree inner, fndecl; + tree inner, fndecl, inner_arg0; enum tree_code code; + /* Distribute the expected value over short-circuiting operators. + See through the cast from truthvalue_type_node to long. */ + inner_arg0 =3D arg0; + while (TREE_CODE (inner_arg0) =3D=3D NOP_EXPR + && INTEGRAL_TYPE_P (TREE_TYPE (inner_arg0)) + && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (inner_arg0, 0)))) + inner_arg0 =3D TREE_OPERAND (inner_arg0, 0); + /* If this is a builtin_expect within a builtin_expect keep the inner one. See through a comparison against a constant. It might have been added to create a thruthvalue. */ - inner =3D arg0; + inner =3D inner_arg0; + if (COMPARISON_CLASS_P (inner) && TREE_CODE (TREE_OPERAND (inner, 1)) =3D=3D INTEGER_CST) inner =3D TREE_OPERAND (inner, 0); @@ -6281,14 +6290,7 @@ fold_builtin_expect (location_t loc, tre && DECL_FUNCTION_CODE (fndecl) =3D=3D BUILT_IN_EXPECT) return arg0; - /* Distribute the expected value over short-circuiting operators. - See through the cast from truthvalue_type_node to long. */ - inner =3D arg0; - while (TREE_CODE (inner) =3D=3D NOP_EXPR - && INTEGRAL_TYPE_P (TREE_TYPE (inner)) - && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (inner, 0)))) - inner =3D TREE_OPERAND (inner, 0); - + inner =3D inner_arg0; code =3D TREE_CODE (inner); if (code =3D=3D TRUTH_ANDIF_EXPR || code =3D=3D TRUTH_ORIF_EXPR) { @@ -6303,13 +6305,13 @@ fold_builtin_expect (location_t loc, tre } /* If the argument isn't invariant then there's nothing else we can do. = */ - if (!TREE_CONSTANT (arg0)) + if (!TREE_CONSTANT (inner_arg0)) return NULL_TREE; /* If we expect that a comparison against the argument will fold to a constant return the constant. In practice, this means a true constant or the address of a non-weak symbol. */ - inner =3D arg0; + inner =3D inner_arg0; STRIP_NOPS (inner); if (TREE_CODE (inner) =3D=3D ADDR_EXPR) { 2011-07-20 Kai Tietz * fold-const.c (fold_unary_loc): Preserve non-boolean-typed casts. * tree-ssa.c (useless_type_conversion_p): Preserve incompatible casts from/to boolean, * builtins.c (fold_builtin_expect): See through the cast from truthvalue_type_node to long. * tree-ssa-forwprop.c (simplify_bitwise_binary): Add simplification for CMP bitwise-binary CMP.