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
* [Bug target/108585] Using std::byte instead of char results in different (worse?) code in array zero initialization
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 ` pinskia at gcc dot gnu.org
2023-01-28 23:29 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-28 23:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108585
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2023-01-28
Status|UNCONFIRMED |NEW
Component|c++ |target
Target| |x86_64-linux-gnu
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
aarch64 produces the same code generation for both std::byte and char so this
is a target issue.
Confirmed.
std::byte:
arr = {};
vs char:
arr = "";
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/108585] Using std::byte instead of char results in different (worse?) code in array zero initialization
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-28 23:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108585
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108586 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/108585] Using std::byte instead of char results in different (worse?) code in array zero initialization
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
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-28 23:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108585
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
#include <cstddef>
int foo(char *arr);
int square(int num) {
char arr[96];
__builtin_memset(arr, 0, sizeof(arr));
return foo(arr);
}
Also produces the rep stosq rather than the SSE stores.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/108585] memset uses SSE stores but afterwards does not but if used "" will use them
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
` (2 preceding siblings ...)
2023-01-28 23:34 ` pinskia at gcc dot gnu.org
@ 2023-01-28 23:39 ` pinskia at gcc dot gnu.org
2023-01-28 23:41 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-28 23:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108585
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Using std::byte instead of |memset uses SSE stores but
|char results in different |afterwards does not but if
|(worse?) code in array zero |used "" will use them
|initialization |
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The size is up to 80 they are the same afterwards they become different ...
But this is still a target issue ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/108585] memset uses SSE stores but afterwards does not but if used "" will use them
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
` (3 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-28 23:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108585
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
"" will start to use the rep at 64*8 ...
^ 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).