aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2006-11-12 18:41:31 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2006-11-12 18:41:31 +0000
commit015e23f4005b00afaf87c90ef67db48b364fe70e (patch)
treeb02ba3cb889c222125601c7fa415210e5d22fcf6 /gcc/fold-const.c
parentc0493b13fb859a27d5554c18ff11db2c1ebb7241 (diff)
downloadgcc-015e23f4005b00afaf87c90ef67db48b364fe70e.zip
gcc-015e23f4005b00afaf87c90ef67db48b364fe70e.tar.gz
gcc-015e23f4005b00afaf87c90ef67db48b364fe70e.tar.bz2
re PR tree-optimization/13827 ((a & b) != (c & b) should be transformed to ((a^c) & b) !=0)
PR tree-optimization/13827 * fold-const.c (fold_binary) <EQ_EXPR, NE_EXPR>: Fold (X&C) op (Y&C) as ((X^Y)&C) op 0. * gcc.dg/fold-eqand-1.c: New test case. From-SVN: r118727
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 08e74a2..cf1df69 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10818,6 +10818,49 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0));
+ /* Fold (X & C) op (Y & C) as (X ^ Y) & C op 0", and symmetries. */
+ if (TREE_CODE (arg0) == BIT_AND_EXPR
+ && TREE_CODE (arg1) == BIT_AND_EXPR)
+ {
+ tree arg00 = TREE_OPERAND (arg0, 0);
+ tree arg01 = TREE_OPERAND (arg0, 1);
+ tree arg10 = TREE_OPERAND (arg1, 0);
+ tree arg11 = TREE_OPERAND (arg1, 1);
+ tree itype = TREE_TYPE (arg0);
+
+ if (operand_equal_p (arg01, arg11, 0))
+ return fold_build2 (code, type,
+ fold_build2 (BIT_AND_EXPR, itype,
+ fold_build2 (BIT_XOR_EXPR, itype,
+ arg00, arg10),
+ arg01),
+ build_int_cst (itype, 0));
+
+ if (operand_equal_p (arg01, arg10, 0))
+ return fold_build2 (code, type,
+ fold_build2 (BIT_AND_EXPR, itype,
+ fold_build2 (BIT_XOR_EXPR, itype,
+ arg00, arg11),
+ arg01),
+ build_int_cst (itype, 0));
+
+ if (operand_equal_p (arg00, arg11, 0))
+ return fold_build2 (code, type,
+ fold_build2 (BIT_AND_EXPR, itype,
+ fold_build2 (BIT_XOR_EXPR, itype,
+ arg01, arg10),
+ arg00),
+ build_int_cst (itype, 0));
+
+ if (operand_equal_p (arg00, arg10, 0))
+ return fold_build2 (code, type,
+ fold_build2 (BIT_AND_EXPR, itype,
+ fold_build2 (BIT_XOR_EXPR, itype,
+ arg01, arg11),
+ arg00),
+ build_int_cst (itype, 0));
+ }
+
return NULL_TREE;
case LT_EXPR: