https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91398
Bug ID: 91398
Summary: Possible missed optimization: Can a pointer be passed
as hidden pointer in x86-64 System V ABI
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
For the following example:
struct Vec3{
double x, y, z;
};
struct Vec3 do_something(void);
void use(struct Vec3 *restrict out){
*out = do_something();
}
The resulting assembly (-O2) is:
use:
pushq %rbx
movq %rdi, %rbx
subq $32, %rsp
movq %rsp, %rdi
call do_something
movdqu (%rsp), %xmm0
movq 16(%rsp), %rax
movups %xmm0, (%rbx)
movq %rax, 16(%rbx)
addq $32, %rsp
popq %rbx
ret
Here on godbolt: https://godbolt.org/z/kUPFox
However, as out is restrict, it could be passed as hidden pointer to
do_something, which would lead to the following assembler:
use:
jmp do_something ; %rdi is now the hidden pointer
So is it a missed optimization, or is there something in x86-64 System V ABI
that would forbid the above?