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

            Bug ID: 90262
           Summary: Inline small constant memmoves
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wilco at gcc dot gnu.org
  Target Milestone: ---

GCC does not inline fixed-size memmoves. However memmove can be as easily
inlined as memcpy. The existing memcpy infrastructure could be reused/expanded
for this - all loads would be emitted first, followed by the stores. Large
memmoves could be inlined on targets with vector registers. Targets without
vector registers could emit an overlap check and use inlined memcpy for the no
overlap case.

void copy(int *p, int *q)
{
  __builtin_memcpy(p, q, 24);
}

void move(int *p, int *q)
{
  __builtin_memmove(p, q, 24);
}

copy:
        ldp     x2, x3, [x1]
        stp     x2, x3, [x0]
        ldr     x1, [x1, 16]
        str     x1, [x0, 16]
        ret

move:
        mov     x2, 24
        b       memmove

The memmove could be expanded using the same number of registers:

        ldp     x2, x3, [x1]
        ldr     x1, [x1, 16]
        stp     x2, x3, [x0]
        str     x1, [x0, 16]

Reply via email to