aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2015-07-01 07:42:10 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2015-07-01 07:42:10 +0000
commit97e7739106863e3d334a8f9bb0cfcc8ae0e972de (patch)
tree06bc5789da51629911c3c7b5192a9b241054aaf7 /gcc
parenta64be36b477db8ab8a10b13c2d18ede5b7f08738 (diff)
downloadgcc-97e7739106863e3d334a8f9bb0cfcc8ae0e972de.zip
gcc-97e7739106863e3d334a8f9bb0cfcc8ae0e972de.tar.gz
gcc-97e7739106863e3d334a8f9bb0cfcc8ae0e972de.tar.bz2
fold-const.c (fold_binary_loc): Move ~X ^ X -> -1 and (X & Y) ^ Y -> ~X & Y transforms to ...
2015-07-01 Richard Biener <rguenther@suse.de> * fold-const.c (fold_binary_loc): Move ~X ^ X -> -1 and (X & Y) ^ Y -> ~X & Y transforms to ... * match.pd: ... here. From-SVN: r225225
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c57
-rw-r--r--gcc/match.pd10
3 files changed, 16 insertions, 57 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index af2c5d8..3f0ba84 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2015-07-01 Richard Biener <rguenther@suse.de>
+
+ * fold-const.c (fold_binary_loc): Move ~X ^ X -> -1 and
+ (X & Y) ^ Y -> ~X & Y transforms to ...
+ * match.pd: ... here.
+
2015-07-01 Richard Biener <rguenther@suse.de>
* genmatch.c (expr::gen_transform): Shortcut re-simplifying
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 7e30002..5da6ed3 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10979,24 +10979,6 @@ fold_binary_loc (location_t loc,
goto bit_rotate;
case BIT_XOR_EXPR:
- /* ~X ^ X is -1. */
- if (TREE_CODE (arg0) == BIT_NOT_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
- {
- t1 = build_zero_cst (type);
- t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
- return omit_one_operand_loc (loc, type, t1, arg1);
- }
-
- /* X ^ ~X is -1. */
- if (TREE_CODE (arg1) == BIT_NOT_EXPR
- && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
- {
- t1 = build_zero_cst (type);
- t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
- return omit_one_operand_loc (loc, type, t1, arg0);
- }
-
/* Fold (X & 1) ^ 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& INTEGRAL_TYPE_P (type)
@@ -11005,45 +10987,6 @@ fold_binary_loc (location_t loc,
return fold_build2_loc (loc, EQ_EXPR, type, arg0,
build_zero_cst (TREE_TYPE (arg0)));
- /* Fold (X & Y) ^ Y as ~X & Y. */
- if (TREE_CODE (arg0) == BIT_AND_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
- {
- tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
- return fold_build2_loc (loc, BIT_AND_EXPR, type,
- fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
- fold_convert_loc (loc, type, arg1));
- }
- /* Fold (X & Y) ^ X as ~Y & X. */
- if (TREE_CODE (arg0) == BIT_AND_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
- && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
- {
- tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
- return fold_build2_loc (loc, BIT_AND_EXPR, type,
- fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
- fold_convert_loc (loc, type, arg1));
- }
- /* Fold X ^ (X & Y) as X & ~Y. */
- if (TREE_CODE (arg1) == BIT_AND_EXPR
- && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
- {
- tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
- return fold_build2_loc (loc, BIT_AND_EXPR, type,
- fold_convert_loc (loc, type, arg0),
- fold_build1_loc (loc, BIT_NOT_EXPR, type, tem));
- }
- /* Fold X ^ (Y & X) as ~Y & X. */
- if (TREE_CODE (arg1) == BIT_AND_EXPR
- && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)
- && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
- {
- tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
- return fold_build2_loc (loc, BIT_AND_EXPR, type,
- fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
- fold_convert_loc (loc, type, arg0));
- }
-
/* See if this can be simplified into a rotate first. If that
is unsuccessful continue in the association code. */
goto bit_rotate;
diff --git a/gcc/match.pd b/gcc/match.pd
index 74e42ef..f013adc 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -298,6 +298,11 @@ along with GCC; see the file COPYING3. If not see
(bit_xor @0 integer_all_onesp@1)
(bit_not @0))
+/* ~X ^ X is -1. */
+(simplify
+ (bit_xor:c (bit_not @0) @0)
+ { build_all_ones_cst (type); })
+
/* x & ~0 -> x */
(simplify
(bit_and @0 integer_all_onesp)
@@ -428,6 +433,11 @@ along with GCC; see the file COPYING3. If not see
(bit_xor (convert? (bit_not @0)) INTEGER_CST@1)
(bit_xor (convert @0) (bit_not @1)))
+/* Fold (X & Y) ^ Y as ~X & Y. */
+(simplify
+ (bit_xor:c (bit_and:c @0 @1) @1)
+ (bit_and (bit_not @0) @1))
+
(simplify
(abs (abs@1 @0))