aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1993-08-19 08:28:38 -0400
committerRichard Kenner <kenner@gcc.gnu.org>1993-08-19 08:28:38 -0400
commit2df46b06a27b26a2b142fc28db58c57985bf0b6e (patch)
treee96bee4e7c3a76d57d8342155a8a22d858e6a249 /gcc
parent0dc92bf6bc0f20b66b5d957993efca53d908a384 (diff)
downloadgcc-2df46b06a27b26a2b142fc28db58c57985bf0b6e.zip
gcc-2df46b06a27b26a2b142fc28db58c57985bf0b6e.tar.gz
gcc-2df46b06a27b26a2b142fc28db58c57985bf0b6e.tar.bz2
(fold): Handle EQ_EXPR and NE_EXPR where both args are comparisons or
BIT_AND_EXPR with constant 1. From-SVN: r5186
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fold-const.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 9d5aecc..a859f6d 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -3167,9 +3167,11 @@ fold (expr)
one of the operands is a comparison and the other is either a comparison
or a BIT_AND_EXPR with the constant 1. In that case, the code below
would make the expression more complex. Change it to a
- TRUTH_{AND,OR}_EXPR. */
+ TRUTH_{AND,OR}_EXPR. Likewise, convert a similar NE_EXPR to
+ TRUTH_XOR_EXPR and an EQ_EXPR to the inversion of a TRUTH_XOR_EXPR. */
- if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR)
+ if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR
+ || code == EQ_EXPR || code == NE_EXPR)
&& ((TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
&& (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<'
|| (TREE_CODE (arg1) == BIT_AND_EXPR
@@ -3178,8 +3180,17 @@ fold (expr)
&& (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
|| (TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1)))))))
- return fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
- type, arg0, arg1));
+ {
+ t = fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR
+ : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR
+ : TRUTH_XOR_EXPR,
+ type, arg0, arg1));
+
+ if (code == EQ_EXPR)
+ t = invert_truthvalue (t);
+
+ return t;
+ }
if (TREE_CODE_CLASS (code) == '1')
{