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.