From: Uros Bizjak Date: Mon, 11 Jun 2007 09:09:24 +0000 (+0200) Subject: re PR middle-end/32279 (Fold 1.0/sqrt(x/y) to sqrt(y/x)) X-Git-Tag: releases/gcc-4.3.0~4525 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f1da2df1e9642bc8660abcd83af2ad8980d42ce0;p=thirdparty%2Fgcc.git re PR middle-end/32279 (Fold 1.0/sqrt(x/y) to sqrt(y/x)) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c16ab208d34c..a026ca1d3c3e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2007-06-11 Uros Bizjak + + 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 Sebastian Pop diff --git a/gcc/fold-const.c b/gcc/fold-const.c index bc6d6022415e..5c7effe3e344 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 32d88ade40ec..f7d76fa848e2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-06-11 Uros Bizjak + + PR middle-end/32279 + * gcc.dg/builtins-11.c: Also check folding of a/sqrt(b/c). + 2007-06-10 Jerry DeLisle PR libgfortran/32235 diff --git a/gcc/testsuite/gcc.dg/builtins-11.c b/gcc/testsuite/gcc.dg/builtins-11.c index a2ff257b9ee4..ba4689201c40 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()