[Bug c++/108585] New: Using std::byte instead of char results in different (worse?) code in array zero initialization
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 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 callfoo(std::byte*) add rsp, 104 ret After swapping "std::byte" with "char" the result is: square(int): sub rsp, 104 pxorxmm0, 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 callfoo(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.
[Bug c++/108586] New: Using std::array instead of a plain array results in different (worse?) code in array zero initialization
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108586 Bug ID: 108586 Summary: Using std::array instead of a plain array 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 int foo(char *arr); int square(int num) { std::array arr = {}; return foo(arr.data()); } results in this: square(int): sub rsp, 104 xor eax, eax mov ecx, 12 mov rdi, rsp rep stosq mov rdi, rsp callfoo(char*) add rsp, 104 ret However, this very similar code: int foo(char *arr); int square(int num) { char arr[96] = {}; return foo(arr); } is compiled as: square(int): sub rsp, 104 pxorxmm0, 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 callfoo(char*) add rsp, 104 ret As you can see, SSE instructions are emitted only with a plain array. I also tested clang and in both cases it emits movaps instructions.