Handle constant fp classifications in fold-const-call.c
authorRichard Sandiford <richard.sandiford@arm.com>
Sat, 7 Nov 2015 10:05:51 +0000 (10:05 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Sat, 7 Nov 2015 10:05:51 +0000 (10:05 +0000)
Move the constant "is finite", "is infinite" and "is nan" queries
to fold-const-call.c.

Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.

gcc/
* builtins.c (fold_builtin_classify): Move constant cases to...
* fold-const-call.c (fold_const_call_ss): ...here.

From-SVN: r229920

gcc/ChangeLog
gcc/builtins.c
gcc/fold-const-call.c

index ab06aab2204bfc78f716d34e21224dcde34628f0..518c2163fbe3e454bdba60992b5edbbda3af2acb 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-07  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * builtins.c (fold_builtin_classify): Move constant cases to...
+       * fold-const-call.c (fold_const_call_ss): ...here.
+
 2015-11-07  Richard Sandiford  <richard.sandiford@arm.com>
 
        * builtins.h (c_getstr): Move to...
index 69c56e75cd571bd154db884028d51c260b58885f..6eefd5409caa62a3c9c98e4a56f5bc8dd54bd67a 100644 (file)
@@ -8018,7 +8018,6 @@ static tree
 fold_builtin_classify (location_t loc, tree fndecl, tree arg, int builtin_index)
 {
   tree type = TREE_TYPE (TREE_TYPE (fndecl));
-  REAL_VALUE_TYPE r;
 
   if (!validate_arg (arg, REAL_TYPE))
     return NULL_TREE;
@@ -8029,16 +8028,6 @@ fold_builtin_classify (location_t loc, tree fndecl, tree arg, int builtin_index)
       if (!HONOR_INFINITIES (arg))
        return omit_one_operand_loc (loc, type, integer_zero_node, arg);
 
-      if (TREE_CODE (arg) == REAL_CST)
-       {
-         r = TREE_REAL_CST (arg);
-         if (real_isinf (&r))
-           return real_compare (GT_EXPR, &r, &dconst0)
-                  ? integer_one_node : integer_minus_one_node;
-         else
-           return integer_zero_node;
-       }
-
       return NULL_TREE;
 
     case BUILT_IN_ISINF_SIGN:
@@ -8078,24 +8067,12 @@ fold_builtin_classify (location_t loc, tree fndecl, tree arg, int builtin_index)
          && !HONOR_INFINITIES (arg))
        return omit_one_operand_loc (loc, type, integer_one_node, arg);
 
-      if (TREE_CODE (arg) == REAL_CST)
-       {
-         r = TREE_REAL_CST (arg);
-         return real_isfinite (&r) ? integer_one_node : integer_zero_node;
-       }
-
       return NULL_TREE;
 
     case BUILT_IN_ISNAN:
       if (!HONOR_NANS (arg))
        return omit_one_operand_loc (loc, type, integer_zero_node, arg);
 
-      if (TREE_CODE (arg) == REAL_CST)
-       {
-         r = TREE_REAL_CST (arg);
-         return real_isnan (&r) ? integer_one_node : integer_zero_node;
-       }
-
       arg = builtin_save_expr (arg);
       return fold_build2_loc (loc, UNORDERED_EXPR, type, arg, arg);
 
index 5af2c635313ee564e347c848651d733b211c8dfc..c277d2b98fc2dc9a1b2fa316bbb6907f467d2f1e 100644 (file)
@@ -736,6 +736,31 @@ fold_const_call_ss (wide_int *result, built_in_function fn,
       /* Not yet folded to a constant.  */
       return false;
 
+    CASE_FLT_FN (BUILT_IN_FINITE):
+    case BUILT_IN_FINITED32:
+    case BUILT_IN_FINITED64:
+    case BUILT_IN_FINITED128:
+    case BUILT_IN_ISFINITE:
+      *result = wi::shwi (real_isfinite (arg) ? 1 : 0, precision);
+      return true;
+
+    CASE_FLT_FN (BUILT_IN_ISINF):
+    case BUILT_IN_ISINFD32:
+    case BUILT_IN_ISINFD64:
+    case BUILT_IN_ISINFD128:
+      if (real_isinf (arg))
+       *result = wi::shwi (arg->sign ? -1 : 1, precision);
+      else
+       *result = wi::shwi (0, precision);
+      return true;
+
+    CASE_FLT_FN (BUILT_IN_ISNAN):
+    case BUILT_IN_ISNAND32:
+    case BUILT_IN_ISNAND64:
+    case BUILT_IN_ISNAND128:
+      *result = wi::shwi (real_isnan (arg) ? 1 : 0, precision);
+      return true;
+
     default:
       return false;
     }