Noop loop is only optimized away when the range is half-open
Open
@veera-sivarajan is already working on this.
Since Dec 2, 2024.
A-codegen
A-LLVM
C-bug
C-optimization
I-heavy
I-slow
S-has-mcve
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#[no_mangle]
pub fn f() {
for _ in 0..=100 {
()
}
}
#[no_mangle]
pub fn g() {
for _ in 0..100 {
()
}
}
with -O gives
f:
xor ecx, ecx
mov eax, 100
.LBB0_1:
lea edx, [rcx + 1]
cmp ecx, 100
mov ecx, edx
cmovge ecx, eax
jge .LBB0_3
cmp ecx, 101
jl .LBB0_1
.LBB0_3:
ret
g:
ret
Meta
Exists in both 1.77 and nightly.
Backtrace
<backtrace>
@rustbot label +A-codegen +A-LLVM +C-optimization +I-slow +S-has-mcve +I-heavy +T-compiler -needs-triage
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.
Assessment
This issue has not been assessed yet.