-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missed bounds check elimination #127553
Comments
@rustbot label +A-codegen +C-optimization +T-compiler +I-slow -needs-triage |
From a quick glance at the IR it looks like the bounds checks exist for both in MIR but get removed before the IR, so maybe mir opts gets one but not the other? Cc @rust-lang/wg-mir-opt if somebody wants to take a closer look. |
The bounds checks of @rustbot label +A-LLVM |
May I point that the code shown is summing upto index 0 but not index 0, which I think is the reason why there's a bound check. |
Why would that cause a bounds check? It should be trivial for the compiler to prove that |
I'm saying that a break after the index update is causing a bound check // This code is equivalent to the first snippet
// And also causes a bound check instruction to be present in the assembly
loop {
sum += v[i];
i -= 1;
if i == 0 {
break;
}
} where as, a break before the index update is not causing a bound check loop {
sum += v[i];
if i == 0 {
break;
}
i -= 1;
} |
On Rust 1.79.0.
https://godbolt.org/z/xxjKd5anW
The compiler should be able to elide the bounds check for
v[i]
sincei
is always in [0, v.len()-1].The text was updated successfully, but these errors were encountered: