]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/32279 (Fold 1.0/sqrt(x/y) to sqrt(y/x))
authorUros Bizjak <ubizjak@gmail.com>
Mon, 11 Jun 2007 09:09:24 +0000 (11:09 +0200)
committerUros Bizjak <uros@gcc.gnu.org>
Mon, 11 Jun 2007 09:09:24 +0000 (11:09 +0200)
PR middle-end/32279
* fold-const (fold_binary) [RDIV_EXPR]: Optimize a/sqrt(b/c)
into a*sqrt(c/b) if flag_unsafe_math_optimizations is set.

testsuite/ChangeLog:

PR middle-end/32279
* gcc.dg/builtins-11.c: Also check folding of a/sqrt(b/c).

From-SVN: r125614

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-11.c

index c16ab208d34c28820148d64a84684ee0f0b0ad62..a026ca1d3c3e9fadfdc3b742c3ced72cba7bfe62 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-11  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR middle-end/32279
+       * fold-const (fold_binary) [RDIV_EXPR]: Optimize a/sqrt(b/c)
+       into a*sqrt(c/b) if flag_unsafe_math_optimizations is set.
+
 2007-06-10  Jan Sjodin  <jan.sjodin@amd.com>
            Sebastian Pop  <sebpop@gmail.com>
 
index bc6d6022415e7783e52e281ae2d37548f57db8fe..5c7effe3e344faa8ef307e4a46f827120c7d6b5e 100644 (file)
@@ -10555,6 +10555,24 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
                }
            }
 
+         /* Optimize a/sqrt(b/c) into a*sqrt(c/b).  */
+         if (BUILTIN_SQRT_P (fcode1))
+           {
+             tree rootarg = CALL_EXPR_ARG (arg1, 0);
+
+             if (TREE_CODE (rootarg) == RDIV_EXPR)
+               {
+                 tree rootfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0);
+                 tree b = TREE_OPERAND (rootarg, 0);
+                 tree c = TREE_OPERAND (rootarg, 1);
+
+                 tree tmp = fold_build2 (RDIV_EXPR, type, c, b);
+
+                 tmp = build_call_expr (rootfn, 1, tmp);
+                 return fold_build2 (MULT_EXPR, type, arg0, tmp);
+               }
+           }
+
          /* Optimize x/expN(y) into x*expN(-y).  */
          if (BUILTIN_EXPONENT_P (fcode1))
            {
index 32d88ade40eca5b7e3699dbfdffebdf6925cb01f..f7d76fa848e22adb581d443e31bef943fa675261 100644 (file)
@@ -1,3 +1,8 @@
+2007-06-11  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR middle-end/32279
+       * gcc.dg/builtins-11.c: Also check folding of a/sqrt(b/c).
+
 2007-06-10  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/32235
index a2ff257b9ee46dd031c3381be74d071d5dd260b2..ba4689201c408458560e690d8e21fa43469cb452 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation.
+/* Copyright (C) 2003,2007 Free Software Foundation.
 
    Check that constant folding of built-in math functions doesn't
    break anything and produces the expected results.
@@ -36,6 +36,9 @@ void test(double x, double y, double z)
 
   if (x/pow(y,z) != x*pow(y,-z))
     link_error ();
+
+  if (x/sqrt(y/z) != x*sqrt(z/y))
+    link_error ();
 }
 
 int main()