diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-24 19:55:47 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-24 19:55:47 +0000 |
commit | 428b02b455d432f94f3c804dddb49392b2de3011 (patch) | |
tree | 519e3bd036acaa7e2d9abb7b298d90d27eb168d5 /gcc/fold-const.c | |
parent | 40f89ebf453edf50b8dd69e7df4d8ca71eefff35 (diff) | |
download | gcc-428b02b455d432f94f3c804dddb49392b2de3011.tar.gz |
2007-02-24 Richard Guenther <rguenther@suse.de>
PR middle-end/30951
* fold-const.c (fold_binary): Fold x +- CST op x for
EQ_EXPR and NE_EXPR.
* gcc.dg/pr30951.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122295 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ffd63cf5e7e..80c3c41ecff 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11203,6 +11203,24 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) fold_convert (TREE_TYPE (arg0), arg1), TREE_OPERAND (arg0, 1))); + /* Transform comparisons of the form X +- C CMP X. */ + if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) + && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) + && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST + && (INTEGRAL_TYPE_P (TREE_TYPE (arg0)) + || POINTER_TYPE_P (TREE_TYPE (arg0)))) + { + tree cst = TREE_OPERAND (arg0, 1); + + if (code == EQ_EXPR + && !integer_zerop (cst)) + return omit_two_operands (type, boolean_false_node, + TREE_OPERAND (arg0, 0), arg1); + else + return omit_two_operands (type, boolean_true_node, + TREE_OPERAND (arg0, 0), arg1); + } + /* If we have X - Y == 0, we can convert that to X == Y and similarly for !=. Don't do this for ordered comparisons due to overflow. */ if (TREE_CODE (arg0) == MINUS_EXPR |