aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorKai Tietz <ktietz@redhat.com>2011-04-20 18:16:28 +0200
committerKai Tietz <ktietz@gcc.gnu.org>2011-04-20 18:16:28 +0200
commit583722ee5836f737b0a05f915d6d4ffc095565f9 (patch)
tree946228850bcada56ffd10a40a2a1dfe0ba959199 /gcc/fold-const.c
parent422c0989b5a4470dabec04c3795eafec7015c2ff (diff)
downloadgcc-583722ee5836f737b0a05f915d6d4ffc095565f9.zip
gcc-583722ee5836f737b0a05f915d6d4ffc095565f9.tar.gz
gcc-583722ee5836f737b0a05f915d6d4ffc095565f9.tar.bz2
ChangeLog gcc/
2011-04-20 Kai Tietz <ktietz@redhat.com> * fold-const.c (fold_binary_loc): Add handling for (X & ~Y) | (~X & Y) and (X && !Y) | (!X && Y) optimization to (X ^ Y). ChangeLog gcc/testsuite 2011-04-20 Kai Tietz <ktietz@redhat.com> * gcc.dg/binio-xor1.c: New test. * gcc.dg/binio-xor2.c: New test. * gcc.dg/binio-xor3.c: New test. * gcc.dg/binio-xor4.c: New test. * gcc.dg/binio-xor5.c: New test. From-SVN: r172776
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 8d543c4..c4bf088 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10660,6 +10660,28 @@ fold_binary_loc (location_t loc,
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 0));
+ /* (X & ~Y) | (~X & Y) is X ^ Y */
+ if (TREE_CODE (arg0) == BIT_AND_EXPR
+ && TREE_CODE (arg1) == BIT_AND_EXPR)
+ {
+ tree a0, a1, l0, l1, n0, n1;
+
+ a0 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
+ a1 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
+
+ l0 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+ l1 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
+
+ n0 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l0);
+ n1 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l1);
+
+ if ((operand_equal_p (n0, a0, 0)
+ && operand_equal_p (n1, a1, 0))
+ || (operand_equal_p (n0, a1, 0)
+ && operand_equal_p (n1, a0, 0)))
+ return fold_build2_loc (loc, BIT_XOR_EXPR, type, l0, n1);
+ }
+
t1 = distribute_bit_expr (loc, code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;
@@ -12039,6 +12061,27 @@ fold_binary_loc (location_t loc,
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
+ /* (X && !Y) || (!X && Y) is X ^ Y */
+ if (TREE_CODE (arg0) == TRUTH_AND_EXPR
+ && TREE_CODE (arg1) == TRUTH_AND_EXPR)
+ {
+ tree a0, a1, l0, l1, n0, n1;
+
+ a0 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
+ a1 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
+
+ l0 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+ l1 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
+
+ n0 = fold_build1_loc (loc, TRUTH_NOT_EXPR, type, l0);
+ n1 = fold_build1_loc (loc, TRUTH_NOT_EXPR, type, l1);
+
+ if ((operand_equal_p (n0, a0, 0)
+ && operand_equal_p (n1, a1, 0))
+ || (operand_equal_p (n0, a1, 0)
+ && operand_equal_p (n1, a0, 0)))
+ return fold_build2_loc (loc, TRUTH_XOR_EXPR, type, l0, n1);
+ }
goto truth_andor;
case TRUTH_XOR_EXPR: