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

Repeating an enum does not generate a memset #101685

Open
Nilstrieb opened this issue Sep 11, 2022 · 4 comments
Open

Repeating an enum does not generate a memset #101685

Nilstrieb opened this issue Sep 11, 2022 · 4 comments
Labels
A-codegen Area: Code generation C-bug Category: This is a bug.

Comments

@Nilstrieb
Copy link
Member

I tried this code: godbolt

pub fn create_array() -> [Option<u8>; 256] {
    [None; 256]
}

I expected to see this happen: This should compile to a memset, or the equivalent unrolled SIMD stores

LLVM IR

Instead, this happened: It compiles to a bunch of movs.

I think this happens because we transform this to a bunch of stores of the discriminant, without touching the data part of the option, making it impossible for LLVM to memset this. Ideally, we'd write 0 to the data part as well here, allowing this to use memset.

@Nilstrieb Nilstrieb added the C-bug Category: This is a bug. label Sep 11, 2022
@Nilstrieb
Copy link
Member Author

@rustbot label A-codegen

@rustbot rustbot added the A-codegen Area: Code generation label Sep 11, 2022
@danielrab
Copy link

there is also an issue which is probably related, where this doesn't get vectorized at all

pub fn create_array() -> [Result<u16, u8>; 512] {
    [Ok(0); 512] 
}

godbolt

@clubby789
Copy link
Contributor

clubby789 commented Sep 14, 2022

This regressed between nightly-2022-02-25 -> nightly-2022-02-26 (bisected to b7e5597)

@crlf0710
Copy link
Member

This works fine though.

#![feature(inline_const)]

pub fn create_array() -> [Result<u16, u8>; 512] {
    const { [Ok(0); 512] }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants