iter::zip changes vectorization behaviour even if value is unused
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#[inline(never)]
pub fn zipped(
slice_of_refs: &mut [&mut bool],
unused_slice: &mut [u8],
) {
for (unused, write_destination) in unused_slice
.iter_mut()
.zip(slice_of_refs) {
**write_destination = true;
}
}
#[inline(never)]
pub fn not_zipped(
slice_of_refs: &mut [&mut bool],
unused_slice: &mut [u8],
) {
for write_destination in slice_of_refs {
**write_destination = true;
}
}
I expected to see this happen: They compile to (approximately) the same assembly (Either both vectorized or both scalar).
Instead, this happened: Only the code which zips (but does not use) another slice is vectorized. (Caveat: so far I could only observe this with -target-cpu=alderlake set, and I am unsure whether vectorized or scalar operations would be considered the 'correct' result here)
Meta
rustc --version --verbose:
Full compiler version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1
Internal compiler ID: r1870
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 zipped and not_zipped functions from the issue in Godbolt with rustc 1.87.0, -C opt-level=3, and -C target-cpu=alderlake, then compare their generated assembly. No repository file or test is named; done means identifying why the unused zipped value changes vectorization and adding a focused regression test or fix in the relevant compiler area.
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