summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-math-opts.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2013-01-28 14:43:03 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2013-01-28 14:43:03 +0000
commit0190fe95747d19aff81809330c3dac92a8a0b7c7 (patch)
tree2a2bfc3d290925073d4af913ae01b69cfbf1aa53 /gcc/tree-ssa-math-opts.c
parentd67dd34f10e3f78ad6cbcde4361bc3593570aad0 (diff)
downloadgcc-0190fe95747d19aff81809330c3dac92a8a0b7c7.tar.gz
PR tree-optimization/56125
* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Don't optimize pow(x,c) into sqrt(x) * powi(x, n/2) or 1.0 / (sqrt(x) * powi(x, abs(n/2))) if c is an integer or when optimizing for size. Don't optimize pow(x,c) into powi(x, n/3) * powi(cbrt(x), n%3) or 1.0 / (powi(x, abs(n)/3) * powi(cbrt(x), abs(n)%3)) if 2c is an integer. * gcc.dg/pr56125.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@195507 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-math-opts.c')
-rw-r--r--gcc/tree-ssa-math-opts.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index fad3529a4d0..2140ced495b 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -1110,7 +1110,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
HOST_WIDE_INT n;
tree type, sqrtfn, cbrtfn, sqrt_arg0, sqrt_sqrt, result, cbrt_x, powi_cbrt_x;
enum machine_mode mode;
- bool hw_sqrt_exists;
+ bool hw_sqrt_exists, c_is_int, c2_is_int;
/* If the exponent isn't a constant, there's nothing of interest
to be done. */
@@ -1122,8 +1122,9 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
c = TREE_REAL_CST (arg1);
n = real_to_integer (&c);
real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0);
+ c_is_int = real_identical (&c, &cint);
- if (real_identical (&c, &cint)
+ if (c_is_int
&& ((n >= -1 && n <= 2)
|| (flag_unsafe_math_optimizations
&& optimize_insn_for_speed_p ()
@@ -1221,7 +1222,8 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
return build_and_insert_call (gsi, loc, cbrtfn, sqrt_arg0);
}
- /* Optimize pow(x,c), where n = 2c for some nonzero integer n, into
+ /* Optimize pow(x,c), where n = 2c for some nonzero integer n
+ and c not an integer, into
sqrt(x) * powi(x, n/2), n > 0;
1.0 / (sqrt(x) * powi(x, abs(n/2))), n < 0.
@@ -1230,10 +1232,13 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
real_arithmetic (&c2, MULT_EXPR, &c, &dconst2);
n = real_to_integer (&c2);
real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0);
+ c2_is_int = real_identical (&c2, &cint);
if (flag_unsafe_math_optimizations
&& sqrtfn
- && real_identical (&c2, &cint))
+ && c2_is_int
+ && !c_is_int
+ && optimize_function_for_speed_p (cfun))
{
tree powi_x_ndiv2 = NULL_TREE;
@@ -1286,6 +1291,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
&& cbrtfn
&& (gimple_val_nonnegative_real_p (arg0) || !HONOR_NANS (mode))
&& real_identical (&c2, &c)
+ && !c2_is_int
&& optimize_function_for_speed_p (cfun)
&& powi_cost (n / 3) <= POWI_MAX_MULTS)
{