Closed
Description
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.