https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113618
Bug ID: 113618 Summary: [14 Regression] AArch64: memmove idiom regression Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: wilco at gcc dot gnu.org Target Milestone: --- The following is often used as an idiom for memmove since GCC mid-end and most back-ends have no support for inlining memmove: void move64 (char *a, char *b) { char temp[64]; memcpy (temp, a, 64); memcpy (b, temp, 64); } On trunk this generates: ldp q30, q31, [x0] sub sp, sp, #64 ldp q28, q29, [x0, 32] stp q30, q31, [sp] ldp q30, q31, [sp] stp q28, q29, [sp, 32] ldp q28, q29, [sp, 32] stp q30, q31, [x1] stp q28, q29, [x1, 32] add sp, sp, 64 ret This is a significant regression from GCC13 which has redundant stores but avoids load-after-store forwarding penalties: ldp q2, q3, [x0] sub sp, sp, #64 ldp q0, q1, [x0, 32] stp q2, q3, [sp] stp q2, q3, [x1] stp q0, q1, [sp, 32] stp q0, q1, [x1, 32] add sp, sp, 64 ret LLVM avoids writing to the temporary and removes the stackframe altogether: ldp q1, q0, [x0, #32] ldp q2, q3, [x0] stp q1, q0, [x1, #32] stp q2, q3, [x1] ret The reason for the regression appears to be the changed RTL representation of LDP/STP. The RTL optimizer does not understand LDP/STP, so emitting LDP/STP early in memcpy expansion means it cannot remove the redundant stack stores. A possible fix would be to avoid emitting LDP/STP in memcpy/memmove/memset expansions.