public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/110247] New: suboptimal code about `no_caller_saved_registers` on caller side
@ 2023-06-14 6:49 lh_mouse at 126 dot com
2023-06-14 16:53 ` [Bug target/110247] " pinskia at gcc dot gnu.org
2023-06-15 3:52 ` lh_mouse at 126 dot com
0 siblings, 2 replies; 3+ messages in thread
From: lh_mouse at 126 dot com @ 2023-06-14 6:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110247
Bug ID: 110247
Summary: suboptimal code about `no_caller_saved_registers` on
caller side
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: lh_mouse at 126 dot com
Target Milestone: ---
Given:
(https://gcc.godbolt.org/z/xevzx56Y5)
```
int complex(int x, int y)
__attribute__((__no_caller_saved_registers__));
int test(int x, int y, int z)
{
return complex(x, y) + complex(y, z) + complex(z, x);
}
```
My understanding is that `__no_caller_saved_registers__` says no register will
be clobbered by `complex`, so it is not necessary for GCC to establish a stack
frame and push arguments there. This is gonna help a lot if the function will
be inlined.
Clang generates much better assembly but I wonder whether it is valid to assume
that arguments registers are also preserved, like
```
test:
push rcx ; align %rsp
; %edi := x, %esi = y, %edx = z
call complex ;
mov ecx, eax ; %ecx = complex(x, y)
xchg edi, esi ; %edi = y
xchg esi, edx ; %esi = z, %edx = x
call complex ;
add ecx, eax ; %ecx += complex(y, z)
mov edi, esi ; %edi = z
mov esi, edx ; %esi = x
call complex ;
add eax, ecx ; %eax = %ecx + complex(z, x)
pop rcx
ret
```
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-15 3:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 6:49 [Bug target/110247] New: suboptimal code about `no_caller_saved_registers` on caller side lh_mouse at 126 dot com
2023-06-14 16:53 ` [Bug target/110247] " pinskia at gcc dot gnu.org
2023-06-15 3:52 ` lh_mouse at 126 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).