aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2006-11-11 04:05:14 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2006-11-11 04:05:14 +0000
commitb81e7144aa0c032c6246e0962467b4284cacd234 (patch)
treed6296e3b6e9ca4e372d936e1dd953fec297ffde3 /gcc/builtins.c
parent345768ef3f0ad0f2b09cbd79ec4daf6ba48f51b7 (diff)
downloadgcc-b81e7144aa0c032c6246e0962467b4284cacd234.zip
gcc-b81e7144aa0c032c6246e0962467b4284cacd234.tar.gz
gcc-b81e7144aa0c032c6246e0962467b4284cacd234.tar.bz2
builtins.c (fold_builtin_cos): Use fold_strip_sign_ops().
* builtins.c (fold_builtin_cos): Use fold_strip_sign_ops(). (fold_builtin_hypot): Likewise. * fold-const.c (fold_strip_sign_ops): Handle "odd" builtins. testsuite: * gcc.dg/builtins-20.c: Add more cases for stripping sign ops. From-SVN: r118683
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 9d27243..f1fa123 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7242,7 +7242,7 @@ static tree
fold_builtin_cos (tree arglist, tree type, tree fndecl)
{
tree arg = TREE_VALUE (arglist);
- tree res;
+ tree res, narg;
if (!validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
return NULL_TREE;
@@ -7252,12 +7252,9 @@ fold_builtin_cos (tree arglist, tree type, tree fndecl)
return res;
/* Optimize cos(-x) into cos (x). */
- if (TREE_CODE (arg) == NEGATE_EXPR)
- {
- tree args = build_tree_list (NULL_TREE,
- TREE_OPERAND (arg, 0));
- return build_function_call_expr (fndecl, args);
- }
+ if ((narg = fold_strip_sign_ops (arg)))
+ return build_function_call_expr (fndecl,
+ build_tree_list (NULL_TREE, narg));
return NULL_TREE;
}
@@ -7765,7 +7762,7 @@ fold_builtin_hypot (tree fndecl, tree arglist, tree type)
{
tree arg0 = TREE_VALUE (arglist);
tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
- tree res;
+ tree res, narg0, narg1;
if (!validate_arglist (arglist, REAL_TYPE, REAL_TYPE, VOID_TYPE))
return NULL_TREE;
@@ -7776,17 +7773,13 @@ fold_builtin_hypot (tree fndecl, tree arglist, tree type)
/* If either argument to hypot has a negate or abs, strip that off.
E.g. hypot(-x,fabs(y)) -> hypot(x,y). */
- if (TREE_CODE (arg0) == NEGATE_EXPR || TREE_CODE (arg1) == NEGATE_EXPR
- || TREE_CODE (arg0) == ABS_EXPR || TREE_CODE (arg1) == ABS_EXPR)
- {
- tree narg0 = (TREE_CODE (arg0) == NEGATE_EXPR
- || TREE_CODE (arg0) == ABS_EXPR)
- ? TREE_OPERAND (arg0, 0) : arg0;
- tree narg1 = (TREE_CODE (arg1) == NEGATE_EXPR
- || TREE_CODE (arg1) == ABS_EXPR)
- ? TREE_OPERAND (arg1, 0) : arg1;
- tree narglist = tree_cons (NULL_TREE, narg0,
- build_tree_list (NULL_TREE, narg1));
+ narg0 = fold_strip_sign_ops (arg0);
+ narg1 = fold_strip_sign_ops (arg1);
+ if (narg0 || narg1)
+ {
+ tree narglist = tree_cons (NULL_TREE, narg0 ? narg0 : arg0,
+ build_tree_list (NULL_TREE,
+ narg1 ? narg1 : arg1));
return build_function_call_expr (fndecl, narglist);
}