-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Closed
Labels
I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size 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
See https://godbolt.org/z/Kn7b7nTnd.
Basically, this function:
const A: [u8; 1024] = [0; 1024];
pub fn copy_const() {
f(A);
f(A);
}uses twice as much stack space as this function:
const A: [u8; 1024] = [0; 1024];
pub fn copy_local() {
let a = A;
f(a);
let b = A;
f(b);
}This happens because:
In copy_local, locals get lifetime markers (@llvm.lifetime.start/@llvm.lifetime.end, or StorageLive/StorageDead in MIR), so a and b can reuse the same stack slot.
In copy_const, the temporaries created to copy A to the stack before the call do not get lifetime markers, so the two calls use two separate stack slots.
@rustbot label T-compiler I-heavy
Metadata
Metadata
Assignees
Labels
I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size 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.