* Move expN folds to match.pd
@ 2015-10-26 9:52 Richard Sandiford
2015-10-26 10:15 ` Richard Biener
2015-10-26 10:40 ` Marc Glisse
0 siblings, 2 replies; 4+ messages in thread
From: Richard Sandiford @ 2015-10-26 9:52 UTC (permalink / raw)
To: gcc-patches
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?
Thanks,
Richard
gcc/
* builtins.c (fold_builtin_exponent): Delete.
(fold_builtin_2): Handle constant expN arguments here.
* match.pd: Fold expN(logN(x)) -> x.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3d39d43..e5a00ee 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7516,47 +7516,6 @@ fold_const_builtin_pow (tree arg0, tree arg1, tree type)
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. */
-
-static tree
-fold_builtin_exponent (location_t loc, tree fndecl, tree arg,
- int (*func)(mpfr_ptr, mpfr_srcptr, mp_rnd_t))
-{
- if (validate_arg (arg, REAL_TYPE))
- {
- tree type = TREE_TYPE (TREE_TYPE (fndecl));
- tree res;
-
- /* Calculate the result when the argument is a constant. */
- if ((res = do_mpfr_arg1 (arg, type, func, NULL, NULL, 0)))
- return res;
-
- /* Optimize expN(logN(x)) = x. */
- if (flag_unsafe_math_optimizations)
- {
- const enum built_in_function fcode = builtin_mathfn_code (arg);
-
- if ((func == mpfr_exp
- && (fcode == BUILT_IN_LOG
- || fcode == BUILT_IN_LOGF
- || fcode == BUILT_IN_LOGL))
- || (func == mpfr_exp2
- && (fcode == BUILT_IN_LOG2
- || fcode == BUILT_IN_LOG2F
- || fcode == BUILT_IN_LOG2L))
- || (func == mpfr_exp10
- && (fcode == BUILT_IN_LOG10
- || fcode == BUILT_IN_LOG10F
- || fcode == BUILT_IN_LOG10L)))
- return fold_convert_loc (loc, type, CALL_EXPR_ARG (arg, 0));
- }
- }
-
- return NULL_TREE;
-}
-
/* Fold function call to builtin memchr. ARG1, ARG2 and LEN are the
arguments to the call, and TYPE is its return type.
Return NULL_TREE if no simplification can be made. */
@@ -9004,14 +8963,20 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
break;
CASE_FLT_FN (BUILT_IN_EXP):
- return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp);
+ if (validate_arg (arg0, REAL_TYPE))
+ return do_mpfr_arg1 (arg0, type, mpfr_exp, NULL, NULL, 0);
+ break;
CASE_FLT_FN (BUILT_IN_EXP2):
- return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp2);
+ if (validate_arg (arg0, REAL_TYPE))
+ return do_mpfr_arg1 (arg0, type, mpfr_exp2, NULL, NULL, 0);
+ break;
CASE_FLT_FN (BUILT_IN_EXP10):
CASE_FLT_FN (BUILT_IN_POW10):
- return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp10);
+ if (validate_arg (arg0, REAL_TYPE))
+ return do_mpfr_arg1 (arg0, type, mpfr_exp10, NULL, NULL, 0);
+ break;
CASE_FLT_FN (BUILT_IN_EXPM1):
if (validate_arg (arg0, REAL_TYPE))
diff --git a/gcc/match.pd b/gcc/match.pd
index a8adffb..303889b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2408,12 +2408,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(rdiv @0 (exps:s @1))
(mult @0 (exps (negate @1)))))
- /* Special case, optimize logN(expN(x)) = x. */
(for logs (LOG LOG2 LOG10 LOG10)
exps (EXP EXP2 EXP10 POW10)
+ /* logN(expN(x)) -> x. */
(simplify
(logs (exps @0))
- @0))
+ @0)
+ /* expN(logN(x)) -> x. */
+ (simplify
+ (exps (logs @0))
+ @0))
/* Optimize logN(func()) for various exponential functions. We
want to determine the value "x" and the power "exponent" in
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Move expN folds to match.pd
2015-10-26 9:52 Move expN folds to match.pd Richard Sandiford
@ 2015-10-26 10:15 ` Richard Biener
2015-10-26 10:40 ` Marc Glisse
1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2015-10-26 10:15 UTC (permalink / raw)
To: GCC Patches, richard.sandiford
On Mon, Oct 26, 2015 at 10:50 AM, Richard Sandiford
<rdsandiford@googlemail.com> 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_exponent): Delete.
> (fold_builtin_2): Handle constant expN arguments here.
> * match.pd: Fold expN(logN(x)) -> x.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 3d39d43..e5a00ee 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7516,47 +7516,6 @@ fold_const_builtin_pow (tree arg0, tree arg1, tree type)
> 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. */
> -
> -static tree
> -fold_builtin_exponent (location_t loc, tree fndecl, tree arg,
> - int (*func)(mpfr_ptr, mpfr_srcptr, mp_rnd_t))
> -{
> - if (validate_arg (arg, REAL_TYPE))
> - {
> - tree type = TREE_TYPE (TREE_TYPE (fndecl));
> - tree res;
> -
> - /* Calculate the result when the argument is a constant. */
> - if ((res = do_mpfr_arg1 (arg, type, func, NULL, NULL, 0)))
> - return res;
> -
> - /* Optimize expN(logN(x)) = x. */
> - if (flag_unsafe_math_optimizations)
> - {
> - const enum built_in_function fcode = builtin_mathfn_code (arg);
> -
> - if ((func == mpfr_exp
> - && (fcode == BUILT_IN_LOG
> - || fcode == BUILT_IN_LOGF
> - || fcode == BUILT_IN_LOGL))
> - || (func == mpfr_exp2
> - && (fcode == BUILT_IN_LOG2
> - || fcode == BUILT_IN_LOG2F
> - || fcode == BUILT_IN_LOG2L))
> - || (func == mpfr_exp10
> - && (fcode == BUILT_IN_LOG10
> - || fcode == BUILT_IN_LOG10F
> - || fcode == BUILT_IN_LOG10L)))
> - return fold_convert_loc (loc, type, CALL_EXPR_ARG (arg, 0));
> - }
> - }
> -
> - return NULL_TREE;
> -}
> -
> /* Fold function call to builtin memchr. ARG1, ARG2 and LEN are the
> arguments to the call, and TYPE is its return type.
> Return NULL_TREE if no simplification can be made. */
> @@ -9004,14 +8963,20 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
> break;
>
> CASE_FLT_FN (BUILT_IN_EXP):
> - return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp);
> + if (validate_arg (arg0, REAL_TYPE))
> + return do_mpfr_arg1 (arg0, type, mpfr_exp, NULL, NULL, 0);
> + break;
>
> CASE_FLT_FN (BUILT_IN_EXP2):
> - return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp2);
> + if (validate_arg (arg0, REAL_TYPE))
> + return do_mpfr_arg1 (arg0, type, mpfr_exp2, NULL, NULL, 0);
> + break;
>
> CASE_FLT_FN (BUILT_IN_EXP10):
> CASE_FLT_FN (BUILT_IN_POW10):
> - return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp10);
> + if (validate_arg (arg0, REAL_TYPE))
> + return do_mpfr_arg1 (arg0, type, mpfr_exp10, NULL, NULL, 0);
> + break;
>
> CASE_FLT_FN (BUILT_IN_EXPM1):
> if (validate_arg (arg0, REAL_TYPE))
> diff --git a/gcc/match.pd b/gcc/match.pd
> index a8adffb..303889b 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2408,12 +2408,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (rdiv @0 (exps:s @1))
> (mult @0 (exps (negate @1)))))
>
> - /* Special case, optimize logN(expN(x)) = x. */
> (for logs (LOG LOG2 LOG10 LOG10)
> exps (EXP EXP2 EXP10 POW10)
> + /* logN(expN(x)) -> x. */
> (simplify
> (logs (exps @0))
> - @0))
> + @0)
> + /* expN(logN(x)) -> x. */
> + (simplify
> + (exps (logs @0))
> + @0))
>
> /* Optimize logN(func()) for various exponential functions. We
> want to determine the value "x" and the power "exponent" in
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Move expN folds to match.pd
2015-10-26 9:52 Move expN folds to match.pd Richard Sandiford
2015-10-26 10:15 ` Richard Biener
@ 2015-10-26 10:40 ` Marc Glisse
2015-10-26 11:26 ` Richard Biener
1 sibling, 1 reply; 4+ messages in thread
From: Marc Glisse @ 2015-10-26 10:40 UTC (permalink / raw)
To: Richard Sandiford; +Cc: gcc-patches
On Mon, 26 Oct 2015, Richard Sandiford wrote:
> + /* expN(logN(x)) -> x. */
> + (simplify
> + (exps (logs @0))
> + @0))
We are not very consistent about it, but wasn't there an idea that we
should use non_lvalue in most such places?
--
Marc Glisse
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Move expN folds to match.pd
2015-10-26 10:40 ` Marc Glisse
@ 2015-10-26 11:26 ` Richard Biener
0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2015-10-26 11:26 UTC (permalink / raw)
To: GCC Patches; +Cc: Richard Sandiford
On Mon, Oct 26, 2015 at 11:32 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Mon, 26 Oct 2015, Richard Sandiford wrote:
>
>> + /* expN(logN(x)) -> x. */
>> + (simplify
>> + (exps (logs @0))
>> + @0))
>
>
> We are not very consistent about it, but wasn't there an idea that we should
> use non_lvalue in most such places?
Hmm, probably. IIRC the builtins.c code always wraps a NOP_EXPR around
constants.
OTOH I hope that the delayed folding branch will get merged for C++ and thus
we can get rid of _all_ NON_VALUE_EXPRs produced by folding. At least the
C FE no longer requires them.
Richard.
> --
> Marc Glisse
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-26 11:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-26 9:52 Move expN folds to match.pd Richard Sandiford
2015-10-26 10:15 ` Richard Biener
2015-10-26 10:40 ` Marc Glisse
2015-10-26 11:26 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).