diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 42b4dedc4f4..21550b3626f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -4,6 +4,12 @@ (expand_builtin): Use it to expand lrint instead of expand_builtin_mathfn. +2006-10-21 Uros Bizjak + + 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 PR target/19398 diff --git a/gcc/builtins.c b/gcc/builtins.c index c1996dc44b1..ecee42b69be 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c30830dff1b..b55cd7c8f8b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-10-21 Uros Bizjak + + 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 PR tree-optimization/3511 diff --git a/gcc/testsuite/gcc.dg/builtins-8.c b/gcc/testsuite/gcc.dg/builtins-8.c index c3066b41cab..be17774d526 100644 --- a/gcc/testsuite/gcc.dg/builtins-8.c +++ b/gcc/testsuite/gcc.dg/builtins-8.c @@ -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()