summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/builtins.c53
-rw-r--r--gcc/match.pd8
3 files changed, 21 insertions, 46 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5e048d99660..219f2580a85 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
2015-10-27 Richard Sandiford <richard.sandiford@arm.com>
+ * builtins.c (fold_builtin_exponent): Delete.
+ (fold_builtin_2): Handle constant expN arguments here.
+ * match.pd: Fold expN(logN(x)) -> x.
+
+2015-10-27 Richard Sandiford <richard.sandiford@arm.com>
+
* builtins.c (fold_builtin_powi): Delete.
(fold_builtin_2): Handle constant powi arguments here.
* match.pd: Add rules previously handled by fold_builtin_powi.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3d39d43594b..e5a00eef18d 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 1c3331972d6..26491d27840 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2407,12 +2407,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