* 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
+2004-06-10 Roger Sayle <roger@eyesopen.com>
+
+ * 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 <jakub@redhat.com>
* config/ia64/unwind-ia64.c (uw_frame_state_for): Don't assume a
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);
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:
}
}
+/* 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. */
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:
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,
TYPE is the type of the result. */
-static tree
+tree
fold_abs_const (tree arg0, tree type)
{
tree t = NULL_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,