https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91123

            Bug ID: 91123
           Summary: [10 Regression] no longer removes redundant store
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

Since r273135 FRE no longer removes the redundant store in

struct X { int i; int j; };

struct X x, y;
void foo ()
{
  x.i = 1;
  y = x;
  y.i = 1; // redundant
}

which is because of

static void *
vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
                       bool *disambiguate_only)
{     
...
  /* 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)
    return (void *)-1;

I have added this check because we're doing

      val = vn_reference_lookup (lhs, gimple_vuse (stmt), VN_WALKREWRITE,
                                 &vnresult, false);
...
          /* We can only remove the later store if the former aliases
             at least all accesses the later one does or if the store
             was to readonly memory storing the same value.  */
          alias_set_type set = get_alias_set (lhs);
          if (! vnresult
              || vnresult->set == set
              || alias_set_subset_of (set, vnresult->set))

and vn_reference_lookup_3 inserts expressions (vnresult) using the
lookup alias-set but here we're looking for the dynamic type before
the store we're looking up.

Reply via email to