3 ms·
FWIW, the original link in the article shows that the panic_bounds_check check is present in optimised code in Rust 1.55, but if you update to a more recent Rus
by DougBTX 4y ago
FWIW, the original link in the article shows that the panic_bounds_check check is present in optimised code in Rust 1.55, but if you update to a more recent Rust, say 1.60, then it is optimised away as expected:
example::mid:
test rsi, rsi
je .LBB0_1
and rsi, -2
mov edx, dword ptr [rdi + 2*rsi]
mov eax, 1
ret
.LBB0_1:
xor eax, eax
ret
https://rust.godbolt.org/z/Wz4Prjed4 https://rust.godbolt.org/z/Wz4Prjed4
- tialaramex 4y agoInteresting, do you know how this is achieved? Is there a Rust optimization that notices logically this type of construction is always in-bounds and so the bounds check is never emitted, or is the LLVM bounds check smarter now and realises hey, my parameter is never out of bounds, so no need to emit code here ?