diff options
author | Jason Merrill <jason@yorick.cygnus.com> | 1998-05-22 20:58:14 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 1998-05-22 16:58:14 -0400 |
commit | 697073d938614f9285bf9e9ffc5c53d657d9677e (patch) | |
tree | 22ca22ac3001522fcadc9ca83f1ac92b53a179e1 | |
parent | 49feb20cf7a83961a57efdc1d4955a99c3d5a11b (diff) | |
download | gcc-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
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/fold-const.c | 34 | ||||
-rw-r--r-- | gcc/tree.h | 1 |
3 files changed, 40 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1566492..4b21e90 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 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. */ @@ -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) |