public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/115690] New: Strange codegen for small fixed-size `memcpy` when targeting `-march=i486`
@ 2024-06-27 21:06 arcata at gmail dot com
  2024-06-27 21:24 ` [Bug target/115690] " pinskia at gcc dot gnu.org
  2024-06-28  6:27 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: arcata at gmail dot com @ 2024-06-27 21:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115690
           Summary: Strange codegen for small fixed-size `memcpy` when
                    targeting `-march=i486`
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arcata at gmail dot com
  Target Milestone: ---

Given the following C code:

```
void *memcpy(void *a, const void *b, unsigned long c);

void foo(unsigned *x, unsigned *y) {
    memcpy(x, y, 16);
}
```

Using gcc 14.1, `gcc -m32 -march=i486 -O2` produces the following assembly:

```
foo:
        push    edi
        push    esi
        mov     ecx, DWORD PTR [esp+12]
        mov     esi, DWORD PTR [esp+16]
        mov     eax, DWORD PTR [esi]
        mov     DWORD PTR [ecx], eax
        mov     eax, DWORD PTR [esi+12]
        mov     DWORD PTR [ecx+12], eax
        lea     edi, [ecx+4]
        and     edi, -4
        sub     ecx, edi
        sub     esi, ecx
        add     ecx, 16
        shr     ecx, 2
        rep movsd
        pop     esi
        pop     edi
        ret
```

While not wrong, this seems suboptimal compared to either using `rep movsd` to
do the entire memcpy or breaking it down into four 32-bit loads and stores.
`-march=i386` does the former:

```
foo:
        push    edi
        push    esi
        mov     esi, DWORD PTR [esp+16]
        mov     ecx, 4
        mov     edi, DWORD PTR [esp+12]
        rep movsd
        pop     esi
        pop     edi
        ret
```

and `-march=i586` does the latter:

```
foo:
        mov     edx, DWORD PTR [esp+8]
        mov     eax, DWORD PTR [esp+4]
        mov     ecx, DWORD PTR [edx]
        mov     DWORD PTR [eax], ecx
        mov     ecx, DWORD PTR [edx+4]
        mov     DWORD PTR [eax+4], ecx
        mov     ecx, DWORD PTR [edx+8]
        mov     DWORD PTR [eax+8], ecx
        mov     edx, DWORD PTR [edx+12]
        mov     DWORD PTR [eax+12], edx
        ret
```

either of which seems like it would better suit the i486 microarchitecture than
the hybrid approach it seems to be taking.

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

* [Bug target/115690] Strange codegen for small fixed-size `memcpy` when targeting `-march=i486`
  2024-06-27 21:06 [Bug rtl-optimization/115690] New: Strange codegen for small fixed-size `memcpy` when targeting `-march=i486` arcata at gmail dot com
@ 2024-06-27 21:24 ` pinskia at gcc dot gnu.org
  2024-06-28  6:27 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-27 21:24 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |6.1.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
First off I am not sure if -march=i486 even is even tuned these days. Or even
why someone is trying to use it.
Especially considering this changed in GCC 7.

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

* [Bug target/115690] Strange codegen for small fixed-size `memcpy` when targeting `-march=i486`
  2024-06-27 21:06 [Bug rtl-optimization/115690] New: Strange codegen for small fixed-size `memcpy` when targeting `-march=i486` arcata at gmail dot com
  2024-06-27 21:24 ` [Bug target/115690] " pinskia at gcc dot gnu.org
@ 2024-06-28  6:27 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-28  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
looks like tuning picks an odd memcpy inline expansion choice.

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

end of thread, other threads:[~2024-06-28  6:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-27 21:06 [Bug rtl-optimization/115690] New: Strange codegen for small fixed-size `memcpy` when targeting `-march=i486` arcata at gmail dot com
2024-06-27 21:24 ` [Bug target/115690] " pinskia at gcc dot gnu.org
2024-06-28  6:27 ` rguenth 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).