[gcc(refs/users/marxin/heads/marxin-gcc-benchmark-branch)] tree-optimization/93538 - add missing comparison folding case

Martin Liska marxin@gcc.gnu.org
Mon Mar 30 10:46:13 GMT 2020


https://gcc.gnu.org/g:5124c34fcc62f0f880ae947542678e28aa2ce703

commit 5124c34fcc62f0f880ae947542678e28aa2ce703
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Feb 4 15:17:01 2020 +0100

    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.

Diff:
---
 gcc/ChangeLog                               |  5 +++++
 gcc/match.pd                                | 33 +++++++++++++++++++----------
 gcc/testsuite/ChangeLog                     |  5 +++++
 gcc/testsuite/gcc.dg/tree-ssa/forwprop-38.c | 13 ++++++++++++
 4 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 04af96808f5..d6b5ded32a4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/match.pd b/gcc/match.pd
index 5fee394e7af..73834c25593 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 25e9595a6f6..7ce58af462b 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 00000000000..e016c825b3c
--- /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" } } */


More information about the Gcc-cvs mailing list