re PR middle-end/28252 (pow(x,1/3.0) should be converted to cbrt(x))
authorUros Bizjak <uros@kss-loka.si>
Sat, 21 Oct 2006 20:05:35 +0000 (22:05 +0200)
committerUros Bizjak <uros@gcc.gnu.org>
Sat, 21 Oct 2006 20:05:35 +0000 (22:05 +0200)
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

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-8.c

index 42b4dedc4f49d4b2aa152d43f263532243f46659..21550b3626fd2797fd5c799c5df961611a14bb68 100644 (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
index c1996dc44b182fa07efb2f05cefe0fcced88933d..ecee42b69be6ff06aa26aa54eeb6fbaabcc1be26 100644 (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);
index c30830dff1b4c71a7a8a4e9a645a59faf7b445b6..b55cd7c8f8bcc800528c6c434e727879affa4950 100644 (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
index c3066b41cabb14493b4443833dfac64d8184cd88..be17774d5265a85a6e05158166ffa7f23e1a7bce 100644 (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()