]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/gcc-tumbl.git/commitdiff
Backported from mainline
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Feb 2013 14:17:50 +0000 (14:17 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Feb 2013 14:17:50 +0000 (14:17 +0000)
2013-01-28  Jakub Jelinek  <jakub@redhat.com>

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/branches/gcc-4_7-branch@195664 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr56125.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index a45df1fb42c5edaf30cf328513472c8da72a6e21..9b194d2befc44a1b903c4ee9d6266f94851fe326 100644 (file)
@@ -1,6 +1,17 @@
 2013-02-01  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-01-28  Jakub Jelinek  <jakub@redhat.com>
+
+       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.
+
        2013-01-25  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/56098
index 67261698890209a653b461510a782a6ee96f3316..bcd1464d35870f0c96f9c9e13d57acccdf4419a2 100644 (file)
@@ -1,6 +1,11 @@
 2013-02-01  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2013-01-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/56125
+       * gcc.dg/pr56125.c: New test.
+
        2013-01-25  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/56098
diff --git a/gcc/testsuite/gcc.dg/pr56125.c b/gcc/testsuite/gcc.dg/pr56125.c
new file mode 100644 (file)
index 0000000..d1840a9
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR tree-optimization/56125 */
+/* { dg-do run } */
+/* { dg-options "-O2 -ffast-math" } */
+
+extern void abort (void);
+extern double fabs (double);
+
+__attribute__((cold)) double
+foo (double x, double n)
+{
+  double u = x / (n * n);
+  return u;
+}
+
+int
+main ()
+{
+  if (fabs (foo (29, 2) - 7.25) > 0.001)
+    abort ();
+  return 0;
+}
index bb60a62fe046a430867ccce925e1420ef92946f6..e79db06139f4bf0474be5ab702b2187d1f8e0f96 100644 (file)
@@ -1113,7 +1113,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
   tree type, sqrtfn, cbrtfn, sqrt_arg0, sqrt_sqrt, result, cbrt_x, powi_cbrt_x;
   tree target = NULL_TREE;
   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.  */
@@ -1125,8 +1125,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 ()
@@ -1224,7 +1225,8 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
       return build_and_insert_call (gsi, loc, &target, 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.
@@ -1233,10 +1235,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;
 
@@ -1289,6 +1294,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)
     {