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

            Bug ID: 101920
           Summary: memcpy expansion treats unknown pointers as unaligned
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dragan.mladjenovic at syrmia dot com
  Target Milestone: ---

I guess it is easiest to observe this on Aarch64 with the following code:

#include <string.h>

void test (int *dst, int *src)
{
    (void)memcpy (dst, src, sizeof *src);
}


With -O1 -mno-strict-align we get:

        ldr     w1, [x1]
        str     w1, [x0]
        ret

With -O1 -mstrict-align we get:

        ldrb    w2, [x1]
        strb    w2, [x0]
        ldrb    w2, [x1, 1]
        strb    w2, [x0, 1]
        ldrb    w2, [x1, 2]
        strb    w2, [x0, 2]
        ldrb    w1, [x1, 3]
        strb    w1, [x0, 3]
        ret

Or with Os:

        mov     x2, 4
        b       memcpy

It seems that builtins.c:get_pointer_alignment finds empty SSA_NAME_PTR_INFO
for both pointers and defaults to 8-bit alignment. This can be worked around by
applying __builtin_assume_alligned to both src and dest.
  • [Bug middle-end/101920] ... dragan.mladjenovic at syrmia dot com via Gcc-bugs

Reply via email to