summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2015-06-29 11:28:17 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2015-06-29 11:28:17 +0000
commit6b4402853b6c8f5f6c3ea6ca0509ee5e3889d870 (patch)
treede2d1287b43d96691cfb42c5e3a59e13f9cf3696
parent59f8b296e7b9b528e5a106bbd59d9c0d635be95a (diff)
downloadgcc-6b4402853b6c8f5f6c3ea6ca0509ee5e3889d870.tar.gz
2015-06-29 Richard Biener <rguenther@suse.de>
* genmatch.c (add_operator): Treat ADDR_EXPR as atom. * fold-const.c (fold_binary_loc): Move &A - &B simplification via ptr_difference_const ... * match.pd: ... here. When matching (X ^ Y) == Y also match with swapped operands. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@225115 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/fold-const.c10
-rw-r--r--gcc/genmatch.c3
-rw-r--r--gcc/match.pd17
4 files changed, 27 insertions, 11 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f891d4471d7..976e6894fa2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,13 @@
2015-06-29 Richard Biener <rguenther@suse.de>
+ * genmatch.c (add_operator): Treat ADDR_EXPR as atom.
+ * fold-const.c (fold_binary_loc): Move &A - &B simplification
+ via ptr_difference_const ...
+ * match.pd: ... here.
+ When matching (X ^ Y) == Y also match with swapped operands.
+
+2015-06-29 Richard Biener <rguenther@suse.de>
+
* lto-streamer.h (LTO_major_version): Bump to 5.
2015-06-29 Richard Biener <rguenther@suse.de>
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6f12dd04c6e..7b9502e2d38 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10618,16 +10618,6 @@ fold_binary_loc (location_t loc,
fold_convert_loc (loc, type,
negate_expr (arg1)));
- /* Try folding difference of addresses. */
- {
- HOST_WIDE_INT diff;
-
- if ((TREE_CODE (arg0) == ADDR_EXPR
- || TREE_CODE (arg1) == ADDR_EXPR)
- && ptr_difference_const (arg0, arg1, &diff))
- return build_int_cst_type (type, diff);
- }
-
/* Fold &a[i] - &a[j] to i-j. */
if (TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == ARRAY_REF
diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 195dc3cf3bc..2bd61d3f06b 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -324,6 +324,9 @@ add_operator (enum tree_code code, const char *id,
/* And allow CONSTRUCTOR for vector initializers. */
&& !(code == CONSTRUCTOR))
return;
+ /* Treat ADDR_EXPR as atom, thus don't allow matching its operand. */
+ if (code == ADDR_EXPR)
+ nargs = 0;
operator_id *op = new operator_id (code, id, nargs, tcc);
id_base **slot = operators->find_slot_with_hash (op, op->hashval, INSERT);
if (*slot)
diff --git a/gcc/match.pd b/gcc/match.pd
index b2f8429c120..0189a966bc8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -545,6 +545,21 @@ along with GCC; see the file COPYING3. If not see
(with { tree algn = wide_int_to_tree (TREE_TYPE (@0), wi::bit_not (@1)); }
(bit_and @0 { algn; })))
+/* Try folding difference of addresses. */
+(simplify
+ (minus (convert ADDR_EXPR@0) (convert @1))
+ (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
+ (with { HOST_WIDE_INT diff; }
+ (if (ptr_difference_const (@0, @1, &diff))
+ { build_int_cst_type (type, diff); }))))
+(simplify
+ (minus (convert @0) (convert ADDR_EXPR@1))
+ (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
+ (with { HOST_WIDE_INT diff; }
+ (if (ptr_difference_const (@0, @1, &diff))
+ { build_int_cst_type (type, diff); }))))
+
+
/* We can't reassociate at all for saturating types. */
(if (!TYPE_SATURATING (type))
@@ -1229,7 +1244,7 @@ along with GCC; see the file COPYING3. If not see
/* (X ^ Y) == Y becomes X == 0.
Likewise (X ^ Y) == X becomes Y == 0. */
(simplify
- (cmp (bit_xor:c @0 @1) @0)
+ (cmp:c (bit_xor:c @0 @1) @0)
(cmp @1 { build_zero_cst (TREE_TYPE (@1)); }))
/* (X ^ C1) op C2 can be rewritten as X op (C1 ^ C2). */