fold-const.c (fold_abs_const): Make extern.
authorRoger Sayle <roger@eyesopen.com>
Thu, 10 Jun 2004 13:29:34 +0000 (13:29 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Thu, 10 Jun 2004 13:29:34 +0000 (13:29 +0000)
* 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
gcc/builtins.c
gcc/fold-const.c
gcc/tree.h

index ed3165a..712b006 100644 (file)
@@ -1,3 +1,16 @@
+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
 2004-06-10  Jakub Jelinek  <jakub@redhat.com>
 
        * config/ia64/unwind-ia64.c (uw_frame_state_for): Don't assume a
index 9816af0..793d7bc 100644 (file)
@@ -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_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);
 
 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)
     {
 
   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:
     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.  */
 
 /* 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:
     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:
 
     case BUILT_IN_CABS:
     case BUILT_IN_CABSF:
index be97417..f5bd659 100644 (file)
@@ -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 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,
 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.  */
 
 
    TYPE is the type of the result.  */
 
-static tree
+tree
 fold_abs_const (tree arg0, tree type)
 {
   tree t = NULL_TREE;
 fold_abs_const (tree arg0, tree type)
 {
   tree t = NULL_TREE;
index e867302..6e97bab 100644 (file)
@@ -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_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,
 
 extern int force_fit_type (tree, int);
 extern int add_double (unsigned HOST_WIDE_INT, HOST_WIDE_INT,