diff options
author | Richard Guenther <rguenth@gcc.gnu.org> | 2005-02-07 13:24:38 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2005-02-07 13:24:38 +0000 |
commit | 6a96f5c111327ebb22e3c6bff923f8c1b2e175f1 (patch) | |
tree | f3c9b917a0f61ec5e98c3b1be02adc081d56f541 /gcc | |
parent | 48c4e71107bd32507fe3a52c85601fce53a4b1ef (diff) | |
download | gcc-6a96f5c111327ebb22e3c6bff923f8c1b2e175f1.zip gcc-6a96f5c111327ebb22e3c6bff923f8c1b2e175f1.tar.gz gcc-6a96f5c111327ebb22e3c6bff923f8c1b2e175f1.tar.bz2 |
re PR middle-end/19775 (sqrt(pow(x,y)) != pow(x,y*0.5) (with -ffast-math))
2005-02-07 Richard Guenther <rguenth@gcc.gnu.org>
PR middle-end/19775
* builtins.c (fold_builtin_sqrt): Transform
sqrt(pow(x,y)) to pow(fabs(x),y*0.5), not
pow(x,y*0.5).
* gcc.dg/torture/builtin-power-1.c: Disable test for
invalid transformation.
* gcc.dg/builtins-10.c: Likewise. Disable one test we
no longer optimize.
* gcc.dg/builtins-47.c: New testcase.
From-SVN: r94701
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/builtins.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/builtins-10.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/builtins-47.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/builtin-power-1.c | 2 |
6 files changed, 47 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1418ba1..dec5375 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2005-02-07 Richard Guenther <rguenth@gcc.gnu.org> + + PR middle-end/19775 + * builtins.c (fold_builtin_sqrt): Transform + sqrt(pow(x,y)) to pow(fabs(x),y*0.5), not + pow(x,y*0.5). + 2005-02-07 Leehod Baruch <leehod@il.ibm.com> Dorit Naishlos <dorit@il.ibm.com> diff --git a/gcc/builtins.c b/gcc/builtins.c index dada41e..09c5b6b 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -6186,7 +6186,7 @@ fold_builtin_sqrt (tree arglist, tree type) } } - /* Optimize sqrt(pow(x,y)) = pow(x,y*0.5). */ + /* Optimize sqrt(pow(x,y)) = pow(|x|,y*0.5). */ if (flag_unsafe_math_optimizations && (fcode == BUILT_IN_POW || fcode == BUILT_IN_POWF @@ -6195,8 +6195,11 @@ fold_builtin_sqrt (tree arglist, tree type) tree powfn = TREE_OPERAND (TREE_OPERAND (arg, 0), 0); tree arg0 = TREE_VALUE (TREE_OPERAND (arg, 1)); tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_OPERAND (arg, 1))); - tree narg1 = fold (build2 (MULT_EXPR, type, arg1, - build_real (type, dconsthalf))); + tree narg1; + if (!tree_expr_nonnegative_p (arg0)) + arg0 = build1 (ABS_EXPR, type, arg0); + narg1 = fold (build2 (MULT_EXPR, type, arg1, + build_real (type, dconsthalf))); arglist = tree_cons (NULL_TREE, arg0, build_tree_list (NULL_TREE, narg1)); return build_function_call_expr (powfn, arglist); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f4fac6f..4e93d07 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2005-02-07 Richard Guenther <rguenth@gcc.gnu.org> + + PR middle-end/19775 + * gcc.dg/torture/builtin-power-1.c: Disable test for + invalid transformation. + * gcc.dg/builtins-10.c: Likewise. Disable one test we + no longer optimize. + * gcc.dg/builtins-47.c: New testcase. + 2005-02-07 Leehod Baruch <leehod@il.ibm.com> Dorit Naishlos <dorit@il.ibm.com> diff --git a/gcc/testsuite/gcc.dg/builtins-10.c b/gcc/testsuite/gcc.dg/builtins-10.c index 9e5a458..53158a0 100644 --- a/gcc/testsuite/gcc.dg/builtins-10.c +++ b/gcc/testsuite/gcc.dg/builtins-10.c @@ -14,11 +14,12 @@ extern double exp(double); extern double log(double); extern double sqrt(double); extern double pow(double,double); +extern double fabs(double); void test(double x) { - if (sqrt(pow(x,4.0)) != x*x) - link_error (); + /*if (sqrt(pow(x,4.0)) != x*x) + link_error (); */ if (pow(sqrt(x),4.0) != x*x) link_error (); @@ -29,7 +30,7 @@ void test(double x) void test2(double x, double y, double z) { - if (sqrt(pow(x,y)) != pow(x,y*0.5)) + if (sqrt(pow(x,y)) != pow(fabs(x),y*0.5)) link_error (); if (log(pow(x,y)) != y*log(x)) diff --git a/gcc/testsuite/gcc.dg/builtins-47.c b/gcc/testsuite/gcc.dg/builtins-47.c new file mode 100644 index 0000000..19ae973 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtins-47.c @@ -0,0 +1,20 @@ +/* { dg-do run } */ +/* { dg-options "-ffast-math -fdump-tree-gimple" } */ + +extern double sqrt (double); +extern double pow (double, double); +extern void abort (void); + +int main () +{ + double x = -1.0; + if (sqrt (pow (x, 2)) != 1.0) + abort(); + if (sqrt (x*x) != 1.0) + abort(); + return 0; +} + +/* { dg-final { scan-tree-dump-times "sqrt" 0 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "pow" 0 "gimple" } } */ + diff --git a/gcc/testsuite/gcc.dg/torture/builtin-power-1.c b/gcc/testsuite/gcc.dg/torture/builtin-power-1.c index 4556611..7cdc00c 100644 --- a/gcc/testsuite/gcc.dg/torture/builtin-power-1.c +++ b/gcc/testsuite/gcc.dg/torture/builtin-power-1.c @@ -63,7 +63,7 @@ void test(double d1, double d2, double d3, || FN##l(powl(ld1,ld2)) != powl(ld1,ld2/N)) \ link_failure_##FN##_pow() - ROOT_POW(sqrt,2); + /*ROOT_POW(sqrt,2); Invalid. */ /*ROOT_POW(cbrt,3); Intentionally not implemented. */ /* Test pow(pow(x,y),z) -> pow(x,y*z). */ |