Skip to content

Statically sized vectors on the stack result in atrocious code gen at --opt-level=0 #4694

Closed
@alexrp

Description

@alexrp

A program like this:

fn main() -> () {
    let x = [0, .. 1024];
    io::println(fmt!("%?", x));
}

Results in code like (--opt-level=0):

4009b8:       48 c7 85 00 e0 ff ff    mov    QWORD PTR [rbp-0x2000],0x0
4009bf:       00 00 00 00 
4009c3:       48 c7 85 08 e0 ff ff    mov    QWORD PTR [rbp-0x1ff8],0x0
4009ca:       00 00 00 00 
4009ce:       48 c7 85 10 e0 ff ff    mov    QWORD PTR [rbp-0x1ff0],0x0
4009d5:       00 00 00 00 
4009d9:       48 c7 85 18 e0 ff ff    mov    QWORD PTR [rbp-0x1fe8],0x0
4009e0:       00 00 00 00 
4009e4:       48 c7 85 20 e0 ff ff    mov    QWORD PTR [rbp-0x1fe0],0x0
4009eb:       00 00 00 00 
4009ef:       48 c7 85 28 e0 ff ff    mov    QWORD PTR [rbp-0x1fd8],0x0
4009f6:       00 00 00 00 
; and so on...

But with--opt-level=3:

40308b:       4c 8d b5 68 df ff ff    lea    r14,[rbp-0x2098]
403092:       4c 89 f7                mov    rdi,r14
403095:       31 f6                   xor    esi,esi
403097:       ba 00 20 00 00          mov    edx,0x2000
40309c:       e8 2f fa ff ff          call   402ad0 <memset@plt>
; ...

Which is what we'd expect.

I know it probably doesn't matter /too/ much how bad the code gen is with no optimization on, but generating a load for every static vector element could result in some serious code explosion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationI-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions