Skip to content

Repeating an enum does not generate a memset  #101685

Open
@Noratrieb

Description

@Noratrieb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions