aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJason Merrill <jason@yorick.cygnus.com>1998-05-22 20:58:14 +0000
committerJason Merrill <jason@gcc.gnu.org>1998-05-22 16:58:14 -0400
commit697073d938614f9285bf9e9ffc5c53d657d9677e (patch)
tree22ca22ac3001522fcadc9ca83f1ac92b53a179e1 /gcc/fold-const.c
parent49feb20cf7a83961a57efdc1d4955a99c3d5a11b (diff)
downloadgcc-697073d938614f9285bf9e9ffc5c53d657d9677e.zip
gcc-697073d938614f9285bf9e9ffc5c53d657d9677e.tar.gz
gcc-697073d938614f9285bf9e9ffc5c53d657d9677e.tar.bz2
fold-const.c (ssize_binop): New fn.
* fold-const.c (ssize_binop): New fn. * tree.h: Declare it. From-SVN: r19963
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c47f80a..9d1cb36 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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));
+}
/* Given T, a tree representing type conversion of ARG1, a constant,
return a constant tree representing the result of conversion. */