public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108585] New: Using std::byte instead of char results in different (worse?) code in array zero initialization
@ 2023-01-28 23:16 technicallyanonymous at proton dot me
  2023-01-28 23:28 ` [Bug target/108585] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: technicallyanonymous at proton dot me @ 2023-01-28 23:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108585
           Summary: Using std::byte instead of char results in different
                    (worse?) code in array zero initialization
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: technicallyanonymous at proton dot me
  Target Milestone: ---

This code, compiled with GCC 12.2 (-O2 -std=c++20)

#include <cstddef>

int foo(std::byte *arr);

int square(int num) {
    std::byte arr[96] = {};
    return foo(arr);
}

results in this:

square(int):
        sub     rsp, 104
        xor     eax, eax
        mov     ecx, 12
        mov     rdi, rsp
        rep stosq
        mov     rdi, rsp
        call    foo(std::byte*)
        add     rsp, 104
        ret

After swapping "std::byte" with "char" the result is:

square(int):
        sub     rsp, 104
        pxor    xmm0, xmm0
        mov     rdi, rsp
        movaps  XMMWORD PTR [rsp], xmm0
        movaps  XMMWORD PTR [rsp+16], xmm0
        movaps  XMMWORD PTR [rsp+32], xmm0
        movaps  XMMWORD PTR [rsp+48], xmm0
        movaps  XMMWORD PTR [rsp+64], xmm0
        movaps  XMMWORD PTR [rsp+80], xmm0
        call    foo(char*)
        add     rsp, 104
        ret

As you can see, SSE instructions are emitted only with an char array. BTW, in
clang, both versions are identical and use movaps.

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

end of thread, other threads:[~2023-01-28 23:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-28 23:16 [Bug c++/108585] New: Using std::byte instead of char results in different (worse?) code in array zero initialization technicallyanonymous at proton dot me
2023-01-28 23:28 ` [Bug target/108585] " pinskia at gcc dot gnu.org
2023-01-28 23:29 ` pinskia at gcc dot gnu.org
2023-01-28 23:34 ` pinskia at gcc dot gnu.org
2023-01-28 23:39 ` [Bug target/108585] memset uses SSE stores but afterwards does not but if used "" will use them pinskia at gcc dot gnu.org
2023-01-28 23:41 ` pinskia 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).