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

--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, while strlen pass has laststmt and some handling of it for the other
direction, shrinking of the memcpy etc. size if the nul byte is being
immediately overwritten, it is actually tree DSE which optimizes:

struct S { int a; char b[]; };

void
foo (struct S *p)
{
  __builtin_memcpy (p->b, "abc", 4);
  p->b[3] = ' ';
}

void
bar (struct S *p)
{
  __builtin_memcpy (p->b, "abc", 4);
  p->a = 3;
  p->b[3] = ' ';
}
into just memcpy with 3 instead of 4 (of course, a question is if it is
actually a win for this exact size, because memcpy of 4 can be done by a 32-bit
store of a constant while of 3 needs 16-bit plus 8-bit store.

Reply via email to