diff options
author | ktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-06-20 11:49:27 +0000 |
---|---|---|
committer | ktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-06-20 11:49:27 +0000 |
commit | 860651b18763e92af779f0ded12003d160044f9a (patch) | |
tree | dd4bcae7ea7637ba444dd69516cc7a1ce4f2d852 /gcc/fold-const.c | |
parent | 0a9aabb7ea3dd92ce3e2f23100e8c8104fbdc2de (diff) | |
download | gcc-860651b18763e92af779f0ded12003d160044f9a.tar.gz |
ChangeLog gcc/
2011-06-20 Kai Tietz <ktietz@redhat.com>
* fold-const.c (fold_binary_loc): Add missing
folding for truth-not operations in combination
with binary and.
ChangeLog gcc/testsuite/
2011-06-20 Kai Tietz <ktietz@redhat.com>
* gcc.dg/binop-notand1.c: New test.
* gcc.dg/binop-notand2.c: New test.
* gcc.dg/binop-notand3.c: New test.
* gcc.dg/binop-notand4.c: New test.
* gcc.dg/binop-notand5.c: New test.
* gcc.dg/binop-notand6.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175206 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c39d33e1da2..e48aae9f4ce 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10866,13 +10866,19 @@ fold_binary_loc (location_t loc, if (operand_equal_p (arg0, arg1, 0)) return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); - /* ~X & X is always zero. */ - if (TREE_CODE (arg0) == BIT_NOT_EXPR + /* ~X & X, (X == 0) & X, and !X & X are always zero. */ + if ((TREE_CODE (arg0) == BIT_NOT_EXPR + || TREE_CODE (arg0) == TRUTH_NOT_EXPR + || (TREE_CODE (arg0) == EQ_EXPR + && integer_zerop (TREE_OPERAND (arg0, 1)))) && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) return omit_one_operand_loc (loc, type, integer_zero_node, arg1); - /* X & ~X is always zero. */ - if (TREE_CODE (arg1) == BIT_NOT_EXPR + /* X & ~X , X & (X == 0), and X & !X are always zero. */ + if ((TREE_CODE (arg1) == BIT_NOT_EXPR + || TREE_CODE (arg1) == TRUTH_NOT_EXPR + || (TREE_CODE (arg1) == EQ_EXPR + && integer_zerop (TREE_OPERAND (arg1, 1)))) && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) return omit_one_operand_loc (loc, type, integer_zero_node, arg0); @@ -10933,6 +10939,14 @@ fold_binary_loc (location_t loc, build_int_cst (TREE_TYPE (tem), 1)), build_int_cst (TREE_TYPE (tem), 0)); } + /* Fold !X & 1 as X == 0. */ + if (TREE_CODE (arg0) == TRUTH_NOT_EXPR + && integer_onep (arg1)) + { + tem = TREE_OPERAND (arg0, 0); + return fold_build2_loc (loc, EQ_EXPR, type, tem, + build_int_cst (TREE_TYPE (tem), 0)); + } /* Fold (X ^ Y) & Y as ~X & Y. */ if (TREE_CODE (arg0) == BIT_XOR_EXPR |