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

            Bug ID: 88709
           Summary: Improve store-merging
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

As shown in:
struct S { char buf[8]; };
void bar (struct S *);

void
foo (void)
{
  struct S s = {};
  s.buf[1] = 1;
  s.buf[3] = 2;
  bar (&s);
}

or

struct val_t
{
  char data[16];
};

void optimize_me (val_t);
void optimize_me3 (val_t, val_t, val_t);

void
good ()
{
  optimize_me ({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
}

void
bad ()
{
  optimize_me ({ 1, 2, 3, 4, 5 });
}

void
why ()
{
  optimize_me ({ 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
}

void
srsly ()
{
  optimize_me3 ({ 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 11, 12, 13, 14, 15, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10 },
                { 21, 22, 23, 24, 25, 20, 20, 20, 10, 20, 20, 20, 20, 20, 20
});
}

void
srsly_not_one_missing ()
{
  optimize_me3 ({ 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 11, 12, 13, 14, 15, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10 },
                { 21, 22, 23, 24, 25, 20, 20, 20, 10, 20, 20, 20, 20, 20, 20,
11 });
}

there is room for improvement in store-merging.  In the first testcase, we
ignore the clearing because !lhs_valid_for_store_merging_p, the lhs is in that
case the whole VAR_DECL rather than a component of it.  And in the second
testcase, we sometimes punt because of the same reason, sometimes because
rhs_valid_for_store_merging_p is false.  Handling these = {} storage clearings
(or perhaps even __builtin_memset calls) is something we could handle, though
with extra care, we don't want to take apart those clears if it doesn't reduce
the amount of needed stores.

Reply via email to