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 <array> int foo(char *arr); int square(int num) { std::array<char,96> 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 call foo(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 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 a plain array. I also tested clang and in both cases it emits movaps instructions.