summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>1998-05-22 20:58:14 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>1998-05-22 20:58:14 +0000
commit3fd3b688a85bb39807413421d9466f9b95d357eb (patch)
tree22ca22ac3001522fcadc9ca83f1ac92b53a179e1 /gcc/fold-const.c
parenta3e6788d3dd8a44c4037f7978e1d158b888072d4 (diff)
downloadgcc-3fd3b688a85bb39807413421d9466f9b95d357eb.tar.gz
* fold-const.c (ssize_binop): New fn.
* tree.h: Declare it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@19963 138bc75d-0d04-0410-961f-82ee72b054a4
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 c47f80a7b68..9d1cb36458d 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. */