Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporaries used for indirectly-passed const arguments should get lifetime markers #98156

Closed
erikdesjardins opened this issue Jun 16, 2022 · 1 comment · Fixed by #98377
Closed
Assignees
Labels
I-heavy Issue: Problems and improvements with respect to binary size of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@erikdesjardins
Copy link
Contributor

erikdesjardins commented Jun 16, 2022

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

@rustbot rustbot added I-heavy Issue: Problems and improvements with respect to binary size of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 16, 2022
@davidv1992
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-heavy Issue: Problems and improvements with respect to binary size of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants