This re-instantiates the patch I had to revert earlier, doing it in
a safer way.  We record the original ref so we can do an additional
disambiguation during vn_reference_lookup_3.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2019-07-08  Richard Biener  <rguent...@suse.de>

        * tree-ssa-sccvn.c (struct vn_walk_cb_data): Add orig_ref member.
        (vn_reference_lookup_3): If the main ref has no access path recorded
        but orig_ref has use it to do access-path based disambiguation.
        (vn_reference_lookup_pieces): Adjust.
        (vn_reference_lookup): Pass down original ref if we valueized.

        * gcc.dg/tree-ssa/alias-access-path-1.c: Scan fre1 dump.
        * gcc.dg/tree-ssa/alias-access-path-2.c: Likewise.
        * gcc.dg/tree-ssa/alias-access-path-8.c: Likewise.

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c        (revision 273232)
+++ gcc/tree-ssa-sccvn.c        (working copy)
@@ -1670,15 +1670,18 @@ struct pd_data
 
 struct vn_walk_cb_data
 {
-  vn_walk_cb_data (vn_reference_t vr_, tree *last_vuse_ptr_,
+  vn_walk_cb_data (vn_reference_t vr_, tree orig_ref_, tree *last_vuse_ptr_,
                   vn_lookup_kind vn_walk_kind_, bool tbaa_p_)
-    : vr (vr_), last_vuse_ptr (last_vuse_ptr_), vn_walk_kind (vn_walk_kind_),
-      tbaa_p (tbaa_p_), known_ranges (NULL)
-   {}
+    : vr (vr_), last_vuse_ptr (last_vuse_ptr_),
+      vn_walk_kind (vn_walk_kind_), tbaa_p (tbaa_p_), known_ranges (NULL)
+   {
+     ao_ref_init (&orig_ref, orig_ref_);
+   }
   ~vn_walk_cb_data ();
   void *push_partial_def (const pd_data& pd, tree, HOST_WIDE_INT);
 
   vn_reference_t vr;
+  ao_ref orig_ref;
   tree *last_vuse_ptr;
   vn_lookup_kind vn_walk_kind;
   bool tbaa_p;
@@ -2246,6 +2249,28 @@ vn_reference_lookup_3 (ao_ref *ref, tree
          lhs_ref_ok = true;
        }
 
+      /* Besides valueizing the LHS we can also use access-path based
+         disambiguation on the original non-valueized ref.  */
+      if (!ref->ref
+         && lhs_ref_ok
+         && data->orig_ref.ref)
+       {
+         /* We want to use the non-valueized LHS for this, but avoid redundant
+            work.  */
+         ao_ref *lref = &lhs_ref;
+         ao_ref lref_alt;
+         if (valueized_anything)
+           {
+             ao_ref_init (&lref_alt, lhs);
+             lref = &lref_alt;
+           }
+         if (!refs_may_alias_p_1 (&data->orig_ref, lref, data->tbaa_p))
+           {
+             *disambiguate_only = true;
+             return NULL;
+           }
+       }
+
       /* If we reach a clobbering statement try to skip it and see if
          we find a VN result with exactly the same value as the
         possible clobber.  In this case we can ignore the clobber
@@ -2983,7 +3008,7 @@ vn_reference_lookup_pieces (tree vuse, a
     {
       ao_ref r;
       unsigned limit = PARAM_VALUE (PARAM_SCCVN_MAX_ALIAS_QUERIES_PER_ACCESS);
-      vn_walk_cb_data data (&vr1, NULL, kind, true);
+      vn_walk_cb_data data (&vr1, NULL_TREE, NULL, kind, true);
       if (ao_ref_init_from_vn_reference (&r, set, type, vr1.operands))
        *vnresult =
          (vn_reference_t)walk_non_aliased_vuses (&r, vr1.vuse, true,
@@ -3040,7 +3065,8 @@ vn_reference_lookup (tree op, tree vuse,
          || !ao_ref_init_from_vn_reference (&r, vr1.set, vr1.type,
                                             vr1.operands))
        ao_ref_init (&r, op);
-      vn_walk_cb_data data (&vr1, last_vuse_ptr, kind, tbaa_p);
+      vn_walk_cb_data data (&vr1, r.ref ? NULL_TREE : op,
+                           last_vuse_ptr, kind, tbaa_p);
       wvnresult =
        (vn_reference_t)walk_non_aliased_vuses (&r, vr1.vuse, tbaa_p,
                                                vn_reference_lookup_2,
Index: gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-1.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-1.c (revision 273232)
+++ gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-1.c (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-fre3" } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
 struct foo
 {
   int val;
@@ -18,4 +18,4 @@ test ()
   return barptr->val2;
 }
 
-/* { dg-final { scan-tree-dump-times "return 123" 1 "fre3"} } */
+/* { dg-final { scan-tree-dump-times "return 123" 1 "fre1"} } */
Index: gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-2.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-2.c (revision 273232)
+++ gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-2.c (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-fre3" } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
 struct a {
   int val;
 };
@@ -19,4 +19,4 @@ test (int i, int j, int k, int l)
   dptr->c.b[k].a2[l].val=2;
   return cptr->b[i].a[j].val;
 }
-/* { dg-final { scan-tree-dump-times "return 123" 1 "fre3"} } */
+/* { dg-final { scan-tree-dump-times "return 123" 1 "fre1"} } */
Index: gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-8.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-8.c (revision 273232)
+++ gcc/testsuite/gcc.dg/tree-ssa/alias-access-path-8.c (working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-fre3" } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
 struct a {
   int val;
 };
@@ -18,4 +18,4 @@ test (int i, int j, int k, int l)
   cptr2->b[k].a2[l].val=2;
   return cptr->b[i].a[j].val;
 }
-/* { dg-final { scan-tree-dump-times "return 123" 1 "fre3"} } */
+/* { dg-final { scan-tree-dump-times "return 123" 1 "fre1"} } */

Reply via email to