From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37483 invoked by alias); 26 Oct 2015 10:15:24 -0000 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 Received: (qmail 36452 invoked by uid 89); 26 Oct 2015 10:15:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f171.google.com Received: from mail-yk0-f171.google.com (HELO mail-yk0-f171.google.com) (209.85.160.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 26 Oct 2015 10:15:17 +0000 Received: by ykaz22 with SMTP id z22so179294818yka.2 for ; Mon, 26 Oct 2015 03:15:15 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.129.125.194 with SMTP id y185mr24639749ywc.5.1445854515903; Mon, 26 Oct 2015 03:15:15 -0700 (PDT) Received: by 10.37.117.136 with HTTP; Mon, 26 Oct 2015 03:15:15 -0700 (PDT) In-Reply-To: <87k2qavu3u.fsf@e105548-lin.cambridge.arm.com> References: <87k2qavu3u.fsf@e105548-lin.cambridge.arm.com> Date: Mon, 26 Oct 2015 10:15:00 -0000 Message-ID: Subject: Re: Move powi folds to match.pd From: Richard Biener To: GCC Patches , richard.sandiford@arm.com Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg02676.txt.bz2 On Mon, Oct 26, 2015 at 10:48 AM, Richard Sandiford wrote: > Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. > OK to install? Ok. Thanks, Richard. > Thanks, > Richard > > > gcc/ > * builtins.c (fold_builtin_powi): Delete. > (fold_builtin_2): Handle constant powi arguments here. > * match.pd: Add rules previously handled by fold_builtin_powi. > > gcc/testsuite/ > * gcc.dg/builtins-52.c: Add -O to dg-options. > > diff --git a/gcc/builtins.c b/gcc/builtins.c > index 88c0576..3d39d43 100644 > --- a/gcc/builtins.c > +++ b/gcc/builtins.c > @@ -156,7 +156,6 @@ static tree rewrite_call_expr (location_t, tree, int, tree, int, ...); > static bool validate_arg (const_tree, enum tree_code code); > static rtx expand_builtin_fabs (tree, rtx, rtx); > static rtx expand_builtin_signbit (tree, rtx); > -static tree fold_builtin_powi (location_t, tree, tree, tree, tree); > static tree fold_builtin_bitop (tree, tree); > static tree fold_builtin_strchr (location_t, tree, tree, tree); > static tree fold_builtin_memchr (location_t, tree, tree, tree, tree); > @@ -7517,52 +7516,6 @@ fold_const_builtin_pow (tree arg0, tree arg1, tree type) > return NULL_TREE; > } > > -/* Fold a builtin function call to powi, powif, or powil with argument ARG. > - Return NULL_TREE if no simplification can be made. */ > -static tree > -fold_builtin_powi (location_t loc, tree fndecl ATTRIBUTE_UNUSED, > - tree arg0, tree arg1, tree type) > -{ > - if (!validate_arg (arg0, REAL_TYPE) > - || !validate_arg (arg1, INTEGER_TYPE)) > - return NULL_TREE; > - > - /* Optimize pow(1.0,y) = 1.0. */ > - if (real_onep (arg0)) > - return omit_one_operand_loc (loc, type, build_real (type, dconst1), arg1); > - > - if (tree_fits_shwi_p (arg1)) > - { > - HOST_WIDE_INT c = tree_to_shwi (arg1); > - > - /* Evaluate powi at compile-time. */ > - if (TREE_CODE (arg0) == REAL_CST > - && !TREE_OVERFLOW (arg0)) > - { > - REAL_VALUE_TYPE x; > - x = TREE_REAL_CST (arg0); > - real_powi (&x, TYPE_MODE (type), &x, c); > - return build_real (type, x); > - } > - > - /* Optimize pow(x,0) = 1.0. */ > - if (c == 0) > - return omit_one_operand_loc (loc, type, build_real (type, dconst1), > - arg0); > - > - /* Optimize pow(x,1) = x. */ > - if (c == 1) > - return arg0; > - > - /* Optimize pow(x,-1) = 1.0/x. */ > - if (c == -1) > - return fold_build2_loc (loc, RDIV_EXPR, type, > - build_real (type, dconst1), arg0); > - } > - > - return NULL_TREE; > -} > - > /* A subroutine of fold_builtin to fold the various exponent > functions. Return NULL_TREE if no simplification can be made. > FUNC is the corresponding MPFR exponent function. */ > @@ -9379,7 +9332,16 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, tree arg1) > return fold_const_builtin_pow (arg0, arg1, type); > > CASE_FLT_FN (BUILT_IN_POWI): > - return fold_builtin_powi (loc, fndecl, arg0, arg1, type); > + if (TREE_CODE (arg0) == REAL_CST > + && !TREE_OVERFLOW (arg0) > + && tree_fits_shwi_p (arg1)) > + { > + HOST_WIDE_INT c = tree_to_shwi (arg1); > + REAL_VALUE_TYPE x; > + real_powi (&x, TYPE_MODE (type), TREE_REAL_CST_PTR (arg0), c); > + return build_real (type, x); > + } > + break; > > CASE_FLT_FN (BUILT_IN_COPYSIGN): > return fold_builtin_copysign (loc, arg0, arg1, type); > diff --git a/gcc/match.pd b/gcc/match.pd > index b681573..a8adffb 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -84,6 +84,7 @@ DEFINE_MATH_FN (LOG10) > DEFINE_MATH_FN (EXP10) > DEFINE_MATH_FN (POW) > DEFINE_MATH_FN (POW10) > +DEFINE_MATH_FN (POWI) > DEFINE_MATH_FN (SQRT) > DEFINE_MATH_FN (CBRT) > DEFINE_MATH_FN (SIN) > @@ -2821,6 +2822,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > real_equal (value, &tmp))) > (cbrts @0)))))) > > +/* powi(1,x) -> 1. */ > +(simplify > + (POWI real_onep@0 @1) > + @0) > + > +(simplify > + (POWI @0 INTEGER_CST@1) > + (switch > + /* powi(x,0) -> 1. */ > + (if (wi::eq_p (@1, 0)) > + { build_real (type, dconst1); }) > + /* powi(x,1) -> x. */ > + (if (wi::eq_p (@1, 1)) > + @0) > + /* powi(x,-1) -> 1/x. */ > + (if (wi::eq_p (@1, -1)) > + (rdiv { build_real (type, dconst1); } @0)))) > + > /* Narrowing of arithmetic and logical operations. > > These are conceptually similar to the transformations performed for > diff --git a/gcc/testsuite/gcc.dg/builtins-52.c b/gcc/testsuite/gcc.dg/builtins-52.c > index 684fd66..1cff017 100644 > --- a/gcc/testsuite/gcc.dg/builtins-52.c > +++ b/gcc/testsuite/gcc.dg/builtins-52.c > @@ -1,5 +1,5 @@ > /* { dg-do link } */ > -/* { dg-options "-ffast-math" } */ > +/* { dg-options "-O -ffast-math" } */ > > extern void link_error(void); > >