Skip to content

Nest array initialization is not optimized #58625

Description

@upsuper

See the following code:

pub fn foo() -> [[i32; 1000]; 1000] {
    [[0; 1000]; 1000]
}

pub fn bar() -> [i32; 1_000_000] {
    [0; 1_000_000]
}

Ideally they should generate the same code as [[i32; 1000]; 1000] is essentially just [i32; 1_000_000]. However, the first function does one memset to set a [i32; 1000] on the stack, then use memcpy to generate the big array, while the second just uses a single memset.

The code generated from the first is way larger than the second, and I would also expect it to be much slower given its repeatedly invoking memcpy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.WG-llvmWorking group: LLVM backend code generation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions