summaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2005-02-07 13:24:38 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2005-02-07 13:24:38 +0000
commitbc33117f4102846bb8db37e5c37845ba65e3028c (patch)
treef3c9b917a0f61ec5e98c3b1be02adc081d56f541 /gcc/builtins.c
parent4d8203bc06c1d16f9ed6e23982085519e216fd25 (diff)
downloadgcc-bc33117f4102846bb8db37e5c37845ba65e3028c.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94701 138bc75d-0d04-0410-961f-82ee72b054a4
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 dada41ef848..09c5b6b795e 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);