re PR middle-end/28252 (pow(x,1/3.0) should be converted to cbrt(x))

2006-10-21  Uros Bizjak  <uros@kss-loka.si>

        PR middle-end/28252
        * builtins.c (fold_builtin): Fold pow(x,1.0/3.0) as cbrt(x) if
        flag_unsafe_math_optimizations is set.

testsuite/ChangeLog:

        PR middle-end/28252
        * gcc.dg/builtins-8.c: Also check pow(x,1.0/3.0) to cbrt(x)
        transformation.

From-SVN: r117937
This commit is contained in:
Uros Bizjak 2006-10-21 22:05:35 +02:00 committed by Uros Bizjak
parent 0bfa1541fa
commit 495ed96c2a
4 changed files with 34 additions and 1 deletions

View File

@ -4,6 +4,12 @@
(expand_builtin): Use it to expand lrint instead of
expand_builtin_mathfn.
2006-10-21 Uros Bizjak <uros@kss-loka.si>
PR middle-end/28252
* builtins.c (fold_builtin): Fold pow(x,1.0/3.0) as cbrt(x) if
flag_unsafe_math_optimizations is set.
2006-10-21 Uros Bizjak <uros@kss-loka.si>
PR target/19398

View File

@ -7775,6 +7775,23 @@ fold_builtin_pow (tree fndecl, tree arglist, tree type)
}
}
/* Optimize pow(x,1.0/3.0) = cbrt(x). */
if (flag_unsafe_math_optimizations)
{
const REAL_VALUE_TYPE dconstroot
= real_value_truncate (TYPE_MODE (type), dconstthird);
if (REAL_VALUES_EQUAL (c, dconstroot))
{
tree cbrtfn = mathfn_built_in (type, BUILT_IN_CBRT);
if (cbrtfn != NULL_TREE)
{
tree arglist = build_tree_list (NULL_TREE, arg0);
return build_function_call_expr (cbrtfn, arglist);
}
}
}
/* Check for an integer exponent. */
n = real_to_integer (&c);
real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0);

View File

@ -1,3 +1,9 @@
2006-10-21 Uros Bizjak <uros@kss-loka.si>
PR middle-end/28252
* gcc.dg/builtins-8.c: Also check pow(x,1.0/3.0) to cbrt(x)
transformation.
2006-10-21 Richard Guenther <rguenther@suse.de>
PR tree-optimization/3511

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 Free Software Foundation.
/* Copyright (C) 2003, 2006 Free Software Foundation.
Verify that built-in math function constant folding of functions
with one constant argument is correctly performed by the compiler.
@ -11,6 +11,7 @@
extern void abort(void);
extern double pow(double, double);
extern double sqrt(double);
extern double cbrt(double);
void test(double x)
{
@ -25,6 +26,9 @@ void test(double x)
if (pow(x,0.5) != sqrt(x))
abort ();
if (pow(x,1.0/3.0) != cbrt(x))
abort ();
}
int main()