Missed bounds check elimination
Open
Nobody has claimed this yet.
A-codegen
A-LLVM
C-bug
C-optimization
I-slow
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
On Rust 1.79.0.
pub const fn missing_bce(v: &[u32]) -> u32 {
if v.is_empty() {
return 0;
}
let mut sum = 0;
let mut i = v.len() - 1;
while i > 0 {
sum += v[i];
i -= 1;
}
sum
}
https://godbolt.org/z/xxjKd5anW
The compiler should be able to elide the bounds check for v[i] since i is always in [0, v.len()-1].
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Rust 1.79.0 reproducer in the issue and inspect its generated assembly on the linked Godbolt example. Confirm where the bounds check remains and compare behavior across compiler versions or optimization settings. Done means the check is eliminated for this pattern, with a regression test covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100