diff options
author | Roger Sayle <roger@eyesopen.com> | 2006-10-29 21:41:48 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2006-10-29 21:41:48 +0000 |
commit | c159ffe7060983000c4cd595318fc08c3983db66 (patch) | |
tree | f4d6cffd55adc058d815562150ef8f07f2e13b87 /gcc/fold-const.c | |
parent | 153ae66aeea1d7b38af1cf77a4107db5964a759a (diff) | |
download | gcc-c159ffe7060983000c4cd595318fc08c3983db66.zip gcc-c159ffe7060983000c4cd595318fc08c3983db66.tar.gz gcc-c159ffe7060983000c4cd595318fc08c3983db66.tar.bz2 |
fold-const.c (fold_comparison): Fold ~X op ~Y as Y op X.
* fold-const.c (fold_comparison): Fold ~X op ~Y as Y op X.
Fold ~X op C as X op' ~C, where op' is the swapped comparison.
(fold_binary): ~X eq/ne C is now handled in fold_comparison.
Fold -X eq/ne -Y as X eq/ne Y.
* gcc.dg/fold-compare-1.c: New test case.
From-SVN: r118158
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 1c3c752..a822abd 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8360,6 +8360,20 @@ fold_comparison (enum tree_code code, tree type, tree op0, tree op1) return tem; } + /* Fold ~X op ~Y as Y op X. */ + if (TREE_CODE (arg0) == BIT_NOT_EXPR + && TREE_CODE (arg1) == BIT_NOT_EXPR) + return fold_build2 (code, type, + TREE_OPERAND (arg1, 0), + TREE_OPERAND (arg0, 0)); + + /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ + if (TREE_CODE (arg0) == BIT_NOT_EXPR + && TREE_CODE (arg1) == INTEGER_CST) + return fold_build2 (swap_tree_comparison (code), type, + TREE_OPERAND (arg0, 0), + fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), arg1)); + return NULL_TREE; } @@ -10426,13 +10440,6 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) && code == EQ_EXPR) return fold_build1 (TRUTH_NOT_EXPR, type, arg0); - /* ~a != C becomes a != ~C where C is a constant. Likewise for ==. */ - if (TREE_CODE (arg0) == BIT_NOT_EXPR - && TREE_CODE (arg1) == INTEGER_CST) - return fold_build2 (code, type, TREE_OPERAND (arg0, 0), - fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), - arg1)); - /* If this is an equality comparison of the address of a non-weak object against zero, then we know the result. */ if (TREE_CODE (arg0) == ADDR_EXPR @@ -10798,6 +10805,14 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) tree res = constant_boolean_node (code==NE_EXPR, type); return omit_one_operand (type, res, arg0); } + + /* Fold -X op -Y as X op Y, where op is eq/ne. */ + if (TREE_CODE (arg0) == NEGATE_EXPR + && TREE_CODE (arg1) == NEGATE_EXPR) + return fold_build2 (code, type, + TREE_OPERAND (arg0, 0), + TREE_OPERAND (arg1, 0)); + return NULL_TREE; case LT_EXPR: |