failed deinterleaving autovectorization
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
fn good(input_buffer: &mut [f32], buf: &[f32]) {
let (l, r) = input_buffer.split_at_mut(input_buffer.len() / 2);
buf.chunks_exact(2)
.zip(l.iter_mut().zip(r).map(<[_; _]>::from))
.for_each(|(buf, sample)| {
*sample[0] = buf[0];
*sample[1] = buf[1];
});
}
fn bad(input_buffer: &mut [f32], buf: &[f32]) {
let (l, r) = input_buffer.split_at_mut(input_buffer.len() / 2);
buf.iter()
.zip(l.iter_mut().zip(r).flat_map(<[_; _]>::from))
.for_each(|(buf, sample)| *sample = *buf);
}
I expected to see this happen: both versions compile to roughly the same code and are roughly the same speed.
Instead, this happened: good is successfully autovectorized, while bad isn't. I'm fairly sure there's no behavioral difference between the two, so the codegen difference seems odd.
Godbolt: https://godbolt.org/z/fohWsjEdr
Meta
rustc --version --verbose:
rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.7
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
Reproduce the good and bad functions from the issue with rustc 1.89.0, starting from the linked Godbolt example and comparing their generated code and vectorization. Done means the deinterleaved bad form receives equivalent autovectorization, or the code-generation difference is characterized and covered by an appropriate compiler test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100