https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91348
Bug ID: 91348 Summary: Missed optimization: not passing hidden pointer but copying memory Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: no...@turm-lahnstein.de Target Milestone: --- For the following example: struct Vec3{ double x, y, z; }; void vadd_v2(struct Vec3* a, struct Vec3* out); struct Vec3 use_v1(struct Vec3 *in){ struct Vec3 out; vadd_v2(in, &out); return out; } the resulting assembler (-O2 -Wall) is: use_v1: pushq %r12 movq %rdi, %r12 movq %rsi, %rdi subq $32, %rsp movq %rsp, %rsi call vadd_v2 movq 16(%rsp), %rax movdqa (%rsp), %xmm0 movq %rax, 16(%r12) movq %r12, %rax movups %xmm0, (%r12) addq $32, %rsp popq %r12 ret However, the hidden pointer could be passed directly into vadd_v2, which is what clang is doing: use_v1: # @use_v1 pushq %rbx movq %rdi, %rbx movq %rsi, %rdi movq %rbx, %rsi callq vadd_v2 movq %rbx, %rax popq %rbx retq See also https://godbolt.org/z/rT41Sj