[PATCH] Fix PR91756

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Fix PR91756

Richard Biener

The following makes the fix for PR87132 less constrained so we can use
the recently added facility for VN disambiguation agains the original
ref tree.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2019-09-16  Richard Biener  <[hidden email]>

        PR tree-optimization/91756
        PR tree-optimization/87132
        * tree-ssa-alias.h (enum translate_flags): New.
        (get_continuation_for_phi): Use it instead of simple bool flag.
        (walk_non_aliased_vuses): Likewise.
        * tree-ssa-alias.c (maybe_skip_until): Adjust.
        (get_continuation_for_phi): When looking across backedges only
        disallow valueization.
        (walk_non_aliased_vuses): Adjust.
        * tree-ssa-sccvn.c (vn_reference_lookup_3): Avoid valueization
        if requested.

        * gcc.dg/tree-ssa/ssa-fre-81.c: New testcase.

Index: gcc/tree-ssa-alias.c
===================================================================
--- gcc/tree-ssa-alias.c (revision 275746)
+++ gcc/tree-ssa-alias.c (working copy)
@@ -3150,7 +3150,8 @@ static bool
 maybe_skip_until (gimple *phi, tree &target, basic_block target_bb,
   ao_ref *ref, tree vuse, bool tbaa_p, unsigned int &limit,
   bitmap *visited, bool abort_on_visited,
-  void *(*translate)(ao_ref *, tree, void *, bool *),
+  void *(*translate)(ao_ref *, tree, void *, translate_flags *),
+  translate_flags disambiguate_only,
   void *data)
 {
   basic_block bb = gimple_bb (phi);
@@ -3185,7 +3186,7 @@ maybe_skip_until (gimple *phi, tree &tar
     return !abort_on_visited;
   vuse = get_continuation_for_phi (def_stmt, ref, tbaa_p, limit,
    visited, abort_on_visited,
-   translate, data);
+   translate, data, disambiguate_only);
   if (!vuse)
     return false;
   continue;
@@ -3200,9 +3201,9 @@ maybe_skip_until (gimple *phi, tree &tar
   --limit;
   if (stmt_may_clobber_ref_p_1 (def_stmt, ref, tbaa_p))
     {
-      bool disambiguate_only = true;
+      translate_flags tf = disambiguate_only;
       if (translate
-  && (*translate) (ref, vuse, data, &disambiguate_only) == NULL)
+  && (*translate) (ref, vuse, data, &tf) == NULL)
  ;
       else
  return false;
@@ -3233,8 +3234,10 @@ tree
 get_continuation_for_phi (gimple *phi, ao_ref *ref, bool tbaa_p,
   unsigned int &limit, bitmap *visited,
   bool abort_on_visited,
-  void *(*translate)(ao_ref *, tree, void *, bool *),
-  void *data)
+  void *(*translate)(ao_ref *, tree, void *,
+     translate_flags *),
+  void *data,
+  translate_flags disambiguate_only)
 {
   unsigned nargs = gimple_phi_num_args (phi);
 
@@ -3276,13 +3279,15 @@ get_continuation_for_phi (gimple *phi, a
       else if (! maybe_skip_until (phi, arg0, dom, ref, arg1, tbaa_p,
    limit, visited,
    abort_on_visited,
-   /* Do not translate when walking over
+   translate,
+   /* Do not valueize when walking over
       backedges.  */
    dominated_by_p
      (CDI_DOMINATORS,
       gimple_bb (SSA_NAME_DEF_STMT (arg1)),
       phi_bb)
-   ? NULL : translate, data))
+   ? TR_DISAMBIGUATE
+   : disambiguate_only, data))
  return NULL_TREE;
     }
 
