Skip to content

vec![None; 1024] randomly gets vectorized or not #106911

Closed
@frankdavid

Description

@frankdavid

I want to initialize a large Vec<Option<i32>> with None.

pub fn vec_none() -> Vec<Option<i32>> {
    vec![None; 1024]
}

Compiling with Rust 1.66 -C opt-level=3 -C target-cpu=skylake generates mov instructions.

However, after initializing with Some(...) the code gets vectorized as expected:

pub fn vec_some() -> Vec<Option<i32>> {
    vec![Some(42); 1024]
}

The generated assembly contains vmovups instructions.

Now, the weird thing is that if I have both functions in the same file, both get vectorized.

See this demonstration. As long asvec_some() is commented out, vec_none() is not vectorized. As soon as you remove the comment, both functions are vectorized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-slowIssue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions