PR 42694: add checks to make sure sqrt is supported
authorMichael Meissner <meissner@linux.vnet.ibm.com>
Wed, 8 Dec 2010 16:34:20 +0000 (16:34 +0000)
committerMichael Meissner <meissner@gcc.gnu.org>
Wed, 8 Dec 2010 16:34:20 +0000 (16:34 +0000)
From-SVN: r167594

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/powerpc/ppc-pow.c [new file with mode: 0644]

index 92b01db..6428570 100644 (file)
@@ -1,3 +1,11 @@
+2010-12-08  Michael Meissner  <meissner@linux.vnet.ibm.com>
+
+       PR middle-end/42694
+       * builtins.c (expand_builtin_pow_root): Don't optimize pow(x,y)
+       where y is 0.25, 1./6., or 0.75 if the target does not have a sqrt
+       instruction, but do optimize if y is 0.5 or 1./3. since that
+       changes an expensive call into a cheaper one.
+
 2010-12-08  Richard Guenther  <rguenther@suse.de>
 
        * tree-ssa-sccvn.c (copy_reference_ops_from_ref): Use a shift
index 2816a7e..eb2aa3e 100644 (file)
@@ -3068,7 +3068,8 @@ expand_builtin_pow_root (location_t loc, tree arg0, tree arg1, tree type,
          if (REAL_VALUES_EQUAL (c, dconsthalf))
            op = build_call_nofold_loc (loc, sqrtfn, 1, arg0);
 
-         else
+         /* Don't do this optimization if we don't have a sqrt insn.  */
+         else if (optab_handler (sqrt_optab, mode) != CODE_FOR_nothing)
            {
              REAL_VALUE_TYPE dconst1_4 = dconst1;
              REAL_VALUE_TYPE dconst3_4;
@@ -3114,7 +3115,8 @@ expand_builtin_pow_root (location_t loc, tree arg0, tree arg1, tree type,
            op = build_call_nofold_loc (loc, cbrtfn, 1, arg0);
 
              /* Now try 1/6.  */
-         else if (optimize_insn_for_speed_p ())
+         else if (optimize_insn_for_speed_p ()
+                  && optab_handler (sqrt_optab, mode) != CODE_FOR_nothing)
            {
              REAL_VALUE_TYPE dconst1_6 = dconst1_3;
              SET_REAL_EXP (&dconst1_6, REAL_EXP (&dconst1_6) - 1);
index 8743d36..7a7f3be 100644 (file)
@@ -1,3 +1,9 @@
+2010-12-08  Michael Meissner  <meissner@linux.vnet.ibm.com>
+
+       PR middle-end/42694
+       * gcc.target/powerpc/ppc-pow.c: New file to make sure pow (x,
+       0.75) is not optimized if the machine has no sqrt instruction.
+
 2010-12-07  Andrey Belevantsev  <abel@ispras.ru>
 
        PR target/43603
diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-pow.c b/gcc/testsuite/gcc.target/powerpc/ppc-pow.c
new file mode 100644 (file)
index 0000000..1255d5c
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile { target { { powerpc*-*-* } && { ! powerpc*-apple-darwin* } } } } */
+/* { dg-options "-O2 -ffast-math -mcpu=power6" } */
+/* { dg-final { scan-assembler-times "fsqrt" 3 } } */
+/* { dg-final { scan-assembler-times "fmul" 1 } } */
+/* { dg-final { scan-assembler-times "bl pow" 1 } } */
+/* { dg-final { scan-assembler-times "bl sqrt" 1 } } */
+
+double
+do_pow_0_75_default (double a)
+{
+  return __builtin_pow (a, 0.75);      /* should generate 2 fsqrts */
+}
+
+double
+do_pow_0_5_default (double a)
+{
+  return __builtin_pow (a, 0.5);       /* should generate fsqrt */
+}
+
+#pragma GCC target "no-powerpc-gpopt,no-powerpc-gfxopt"
+
+double
+do_pow_0_75_nosqrt (double a)
+{
+  return __builtin_pow (a, 0.75);      /* should call pow */
+}
+
+double
+do_pow_0_5_nosqrt (double a)
+{
+  return __builtin_pow (a, 0.5);       /* should call sqrt */
+}
+
+#pragma GCC reset_options