@@ -3320,7 +3325,8 @@ get_continuation_for_phi (gimple *phi, a
 void *
 walk_non_aliased_vuses (ao_ref *ref, tree vuse, bool tbaa_p,
  void *(*walker)(ao_ref *, tree, void *),
- void *(*translate)(ao_ref *, tree, void *, bool *),
+ void *(*translate)(ao_ref *, tree, void *,
+   translate_flags *),
  tree (*valueize)(tree),
  unsigned &limit, void *data)
 {
@@ -3373,7 +3379,7 @@ walk_non_aliased_vuses (ao_ref *ref, tre
     {
       if (!translate)
  break;
-      bool disambiguate_only = false;
+      translate_flags disambiguate_only = TR_TRANSLATE;
       res = (*translate) (ref, vuse, data, &disambiguate_only);
       /* Failed lookup and translation.  */
       if (res == (void *)-1)
@@ -3385,7 +3391,7 @@ walk_non_aliased_vuses (ao_ref *ref, tre
       else if (res != NULL)
  break;
       /* Translation succeeded, continue walking.  */
-      translated = translated || !disambiguate_only;
+      translated = translated || disambiguate_only == TR_TRANSLATE;
     }
   vuse = gimple_vuse (def_stmt);
  }
Index: gcc/tree-ssa-alias.h
===================================================================
--- gcc/tree-ssa-alias.h (revision 275746)
+++ gcc/tree-ssa-alias.h (working copy)
@@ -132,13 +132,18 @@ extern bool call_may_clobber_ref_p (gcal
 extern bool call_may_clobber_ref_p_1 (gcall *, ao_ref *);
 extern bool stmt_kills_ref_p (gimple *, tree);
 extern bool stmt_kills_ref_p (gimple *, ao_ref *);
+enum translate_flags
+  { TR_TRANSLATE, TR_VALUEIZE_AND_DISAMBIGUATE, TR_DISAMBIGUATE };
 extern tree get_continuation_for_phi (gimple *, ao_ref *, bool,
       unsigned int &, bitmap *, bool,
-      void *(*)(ao_ref *, tree, void *, bool *),
-      void *);
+      void *(*)(ao_ref *, tree, void *,
+ translate_flags *),
+      void *, translate_flags
+        = TR_VALUEIZE_AND_DISAMBIGUATE);
 extern void *walk_non_aliased_vuses (ao_ref *, tree, bool,
      void *(*)(ao_ref *, tree, void *),
-     void *(*)(ao_ref *, tree, void *, bool *),
+     void *(*)(ao_ref *, tree, void *,
+       translate_flags *),
      tree (*)(tree), unsigned &, void *);
 extern int walk_aliased_vdefs (ao_ref *, tree,
        bool (*)(ao_ref *, tree, void *),
Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c (revision 275746)
+++ gcc/tree-ssa-sccvn.c (working copy)
@@ -2189,7 +2252,7 @@ adjust_offsets_for_equal_base_address (t
 
 static void *
 vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
-       bool *disambiguate_only)
+       translate_flags *disambiguate_only)
 {
   vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
   vn_reference_t vr = data->vr;
@@ -2210,8 +2273,11 @@ vn_reference_lookup_3 (ao_ref *ref, tree
       lhs_ops.truncate (0);
       basic_block saved_rpo_bb = vn_context_bb;
       vn_context_bb = gimple_bb (def_stmt);
-      copy_reference_ops_from_ref (lhs, &lhs_ops);
-      lhs_ops = valueize_refs_1 (lhs_ops, &valueized_anything, true);
+      if (*disambiguate_only <= TR_VALUEIZE_AND_DISAMBIGUATE)
+ {
+  copy_reference_ops_from_ref (lhs, &lhs_ops);
+  lhs_ops = valueize_refs_1 (lhs_ops, &valueized_anything, true);
+ }
       vn_context_bb = saved_rpo_bb;
       if (valueized_anything)
  {
@@ -2221,7 +2287,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
   if (lhs_ref_ok
       && !refs_may_alias_p_1 (ref, &lhs_ref, data->tbaa_p))
     {
-      *disambiguate_only = true;
+      *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE;
       return NULL;
     }
  }
@@ -2248,7 +2314,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree
     }
   if (!refs_may_alias_p_1 (&data->orig_ref, lref, data->tbaa_p))
     {
-      *disambiguate_only = true;
+      *disambiguate_only = (valueized_anything
+    ? TR_VALUEIZE_AND_DISAMBIGUATE
+    : TR_DISAMBIGUATE);
       return NULL;
     }
  }
@@ -2290,7 +2358,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree
     }
  }
     }
-  else if (gimple_call_builtin_p (def_stmt, BUILT_IN_NORMAL)
+  else if (*disambiguate_only <= TR_VALUEIZE_AND_DISAMBIGUATE
+   && gimple_call_builtin_p (def_stmt, BUILT_IN_NORMAL)
    && gimple_call_num_args (def_stmt) <= 4)
     {
       /* For builtin calls valueize its arguments and call the
@@ -2319,7 +2388,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
     gimple_call_set_arg (def_stmt, i, oldargs[i]);
   if (!res)
     {
-      *disambiguate_only = true;
+      *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE;
       return NULL;
     }
  }
@@ -2327,7 +2396,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
 
   /* If we are looking for redundant stores do not create new hashtable
      entries from aliasing defs with made up alias-sets.  */
-  if (*disambiguate_only || !data->tbaa_p)
+  if (*disambiguate_only > TR_TRANSLATE || !data->tbaa_p)
     return (void *)-1;
 
   /* If we cannot constrain the size of the reference we cannot

Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-81.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-81.c (nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-81.c (working copy)
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-fre1-details" } */
+
+struct a
+{
+  int foo,bar;
+};
+struct b
+{
+  struct a a[10];
+};
+struct b b, *bptr=&b, *bptr2=&b;
+int j;
+int i;
+int n=1;
+
+int
+main ()
+{
+  int jj=j;
+  bptr2->a[jj].bar = 0;
+  for (int i=0; i<n; i++)
+    bptr->a[i].foo=1;
+  if (!__builtin_constant_p (bptr2->a[jj].bar == 0))
+    __builtin_abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "Replaced __builtin_constant_p \\\(\[^)\]*\\\) with 1" "fre1" } } */