Rustc fails to perform autovectorization for a loop when targeting aarch64-apple-darwin
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
const N: usize = 4096;
#[inline(never)]
pub fn example_fn(xs: &[u64; N], ys: &[u64; N], res: &mut [u64; N]) {
for i in 0..N {
res[i] = xs[i] + ys[i];
}
}
I expected to see VADD in resulting assembly but unfortunately instead it uses just adds:
add z0.d, z4.d, z0.d
add z1.d, z5.d, z1.d
add z2.d, z6.d, z2.d
add z3.d, z7.d, z3.d
Link to godbolt: https://godbolt.org/z/YWhT5GqxW
Just for reference I would expect it to mirror x86 SSE: https://godbolt.org/z/z5Pf3G17e
I think rustc should be able to perform autovectorization without additional hints/features enabled and use VADD in the loop.
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 reproducer and inspect the aarch64-apple-darwin output in the linked Godbolt example, comparing it with the x86 SSE example. Trace the rustc compilation path responsible for loop autovectorization and verify the generated assembly. Done means this loop is autovectorized for the reported target without additional hints or features.
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