From 9655d83b750bc6de0074b0501044d4bcb28679d9 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Thu, 10 Jun 2004 13:29:34 +0000 Subject: [PATCH] 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 --- gcc/ChangeLog | 13 ++++++++++++ gcc/builtins.c | 51 ++++++++++++++++++++++++++++++++++++++---------- gcc/fold-const.c | 3 +-- gcc/tree.h | 1 + 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ed3165aa850..712b0064c2c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2004-06-10 Roger Sayle + + * 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. + 2004-06-10 Jakub Jelinek * config/ia64/unwind-ia64.c (uw_frame_state_for): Don't assume a diff --git a/gcc/builtins.c b/gcc/builtins.c index 9816af0817c..793d7bc9208 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: diff --git a/gcc/fold-const.c b/gcc/fold-const.c index be97417253d..f5bd659fa34 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -135,7 +135,6 @@ static bool reorder_operands_p (tree, tree); static bool tree_swap_operands_p (tree, tree, bool); static tree fold_negate_const (tree, tree); -static tree fold_abs_const (tree, tree); static tree fold_not_const (tree, tree); static tree fold_relational_const (enum tree_code, tree, tree, tree); static tree fold_relational_hi_lo (enum tree_code *, const tree, @@ -9846,7 +9845,7 @@ fold_negate_const (tree arg0, tree type) TYPE is the type of the result. */ -static tree +tree fold_abs_const (tree arg0, tree type) { tree t = NULL_TREE; diff --git a/gcc/tree.h b/gcc/tree.h index e867302965e..6e97babfd6e 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3462,6 +3462,7 @@ extern tree fold (tree); extern tree fold_initializer (tree); extern tree fold_convert (tree, tree); extern tree fold_single_bit_test (enum tree_code, tree, tree, tree); +extern tree fold_abs_const (tree, tree); extern int force_fit_type (tree, int); extern int add_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT, -- 2.30.2