aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenth@gcc.gnu.org>2005-02-07 13:24:38 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2005-02-07 13:24:38 +0000
commit6a96f5c111327ebb22e3c6bff923f8c1b2e175f1 (patch)
treef3c9b917a0f61ec5e98c3b1be02adc081d56f541 /gcc/builtins.c
parent48c4e71107bd32507fe3a52c85601fce53a4b1ef (diff)
downloadgcc-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/builtins.c')
-rw-r--r--gcc/builtins.c9
1 files changed, 6 insertions, 3 deletions
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);