Missing optimization: mempcpy(3) vs memcpy(3)

Cristian Rodríguez crrodriguez@opensuse.org
Mon Dec 12 14:57:36 GMT 2022


On Mon, Dec 12, 2022 at 11:35 AM Wilco Dijkstra via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Hi,
>
> I don't believe there is a missing optimization here: compilers expand mempcpy
> by default into memcpy since that is the standard library call. That means even
> if your source code contains mempcpy, there will never be any calls to mempcpy.
>
> The reason is obvious: most targets support optimized memcpy in the C library
> while very few optimize mempcpy. The same is true for bzero, bcmp and bcopy.
>
> Targets can do it differently, IIRC x86 is the only target that emits calls both to
> memcpy and mempcpy.

yeah, x86_64 at least uses both, but I think open coded mempcpy needs
to be transformed into a library call anyway.

Other optimizations that are actually missing are:

-  the cases where of snprintf %s could become memccpy

- open coded memccpy could also be turned into library calls.


More information about the Gcc mailing list