Closed
Description
With this lib.rs
pub struct S([i64; 2]);
pub fn foo(create: fn() -> S) -> S {
create()
}
pub fn bar(create: fn() -> S) -> S {
let s = create();
s
}
rustc lib.rs --crate-type lib -C opt-level=3 --emit=asm
produces this lib.s (cleaned up)
foo:
pushq %rbx
movq %rdi, %rbx
callq *%rsi
movq %rbx, %rax
popq %rbx
retq
bar:
pushq %rbx
subq $16, %rsp
movq %rdi, %rbx
movq %rsp, %rdi
callq *%rsi
movups (%rsp), %xmm0
movups %xmm0, (%rbx)
movq %rbx, %rax
addq $16, %rsp
popq %rbx
retq
The assembly for bar
should not be longer than the assembly for foo
.
This is similar to #42870. I don't know if it's a duplicate or just similar.