aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2020-02-04 15:17:01 +0100
committerRichard Biener <rguenther@suse.de>2020-02-04 15:18:25 +0100
commit5124c34fcc62f0f880ae947542678e28aa2ce703 (patch)
treeed149fabf769e532c99a6fe6f1eecad4cafc740f
parent9bc5bea1f3f0ce3927fd86ce728641d087f3d3b5 (diff)
downloadgcc-5124c34fcc62f0f880ae947542678e28aa2ce703.zip
gcc-5124c34fcc62f0f880ae947542678e28aa2ce703.tar.gz
gcc-5124c34fcc62f0f880ae947542678e28aa2ce703.tar.bz2
tree-optimization/93538 - add missing comparison folding case
This adds back a folding that worked in GCC 4.5 times by amending the pattern that handles other cases of address vs. SSA name comparisons. 2020-02-04 Richard Biener <rguenther@suse.de> PR tree-optimization/93538 * match.pd (addr EQ/NE ptr): Amend to handle &ptr->x EQ/NE ptr. * gcc.dg/tree-ssa/forwprop-38.c: New testcase.
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/match.pd33
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/forwprop-38.c13
4 files changed, 45 insertions, 11 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 04af968..d6b5ded 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
2020-02-04 Richard Biener <rguenther@suse.de>
+ PR tree-optimization/93538
+ * match.pd (addr EQ/NE ptr): Amend to handle &ptr->x EQ/NE ptr.
+
+2020-02-04 Richard Biener <rguenther@suse.de>
+
PR tree-optimization/91123
* tree-ssa-sccvn.c (vn_walk_cb_data::finish): New method.
(vn_walk_cb_data::last_vuse): New member.
diff --git a/gcc/match.pd b/gcc/match.pd
index 5fee394..73834c2 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4267,19 +4267,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
{ constant_boolean_node (above ? false : true, type); }))))))))))))
(for cmp (eq ne)
- /* A local variable can never be pointed to by
- the default SSA name of an incoming parameter.
- SSA names are canonicalized to 2nd place. */
(simplify
+ /* SSA names are canonicalized to 2nd place. */
(cmp addr@0 SSA_NAME@1)
- (if (SSA_NAME_IS_DEFAULT_DEF (@1)
- && TREE_CODE (SSA_NAME_VAR (@1)) == PARM_DECL)
- (with { tree base = get_base_address (TREE_OPERAND (@0, 0)); }
- (if (TREE_CODE (base) == VAR_DECL
- && auto_var_in_fn_p (base, current_function_decl))
- (if (cmp == NE_EXPR)
- { constant_boolean_node (true, type); }
- { constant_boolean_node (false, type); }))))))
+ (with
+ { poly_int64 off; tree base; }
+ /* A local variable can never be pointed to by
+ the default SSA name of an incoming parameter. */
+ (if (SSA_NAME_IS_DEFAULT_DEF (@1)
+ && TREE_CODE (SSA_NAME_VAR (@1)) == PARM_DECL
+ && (base = get_base_address (TREE_OPERAND (@0, 0)))
+ && TREE_CODE (base) == VAR_DECL
+ && auto_var_in_fn_p (base, current_function_decl))
+ (if (cmp == NE_EXPR)
+ { constant_boolean_node (true, type); }
+ { constant_boolean_node (false, type); })
+ /* If the address is based on @1 decide using the offset. */
+ (if ((base = get_addr_base_and_unit_offset (TREE_OPERAND (@0, 0), &off))
+ && TREE_CODE (base) == MEM_REF
+ && TREE_OPERAND (base, 0) == @1)
+ (with { off += mem_ref_offset (base).force_shwi (); }
+ (if (known_ne (off, 0))
+ { constant_boolean_node (cmp == NE_EXPR, type); }
+ (if (known_eq (off, 0))
+ { constant_boolean_node (cmp == EQ_EXPR, type); }))))))))
/* Equality compare simplifications from fold_binary */
(for cmp (eq ne)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 25e9595..7ce58af 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-04 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/93538
+ * gcc.dg/tree-ssa/forwprop-38.c: New testcase.
+
2020-02-04 Jakub Jelinek <jakub@redhat.com>
* c-c++-common/cpp/has-include-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-38.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-38.c
new file mode 100644
index 0000000..e016c82
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-38.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+struct A { int a[1]; };
+
+void f (struct A *p)
+{
+ void *q = p->a;
+ if (p != q)
+ __builtin_abort ();
+}
+
+/* { dg-final { scan-tree-dump-not "abort" "forwprop1" } } */