-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-nrvoFixed by the Named Return Value Opt. (NRVO)Fixed by the Named Return Value Opt. (NRVO)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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
This is similar to #56356 except this time with more fields:
use std::mem;
struct SV {
capacity: usize,
disc: usize,
data: [usize; 40],
}
impl SV {
fn new() -> SV {
SV { data: unsafe { mem::uninitialized() },
disc: 0,
capacity: 0 }
}
}
pub struct L {
a: SV,
b: SV
}
pub struct Allocation<T> {
f: *mut T,
}
impl<T> Allocation<T> {
pub fn init(self, value: T) {
use std::ptr;
unsafe {
ptr::write(self.f, value);
}
}
}
#[inline(never)]
pub fn foo(a: Allocation<L>) {
a.init(L {
a: SV::new(),
b: SV::new()
});
}
gives:
example::foo:
sub rsp, 680
xorps xmm0, xmm0
movaps xmmword ptr [rsp], xmm0
movaps xmmword ptr [rsp + 336], xmm0
mov rsi, rsp
mov edx, 672
call qword ptr [rip + memcpy@GOTPCREL]
add rsp, 680
ret
vs moving capacity to the end of the struct:
example::foo:
mov qword ptr [rdi], 0
xorps xmm0, xmm0
movups xmmword ptr [rdi + 328], xmm0
mov qword ptr [rdi + 664], 0
ret
The problem is reproducible with C++ so I'll file a new llvm bug too.
hellow554 and LifeIsStrange
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-nrvoFixed by the Named Return Value Opt. (NRVO)Fixed by the Named Return Value Opt. (NRVO)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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.