[Bug target/110247] New: suboptimal code about `no_caller_saved_registers` on caller side
lh_mouse at 126 dot com
gcc-bugzilla@gcc.gnu.org
Wed Jun 14 06:49:00 GMT 2023
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
```
More information about the Gcc-bugs
mailing list