diff options
author | Roger Sayle <roger@eyesopen.com> | 2003-08-01 00:36:53 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2003-08-01 00:36:53 +0000 |
commit | 2598550fa6d3583ce066a9aaf5abfa4acd186077 (patch) | |
tree | a842e3f3e11953156cef321cf6510aeed77635b1 /gcc/builtins.c | |
parent | e3da5a9a50524344c9b80ee1b8f2a8639493dd46 (diff) | |
download | gcc-2598550fa6d3583ce066a9aaf5abfa4acd186077.zip gcc-2598550fa6d3583ce066a9aaf5abfa4acd186077.tar.gz gcc-2598550fa6d3583ce066a9aaf5abfa4acd186077.tar.bz2 |
fold-const.c (fold <MULT_EXPR>): Optimize both x*pow(x,c) and pow(x,c)*x as pow(x,c+1) for constant values c.
* fold-const.c (fold <MULT_EXPR>): Optimize both x*pow(x,c) and
pow(x,c)*x as pow(x,c+1) for constant values c. Optimize x*x
as pow(x,2.0) when the latter will be expanded back into x*x.
(fold <RDIV_EXPR>): Optimize pow(x,c)/x as pow(x,c-1).
* builtins.c (expand_builtin_pow): Ignore flag_errno_math as
pow can never set errno when used with an integer exponent.
Always use expand_powi when exponent is -1, 0, 1 or 2.
(fold_builtin): Don't rewrite pow(x,2.0) as x*x nor pow(x,-2.0)
as 1.0/(x*x). This avoids unbounded recursion as we now prefer
the pow forms of these expressions.
* gcc.dg/builtins-27.c: New test case.
From-SVN: r70030
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index a8c1d47..535b84c 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -2170,10 +2170,7 @@ expand_builtin_pow (tree exp, rtx target, rtx subtarget) arg0 = TREE_VALUE (arglist); arg1 = TREE_VALUE (TREE_CHAIN (arglist)); - if (flag_unsafe_math_optimizations - && ! flag_errno_math - && ! optimize_size - && TREE_CODE (arg1) == REAL_CST + if (TREE_CODE (arg1) == REAL_CST && ! TREE_CONSTANT_OVERFLOW (arg1)) { REAL_VALUE_TYPE cint; @@ -2183,13 +2180,21 @@ expand_builtin_pow (tree exp, rtx target, rtx subtarget) c = TREE_REAL_CST (arg1); n = real_to_integer (&c); real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0); - if (real_identical (&c, &cint) - && powi_cost (n) <= POWI_MAX_MULTS) + if (real_identical (&c, &cint)) { - enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); - rtx op = expand_expr (arg0, subtarget, VOIDmode, 0); - op = force_reg (mode, op); - return expand_powi (op, mode, n); + /* If the exponent is -1, 0, 1 or 2, then expand_powi is exact. + Otherwise, check the number of multiplications required. + Note that pow never sets errno for an integer exponent. */ + if ((n >= -1 && n <= 2) + || (flag_unsafe_math_optimizations + && ! optimize_size + && powi_cost (n) <= POWI_MAX_MULTS)) + { + enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); + rtx op = expand_expr (arg0, subtarget, VOIDmode, 0); + op = force_reg (mode, op); + return expand_powi (op, mode, n); + } } } return expand_builtin_mathfn_2 (exp, target, NULL_RTX); @@ -6245,28 +6250,6 @@ fold_builtin (tree exp) build_real (type, dconst1), arg0)); - /* Optimize pow(x,2.0) = x*x. */ - if (REAL_VALUES_EQUAL (c, dconst2) - && (*lang_hooks.decls.global_bindings_p) () == 0 - && ! CONTAINS_PLACEHOLDER_P (arg0)) - { - arg0 = save_expr (arg0); - return fold (build (MULT_EXPR, type, arg0, arg0)); - } - - /* Optimize pow(x,-2.0) = 1.0/(x*x). */ - if (flag_unsafe_math_optimizations - && REAL_VALUES_EQUAL (c, dconstm2) - && (*lang_hooks.decls.global_bindings_p) () == 0 - && ! CONTAINS_PLACEHOLDER_P (arg0)) - { - arg0 = save_expr (arg0); - return fold (build (RDIV_EXPR, type, - build_real (type, dconst1), - fold (build (MULT_EXPR, type, - arg0, arg0)))); - } - /* Optimize pow(x,0.5) = sqrt(x). */ if (flag_unsafe_math_optimizations && REAL_VALUES_EQUAL (c, dconsthalf)) |