diff options
author | Uros Bizjak <ubizjak@gmail.com> | 2007-06-11 11:09:24 +0200 |
---|---|---|
committer | Uros Bizjak <uros@gcc.gnu.org> | 2007-06-11 11:09:24 +0200 |
commit | f1da2df1e9642bc8660abcd83af2ad8980d42ce0 (patch) | |
tree | f2a31a94dd3b7deafbd6738b40a6ea25123d51a0 /gcc/fold-const.c | |
parent | 93e17a25c4dd862cb3f6439f1cb1df2374439c59 (diff) | |
download | gcc-f1da2df1e9642bc8660abcd83af2ad8980d42ce0.zip gcc-f1da2df1e9642bc8660abcd83af2ad8980d42ce0.tar.gz gcc-f1da2df1e9642bc8660abcd83af2ad8980d42ce0.tar.bz2 |
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
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index bc6d602..5c7effe 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)) { |