OSDN Git Service

* fold-const.c (ssize_binop): New fn.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 22 May 1998 20:58:14 +0000 (20:58 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 22 May 1998 20:58:14 +0000 (20:58 +0000)
* tree.h: Declare it.

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

gcc/ChangeLog
gcc/fold-const.c
gcc/tree.h

index 1566492..4b21e90 100644 (file)
@@ -1,3 +1,8 @@
+1998-05-22  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * fold-const.c (ssize_binop): New fn.
+       * tree.h: Declare it.
+
 Fri May 22 03:42:05 1998  Richard Earnshaw (rearnsha@arm.com)
 
        * genextract.c (print_path): Handle zero-length path as a special 
index c47f80a..9d1cb36 100644 (file)
@@ -1489,6 +1489,40 @@ size_binop (code, arg0, arg1)
 
   return fold (build (code, sizetype, arg0, arg1));
 }
+
+/* Combine operands OP1 and OP2 with arithmetic operation CODE.
+   CODE is a tree code.  Data type is taken from `ssizetype',
+   If the operands are constant, so is the result.  */
+
+tree
+ssize_binop (code, arg0, arg1)
+     enum tree_code code;
+     tree arg0, arg1;
+{
+  /* Handle the special case of two integer constants faster.  */
+  if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
+    {
+      /* And some specific cases even faster than that.  */
+      if (code == PLUS_EXPR && integer_zerop (arg0))
+       return arg1;
+      else if ((code == MINUS_EXPR || code == PLUS_EXPR)
+              && integer_zerop (arg1))
+       return arg0;
+      else if (code == MULT_EXPR && integer_onep (arg0))
+       return arg1;
+
+      /* Handle general case of two integer constants.  We convert
+         arg0 to ssizetype because int_const_binop uses its type for the
+        return value.  */
+      arg0 = convert (ssizetype, arg0);
+      return int_const_binop (code, arg0, arg1, 0, 0);
+    }
+
+  if (arg0 == error_mark_node || arg1 == error_mark_node)
+    return error_mark_node;
+
+  return fold (build (code, ssizetype, arg0, arg1));
+}
 \f
 /* Given T, a tree representing type conversion of ARG1, a constant,
    return a constant tree representing the result of conversion.  */
index 440c664..6320077 100644 (file)
@@ -1484,6 +1484,7 @@ extern tree convert                       PROTO((tree, tree));
 extern tree size_in_bytes              PROTO((tree));
 extern HOST_WIDE_INT int_size_in_bytes PROTO((tree));
 extern tree size_binop                 PROTO((enum tree_code, tree, tree));
+extern tree ssize_binop                        PROTO((enum tree_code, tree, tree));
 extern tree size_int_wide              PROTO((unsigned HOST_WIDE_INT,
                                               unsigned HOST_WIDE_INT, int));
 #define size_int(L) size_int_2 ((L), 0, 0)