[Bug tree-optimization/88709] Improve store-merging

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 7 11:34:00 GMT 2019


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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, especially with large constructors, unlike other overlapping stores it
might not be feasible to merge the large clearing or memset with the other
stores, but still it might be possible to merge several later stores using info
on what we know has been stored in the gaps in between.
So, say:
struct S { char a[16]; };

void
foo (void)
{
  struct S s = {};
  s.a[3] = 1; // We don't want to bump this into a larger store unless we can
  // eliminate the whole 16 byte initialization through it (still, in this case
  // it is likely beneficial, but we should see what would that = {} be
expanded
  // to, depending on can_store_by_pieces etc.
  bar (&s);
}

struct T { char a[1024]; };

void
foo (void)
{
  struct T t = {};
  t.a[54] = 1;
  t.a[52] = 2;  // But we can using the info that t = {} cleared the whole
  // var merge these two stores, not using unnecessary masking etc. because
  // we know what the gaps will contain and can even extend the store
  // on either side or both to find optimal store size
  bar (&s);
}


More information about the Gcc-bugs mailing list