rust-lang / rust-lang/rust

Rustc fails to perform autovectorization for a loop when targeting aarch64-apple-darwin

Open
#117,345 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-autovectorization A-LLVM C-optimization I-slow O-AArch64 T-compiler
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.