diff options
author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-25 03:57:30 +0000 |
---|---|---|
committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-25 03:57:30 +0000 |
commit | abe4dcf61d4cae33c1defdcf2faac5385eabac20 (patch) | |
tree | e71f14cf38a4ea58b59e83a908432bc1c7fe652e /gcc/builtins.c | |
parent | 519024deacd16e3d7a009c174d80e11b88e0e0f6 (diff) | |
download | gcc-abe4dcf61d4cae33c1defdcf2faac5385eabac20.tar.gz |
* builtins.c (fold_builtin_carg): New.
(fold_builtin_1): Use it.
testsuite:
* gcc.dg/builtins-20.c: Test builtin carg.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121159 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 240231e538b..19e7d345e53 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -9058,6 +9058,29 @@ fold_builtin_fmin_fmax (tree arglist, tree type, bool max) return NULL_TREE; } +/* Fold a call to builtin carg(a+bi) -> atan2(b,a). */ + +static tree +fold_builtin_carg(tree arglist, tree type) +{ + if (validate_arglist (arglist, COMPLEX_TYPE, VOID_TYPE)) + { + tree atan2_fn = mathfn_built_in (type, BUILT_IN_ATAN2); + + if (atan2_fn) + { + tree arg = builtin_save_expr (TREE_VALUE (arglist)); + tree r_arg = fold_build1 (REALPART_EXPR, type, arg); + tree i_arg = fold_build1 (IMAGPART_EXPR, type, arg); + tree newarglist = tree_cons (NULL_TREE, i_arg, + build_tree_list (NULL_TREE, r_arg)); + return build_function_call_expr (atan2_fn, newarglist); + } + } + + return NULL_TREE; +} + /* Fold a call to __builtin_isnan(), __builtin_isinf, __builtin_finite. EXP is the CALL_EXPR for the call. */ @@ -9339,6 +9362,9 @@ fold_builtin_1 (tree fndecl, tree arglist, bool ignore) CASE_FLT_FN (BUILT_IN_CABS): return fold_builtin_cabs (arglist, type, fndecl); + CASE_FLT_FN (BUILT_IN_CARG): + return fold_builtin_carg (arglist, type); + CASE_FLT_FN (BUILT_IN_SQRT): return fold_builtin_sqrt (arglist, type); |