Optimization regression: array argument somehow produces null check?
Open
Nobody has claimed this yet.
A-ABI
A-codegen
A-LLVM
C-optimization
I-slow
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#[no_mangle]
pub fn f1(v: [&mut usize; 1]) {
for x in v {
*x += 1;
}
}
Results in:
f1:
test rdi, rdi
je .LBB0_2
inc qword ptr [rdi]
.LBB0_2:
ret
Rust's semantics don't allow v to ever be NULL! I don't know where the test rdi, rdi is coming from!
This regressed between 1.78 and 1.79.
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 by reproducing the minimal Rust example and comparing its generated assembly on Rust 1.78 and 1.79 using the linked Rust Compiler Explorer case. Trace the regression through the compiler output to determine why the null check appears. Done means the unnecessary check is removed without changing the function's behavior or safety semantics.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100