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
* [Bug target/110247] suboptimal code about `no_caller_saved_registers` on caller side
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 ` pinskia at gcc dot gnu.org
2023-06-15 3:52 ` lh_mouse at 126 dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-14 16:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110247
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |documentation
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The way I read the documentation, it will NOT be used when dealing with calls
to that function but rather the function that has that attribute will save all
registers and restore them at the end.
And it is used only for calls from an interrupt handler (e.g. directly from
assembly). and even more you need to use -mgeneral-regs-only too.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/110247] suboptimal code about `no_caller_saved_registers` on caller side
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
1 sibling, 0 replies; 3+ messages in thread
From: lh_mouse at 126 dot com @ 2023-06-15 3:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110247
--- Comment #2 from LIU Hao <lh_mouse at 126 dot com> ---
(In reply to Andrew Pinski from comment #1)
> The way I read the documentation, it will NOT be used when dealing with
If it is known, then why shouldn't it?
One potential usecase where this would be helpful is `__errno_location()` in
GNU libc., and maybe `__emutls_get_address()`.
> And it is used only for calls from an interrupt handler (e.g. directly from
> assembly). and even more you need to use -mgeneral-regs-only too.
That function will be compiled with `-mgeneral-regs-only`, but callers need
not.
^ 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).