diff options
| author | rakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-31 18:29:34 +0000 |
|---|---|---|
| committer | rakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-31 18:29:34 +0000 |
| commit | 0e0b35f986cd3cccec3bf400fa443b1db73e727a (patch) | |
| tree | f8f5e57558cf91a668b545f5720692e87cd5d862 | |
| parent | ef437672e66a0efba5db4cfe035b168751b28a41 (diff) | |
| download | ppe42-gcc-0e0b35f986cd3cccec3bf400fa443b1db73e727a.tar.gz ppe42-gcc-0e0b35f986cd3cccec3bf400fa443b1db73e727a.zip | |
* fold-const.c (fold): Fold some comparisons of bit operations.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70009 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/ChangeLog | 4 | ||||
| -rw-r--r-- | gcc/fold-const.c | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 923f25ea669..caa596bc59a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2003-07-31 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz> + + * fold-const.c (fold): Fold some comparisons of bit operations. + Thu Jul 31 19:49:53 CEST 2003 Jan Hubicka <jh@suse.cz> * cgraph.c (create_edge): Fix typo. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 58cec23773b..aea392f8ab4 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7182,6 +7182,34 @@ fold (tree expr) if (tem) return tem; + /* If we have (A & C) == D where D & ~C != 0, convert this into 0. + Similarly for NE_EXPR. */ + if ((code == EQ_EXPR || code == NE_EXPR) + && TREE_CODE (arg0) == BIT_AND_EXPR + && TREE_CODE (arg1) == INTEGER_CST + && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) + { + tree dandnotc = fold (build (BIT_ANDTC_EXPR, TREE_TYPE (arg0), + arg1, TREE_OPERAND (arg0, 1))); + tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node; + if (!integer_zerop (dandnotc)) + return omit_one_operand (type, rslt, arg0); + } + + /* If we have (A | C) == D where C & ~D != 0, convert this into 0. + Similarly for NE_EXPR. */ + if ((code == EQ_EXPR || code == NE_EXPR) + && TREE_CODE (arg0) == BIT_IOR_EXPR + && TREE_CODE (arg1) == INTEGER_CST + && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) + { + tree candnotd = fold (build (BIT_ANDTC_EXPR, TREE_TYPE (arg0), + TREE_OPERAND (arg0, 1), arg1)); + tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node; + if (!integer_zerop (candnotd)) + return omit_one_operand (type, rslt, arg0); + } + /* If X is unsigned, convert X < (1 << Y) into X >> Y == 0 and similarly for >= into !=. */ if ((code == LT_EXPR || code == GE_EXPR) |

