Rust 1.45+ generates suboptimal control flow for ARMv7 atomic compare exchange
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
I tried this code:
https://rust.godbolt.org/z/vP88v5GGc
I expected to see this happen:
A tight loop.
Instead, this happened:
In Rust 1.45 and later, LLVM generates a switch + unconditional branch to a conditional branch. This happens in opt-level=z, s, 1, 2, 3.
In some versions generates a dead branch, e.g.
mov r2, #0
cmp r2, #0
bne ... # If this branch is taken, hell has frozen over.
Version it worked on
It most recently worked on: 1.44
Version with regression
rustc --version --verbose:
rustc 1.79.0-nightly (0824b300e 2024-03-24)
binary: rustc
commit-hash: 0824b300eb0dae5d9ed59719d3f2732016683d66
commit-date: 2024-03-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
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 Compiler Explorer reproduction linked in the issue, comparing ARMv7 output from Rust 1.44 with 1.45 and later at the listed optimization levels. Trace the rustc/LLVM code-generation path for atomic compare exchange and identify the change responsible; done means the generated control flow no longer includes the reported unnecessary switch, branch, or dead branch.
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
- 35/100