-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.