OSDN Git Service

* fold-const.c (constant_boolean_node): New function.
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 15 May 1998 07:19:38 +0000 (07:19 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 15 May 1998 07:19:38 +0000 (07:19 +0000)
(fold): Use it.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@19775 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c

index f3c35da..3b0c921 100644 (file)
@@ -1,3 +1,8 @@
+Fri May 15 07:20:03 1998  Mark Mitchell  <mmitchell@usa.net>
+
+       * fold-const.c (constant_boolean_node): New function.
+       (fold): Use it.
+
 Fri May 15 11:21:16 1998  J"orn Rennecke <amylaar@cygnus.co.uk>
 
        * sh.c (gen_shl_and): Don't sign extend constant for kind two.
index bfcaed7..c47f80a 100644 (file)
@@ -94,6 +94,7 @@ static tree unextend          PROTO((tree, int, int, tree));
 static tree fold_truthop       PROTO((enum tree_code, tree, tree, tree));
 static tree strip_compound_expr PROTO((tree, tree));
 static int multiple_of_p       PROTO((tree, tree, tree));
+static tree constant_boolean_node PROTO((int, tree));
 
 #ifndef BRANCH_COST
 #define BRANCH_COST 1
@@ -3702,6 +3703,27 @@ strip_compound_expr (t, s)
   return t;
 }
 \f
+/* Return a node which has the indicated constant VALUE (either 0 or
+   1), and is of the indicated TYPE.  */
+
+tree
+constant_boolean_node (value, type)
+     int value;
+     tree type;
+{
+  if (type == integer_type_node)
+    return value ? integer_one_node : integer_zero_node;
+  else if (TREE_CODE (type) == BOOLEAN_TYPE)
+    return truthvalue_conversion (value ? integer_one_node :
+                                 integer_zero_node); 
+  else 
+    {
+      tree t = build_int_2 (value, 0);
+      TREE_TYPE (t) = type;
+      return t;
+    }
+}
+
 /* Perform constant folding and related simplification of EXPR.
    The related simplifications include x*1 => x, x*0 => 0, etc.,
    and application of the associative law.
@@ -5343,14 +5365,7 @@ fold (expr)
            case GE_EXPR:
            case LE_EXPR:
              if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
-               {
-                 if (type == integer_type_node)
-                   return integer_one_node;
-
-                 t = build_int_2 (1, 0);
-                 TREE_TYPE (t) = type;
-                 return t;
-               }
+               return constant_boolean_node (1, type);
              code = EQ_EXPR;
              TREE_SET_CODE (t, code);
              break;
@@ -5362,12 +5377,7 @@ fold (expr)
              /* ... fall through ...  */
            case GT_EXPR:
            case LT_EXPR:
-             if (type == integer_type_node)
-               return integer_zero_node;
-
-             t = build_int_2 (0, 0);
-             TREE_TYPE (t) = type;
-             return t;
+             return constant_boolean_node (0, type);
            default:
              abort ();
            }