diff options
author | Roger Sayle <roger@eyesopen.com> | 2004-06-10 13:29:34 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2004-06-10 13:29:34 +0000 |
commit | 9655d83b750bc6de0074b0501044d4bcb28679d9 (patch) | |
tree | e940d7de6a39821eb5ab7003e89e3a25995283fa /gcc/builtins.c | |
parent | a7b155a6ad9475549f1c0e32bb7c29dc66567864 (diff) | |
download | gcc-9655d83b750bc6de0074b0501044d4bcb28679d9.zip gcc-9655d83b750bc6de0074b0501044d4bcb28679d9.tar.gz gcc-9655d83b750bc6de0074b0501044d4bcb28679d9.tar.bz2 |
fold-const.c (fold_abs_const): Make extern.
* fold-const.c (fold_abs_const): Make extern.
* tree.h (fold_abs_const): Prototype here.
* builtins.c (fold_builtin_fabs): New function to transform
fabs, fabsf and fabsl builtins into ABS_EXPR tree nodes.
(fold_builtin_abs): New function to transform abs, labs, llabs
and imaxabs builtins into ABS_EXPR tree nodes.
(expand_builtin): Fall back to a function call for abs, labs,
llabs and imaxabs builtins that survive constant folding.
(fold_builtin_1): Call fold_builtin_fabs for FABS, FABSF and
FABSL, and fold_builtin_abs for ABS, LABS, LLABS and IMAXABS.
From-SVN: r82916
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 9816af0..793d7bc 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -166,6 +166,8 @@ static tree fold_builtin_copysign (tree, tree); static tree fold_builtin_isascii (tree); static tree fold_builtin_toascii (tree); static tree fold_builtin_isdigit (tree); +static tree fold_builtin_fabs (tree, tree); +static tree fold_builtin_abs (tree, tree); static tree simplify_builtin_memcmp (tree); static tree simplify_builtin_strcmp (tree); @@ -5628,13 +5630,6 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, switch (fcode) { - case BUILT_IN_ABS: - case BUILT_IN_LABS: - case BUILT_IN_LLABS: - case BUILT_IN_IMAXABS: - /* build_function_call changes these into ABS_EXPR. */ - abort (); - case BUILT_IN_FABS: case BUILT_IN_FABSF: case BUILT_IN_FABSL: @@ -7587,6 +7582,38 @@ fold_builtin_isdigit (tree arglist) } } +/* Fold a call to fabs, fabsf or fabsl. */ + +static tree +fold_builtin_fabs (tree arglist, tree type) +{ + tree arg; + + if (!validate_arglist (arglist, REAL_TYPE, VOID_TYPE)) + return 0; + + arg = TREE_VALUE (arglist); + if (TREE_CODE (arg) == REAL_CST) + return fold_abs_const (arg, type); + return fold (build1 (ABS_EXPR, type, arg)); +} + +/* Fold a call to abs, labs, llabs or imaxabs. */ + +static tree +fold_builtin_abs (tree arglist, tree type) +{ + tree arg; + + if (!validate_arglist (arglist, INTEGER_TYPE, VOID_TYPE)) + return 0; + + arg = TREE_VALUE (arglist); + if (TREE_CODE (arg) == INTEGER_CST) + return fold_abs_const (arg, type); + return fold (build1 (ABS_EXPR, type, arg)); +} + /* Used by constant folding to eliminate some builtin calls early. EXP is the CALL_EXPR of a call to a builtin function. */ @@ -7628,9 +7655,13 @@ fold_builtin_1 (tree exp) case BUILT_IN_FABS: case BUILT_IN_FABSF: case BUILT_IN_FABSL: - if (validate_arglist (arglist, REAL_TYPE, VOID_TYPE)) - return fold (build1 (ABS_EXPR, type, TREE_VALUE (arglist))); - break; + return fold_builtin_fabs (arglist, type); + + case BUILT_IN_ABS: + case BUILT_IN_LABS: + case BUILT_IN_LLABS: + case BUILT_IN_IMAXABS: + return fold_builtin_abs (arglist, type); case BUILT_IN_CABS: case BUILT_IN_CABSF: |