public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113269] New: X86_64 generates extra mov (and xchg) when passing struct with constant value to function
@ 2024-01-08 11:29 denis.campredon at gmail dot com
0 siblings, 0 replies; only message in thread
From: denis.campredon at gmail dot com @ 2024-01-08 11:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113269
Bug ID: 113269
Summary: X86_64 generates extra mov (and xchg) when passing
struct with constant value to function
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: denis.campredon at gmail dot com
Target Milestone: ---
On today's trunk, compiled with g++
---------------
typedef struct s{
char *key, *value;
}s;
s *search(s);
s *find(char *word)
{
return search((s){.key = word});
}
s *find2(char *word)
{
s a = {.key = word, .value = 0};
return search(a);
}
----------------
compiled with -O2 produces a useless mov instruction in each function :
----------------------
find(char*):
xor edx, edx
mov rsi, rdx
jmp search(s)
find2(char*):
xor edx, edx
mov rsi, rdx
jmp search(s)
----------------------
compiled with -Oz, a useless mov and two useless xchg instructions are
produced.
-----------------------
find(char*):
xchg rdi, rax
xor edx, edx
xchg rax, rdi
mov rsi, rdx
jmp search(s)
find2(char*):
xchg rdi, rax
xor edx, edx
xchg rax, rdi
mov rsi, rdx
jmp search(s)
------------------------
If the code is compiled with gcc, the mov instruction is not generated for
find2.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-08 11:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-08 11:29 [Bug target/113269] New: X86_64 generates extra mov (and xchg) when passing struct with constant value to function denis.campredon at gmail dot com
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).