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

            Bug ID: 80933
           Summary: redundant bzero/bcopy calls not eliminated
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC eliminates redundant calls to memcpy, memmove, and memset, but it doesn't
do the same for redundant calls to bcopy and bzero.  The tree-ssa-dse.c pass
that performs the former optimization is missing any handling for the latter
pair of functions.

$ cat t.c && gcc -O2 -S -Wall -Wall -fdump-tree-optimized=/dev/stdout t.c
void sink (void*);

void f (void)
{
  char a[32];
  __builtin_memset (a, 0, sizeof a);
  __builtin_memset (a, 0, sizeof a);   // eliminated as expected
  sink (a);
}

void g (void)
{
  char a[33];
  __builtin_bzero (a, sizeof a);
  __builtin_memset (a, 0, sizeof a);   // not eliminated but could be
  sink (a);
}

void h (void)
{
  char a[33];
  __builtin_bzero (a, sizeof a);
  __builtin_bzero (a, sizeof a);   // not eliminated but could be
  sink (a);
}


;; Function f (f, funcdef_no=0, decl_uid=1795, cgraph_uid=0, symbol_order=0)

f ()
{
  char a[32];

  <bb 2> [100.00%]:
  __builtin_memset (&a, 0, 32);
  sink (&a);
  a ={v} {CLOBBER};
  return;

}



;; Function g (g, funcdef_no=1, decl_uid=1799, cgraph_uid=1, symbol_order=1)

g ()
{
  char a[33];

  <bb 2> [100.00%]:
  __builtin_bzero (&a, 33);
  __builtin_memset (&a, 0, 33);
  sink (&a);
  a ={v} {CLOBBER};
  return;

}



;; Function h (h, funcdef_no=2, decl_uid=1803, cgraph_uid=2, symbol_order=2)

h ()
{
  char a[33];

  <bb 2> [100.00%]:
  __builtin_bzero (&a, 33);
  __builtin_bzero (&a, 33);
  sink (&a);
  a ={v} {CLOBBER};
  return;

}

Reply via email to