summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-11 09:09:24 +0000
committeruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-11 09:09:24 +0000
commit93ad369f347dc33419d853043156d50a8548d4bb (patch)
treef2a31a94dd3b7deafbd6738b40a6ea25123d51a0
parentb17d8487752a25bc37883f8d7f557d1f9deca826 (diff)
downloadgcc-93ad369f347dc33419d853043156d50a8548d4bb.tar.gz
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). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125614 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c18
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/builtins-11.c5
4 files changed, 33 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c16ab208d34..a026ca1d3c3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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>
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index bc6d6022415..5c7effe3e34 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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))
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 32d88ade40e..f7d76fa848e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/gcc.dg/builtins-11.c b/gcc/testsuite/gcc.dg/builtins-11.c
index a2ff257b9ee..ba4689201c4 100644
--- a/gcc/testsuite/gcc.dg/builtins-11.c
+++ b/gcc/testsuite/gcc.dg/builtins-11.c
@@ -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()