From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2087 invoked by alias); 10 Jun 2011 08:56:27 -0000 Received: (qmail 2076 invoked by uid 22791); 10 Jun 2011 08:56:26 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,TW_HF,TW_TM X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Jun 2011 08:56:12 +0000 Received: by wwf26 with SMTP id 26so2274065wwf.8 for ; Fri, 10 Jun 2011 01:56:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.55.67 with SMTP id t3mr1803460wbg.90.1307696170802; Fri, 10 Jun 2011 01:56:10 -0700 (PDT) Received: by 10.227.37.152 with HTTP; Fri, 10 Jun 2011 01:56:10 -0700 (PDT) In-Reply-To: <1307640882.4798.93.camel@L3G5336.ibm.com> References: <1307640882.4798.93.camel@L3G5336.ibm.com> Date: Fri, 10 Jun 2011 09:05:00 -0000 Message-ID: Subject: Re: [PATCH] Fix PR lto/49302 (corrected) From: Richard Guenther To: "William J. Schmidt" Cc: 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-06/txt/msg00807.txt.bz2 On Thu, Jun 9, 2011 at 7:34 PM, William J. Schmidt wrote: > Richard, thanks for the comments. =A0Here's the revised patch for > expanding cabs in gimple. > > Given the direction this pass is taking, should it eventually be renamed > from cse_sincos to something more general? Eventually yes - but names are just - names ;) Ok with ... > Thanks, > Bill > > > 2011-06-09 =A0Bill Schmidt =A0 > > =A0 =A0 =A0 =A0PR lto/49302 > =A0 =A0 =A0 =A0* tree-ssa-math-opts.c (build_and_insert_ref): New. > =A0 =A0 =A0 =A0(gimple_expand_builtin_pow): Minor cleanup. > =A0 =A0 =A0 =A0(gimple_expand_builtin_cabs): New. > =A0 =A0 =A0 =A0(execute_cse_sincos): Add case for BUILT_IN_CABS. > > > Index: gcc/tree-ssa-math-opts.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/tree-ssa-math-opts.c =A0 =A0(revision 174845) > +++ gcc/tree-ssa-math-opts.c =A0 =A0(working copy) > @@ -1070,6 +1070,22 @@ build_and_insert_binop (gimple_stmt_iterator *gsi, > =A0 return result; > =A0} > > +/* Build a gimple reference operation with the given CODE and argument > + =A0 ARG, assigning the result to a new SSA name for variable TARGET. > + =A0 Insert the statement prior to GSI's current position, and return > + =A0 the fresh SSA name. =A0*/ > + > +static inline tree > +build_and_insert_ref (gimple_stmt_iterator *gsi, location_t loc, tree ty= pe, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tree target, enum tree_code cod= e, tree arg0) > +{ > + =A0tree result =3D make_ssa_name (target, NULL); > + =A0gimple stmt =3D gimple_build_assign (result, build1 (code, type, arg= 0)); > + =A0gimple_set_location (stmt, loc); > + =A0gsi_insert_before (gsi, stmt, GSI_SAME_STMT); > + =A0return result; > +} > + > =A0/* ARG0 and ARG1 are the two arguments to a pow builtin call in GSI > =A0 =A0with location info LOC. =A0If possible, create an equivalent and > =A0 =A0less expensive sequence of statements prior to GSI, and return an > @@ -1124,7 +1140,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *g > =A0 =A0 =A0if we don't have a hardware sqrt insn. =A0*/ > =A0 dconst1_4 =3D dconst1; > =A0 SET_REAL_EXP (&dconst1_4, REAL_EXP (&dconst1_4) - 2); > - =A0hw_sqrt_exists =3D optab_handler(sqrt_optab, mode) !=3D CODE_FOR_not= hing; > + =A0hw_sqrt_exists =3D optab_handler (sqrt_optab, mode) !=3D CODE_FOR_no= thing; > > =A0 if (flag_unsafe_math_optimizations > =A0 =A0 =A0 && sqrtfn > @@ -1306,6 +1322,42 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *g > =A0 return NULL_TREE; > =A0} > > +/* ARG is the argument to a cabs builtin call in GSI with location info > + =A0 LOC. =A0Create a sequence of statements prior to GSI that calculates > + =A0 sqrt(R*R + I*I), where R and I are the real and imaginary components > + =A0 of ARG, respectively. =A0Return an expression holding the result. = =A0*/ > + > +static tree > +gimple_expand_builtin_cabs (gimple_stmt_iterator *gsi, location_t loc, t= ree arg) > +{ > + =A0tree target, real_part, imag_part, addend1, addend2, sum, result; > + =A0tree type =3D TREE_TYPE (TREE_TYPE (arg)); > + =A0tree sqrtfn =3D mathfn_built_in (type, BUILT_IN_SQRT); > + =A0enum machine_mode mode =3D TYPE_MODE (type); > + > + =A0if (!flag_unsafe_math_optimizations > + =A0 =A0 =A0|| !optimize_bb_for_speed_p (gimple_bb (gsi_stmt (*gsi))) > + =A0 =A0 =A0|| !sqrtfn > + =A0 =A0 =A0|| optab_handler (sqrt_optab, mode) =3D=3D CODE_FOR_nothing) > + =A0 =A0return NULL_TREE; > + > + =A0target =3D create_tmp_var (type, "cabs"); use create_tmp_reg instead Thanks, Richard. > + =A0add_referenced_var (target); > + > + =A0real_part =3D build_and_insert_ref (gsi, loc, type, target, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 REA= LPART_EXPR, arg); > + =A0addend1 =3D build_and_insert_binop (gsi, loc, target, MULT_EXPR, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rea= l_part, real_part); > + =A0imag_part =3D build_and_insert_ref (gsi, loc, type, target, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 IMA= GPART_EXPR, arg); > + =A0addend2 =3D build_and_insert_binop (gsi, loc, target, MULT_EXPR, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ima= g_part, imag_part); > + =A0sum =3D build_and_insert_binop (gsi, loc, target, PLUS_EXPR, addend1= , addend2); > + =A0result =3D build_and_insert_call (gsi, loc, &target, sqrtfn, sum); > + > + =A0return result; > +} > + > =A0/* Go through all calls to sin, cos and cexpi and call execute_cse_sin= cos_1 > =A0 =A0on the SSA_NAME argument of each of them. =A0Also expand powi(x,n)= into > =A0 =A0an optimal number of multiplies, when n is a constant. =A0*/ > @@ -1388,6 +1440,21 @@ execute_cse_sincos (void) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 CASE_FLT_FN (BUILT_IN_CABS): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 arg0 =3D gimple_call_arg (stmt, 0); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 loc =3D gimple_location (stmt); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 result =3D gimple_expand_builtin_cabs (= &gsi, loc, arg0); > + > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (result) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tree lhs =3D gimple_get_lhs (st= mt); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 gimple new_stmt =3D gimple_buil= d_assign (lhs, result); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 gimple_set_location (new_stmt, = loc); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unlink_stmt_vdef (stmt); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 gsi_replace (&gsi, new_stmt, tr= ue); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; > + > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0default:; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0 =A0 =A0} > > >