3 ms·
LLVM (used by rustc) is perfectly capable of hoisting and eliminating subscript checks, although I believe rustc doesn't necessarily drive LLVM in the optimal w
by dbaupp 12y ago
LLVM (used by rustc) is perfectly capable of hoisting and eliminating subscript checks, although I believe rustc doesn't necessarily drive LLVM in the optimal way, yet: https://github.com/rust-lang/rust/issues/22987 https://github.com/rust-lang/rust/issues/22987
E.g. this has no bounds checks, and is in fact vectorised:
pub fn bad_sum(x: &[i32]) -> i32 {
let x = x; // *
let mut sum = 0;
for i in 0..x.len() {
sum += x[i]
}
sum
}
The line marked * is needed because of https://github.com/rust-lang/rust/issues/22924 https://github.com/rust-lang/rust/issues/22924 which is caused by https://llvm.org/bugs/show_bug.cgi?id=22786 https://llvm.org/bugs/show_bug.cgi?id=22786 .