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

            Bug ID: 93556
           Summary: lower mempcpy to memcpy when result is unused
           Product: gcc
           Version: 10.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 lowers calls to strpcpy whose result isn't used to strcpy, presumably
because the latter tends to be more efficient.  With pr90263 resolved, GCC also
expands some calls to mempcpy to memcpy on most targets, again because the
latter is almost always more efficient.  But when the result of the mempcpy
call is not used, the call could be transformed to memcpy unconditionally, on
all targets, including those like x86 where targetm.libc_has_fast_function
(BUILT_IN_MEMPCPY) returns true.

$ cat a.c && gcc -S -Wall -fdump-tree-lower=/dev/stdout a.c
void f0 (char *d, const char *s)
{
  __builtin_stpcpy (d, s);   // lowered to strcpy
}

void f1 (void *d, const void *s, __SIZE_TYPE__ n)
{
  __builtin_mempcpy (d, s, n);   // should be lowered to memcpy
}

;; Function f0 (f0, funcdef_no=0, decl_uid=1931, cgraph_uid=1, symbol_order=0)

f0 (char * d, const char * s)
{
  __builtin_strcpy (d, s);
  return;
}



;; Function f1 (f1, funcdef_no=1, decl_uid=1936, cgraph_uid=2, symbol_order=1)

f1 (void * d, const void * s, long unsigned int n)
{
  __builtin_mempcpy (d, s, n);
  return;
}

Reply via email to