https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123458
Bug ID: 123458
Summary: Suboptimal assembly when passing a pointer and size to
a function having a span-like parameter
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: boris.staletic at protonmail dot com
Target Milestone: ---
Not sure if I have picked the right component.
With a C source looking like this:
```
struct span {
int p;
int size;
};
void f(struct span);
void g(int p, int size) { return f((struct span){p, size}); }
```
On x86_64-pc-linux-gnu target, at least on linux, `g()` can just be `jmp f`,
but "gcc -O3 -fcf-protection=none" produces
```
g:
.LFB0:
.cfi_startproc
xchgq %rdi, %rsi
movq %rsi, %rax
movq %rdi, %rsi
movq %rax, %rdi
jmp f@PLT
.cfi_endproc
```
And if I use "-Oz", I get an amusing
```
g:
.LFB0:
.cfi_startproc
xchgq %rdi, %rsi
xchgq %rdi, %rsi
jmp f@PLT
.cfi_endproc
```
As a side note, according to compiler explorer, other architectures might be
affected, but I'm not as familiar with other calling conventions.