public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113618] New: [14 Regression] AArch64: memmove idiom regression
@ 2024-01-26 14:49 wilco at gcc dot gnu.org
  2024-01-26 15:05 ` [Bug target/113618] " acoplan at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: wilco at gcc dot gnu.org @ 2024-01-26 14:49 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-13 14:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-26 14:49 [Bug target/113618] New: [14 Regression] AArch64: memmove idiom regression wilco at gcc dot gnu.org
2024-01-26 15:05 ` [Bug target/113618] " acoplan at gcc dot gnu.org
2024-01-26 16:51 ` pinskia at gcc dot gnu.org
2024-01-29  7:55 ` rguenth at gcc dot gnu.org
2024-01-29 11:51 ` wilco at gcc dot gnu.org
2024-01-31 16:58 ` wilco at gcc dot gnu.org
2024-03-07 20:44 ` law at gcc dot gnu.org
2024-03-07 21:25 ` cvs-commit at gcc dot gnu.org
2024-03-13 14:36 ` wilco at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).