rust-lang / rust-lang/rust

Significantly worse codegen for SIMD shuffles after Rust 1.73.0

Open
#129,132 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM C-optimization E-needs-test I-slow P-medium regression-untriaged
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

See https://godbolt.org/z/jKczKPMMe.

The code is the following:

use std::arch::x86_64::*;

#[no_mangle]
pub unsafe fn custom_shuffle(x: __m128i) -> __m128i {
    let mut tmp1 = _mm_unpacklo_epi8(x, _mm_setzero_si128());
    tmp1 = _mm_shuffle_epi32::<78>(tmp1);
    tmp1 = _mm_shufflelo_epi16::<27>(tmp1);
    tmp1 = _mm_shufflehi_epi16::<27>(tmp1);

    let mut tmp2 = _mm_unpackhi_epi8(x, _mm_setzero_si128());
    tmp2 = _mm_shuffle_epi32::<78>(tmp2);
    tmp2 = _mm_shufflelo_epi16::<27>(tmp2);
    tmp2 = _mm_shufflehi_epi16::<27>(tmp2);

    _mm_packus_epi16(tmp2, tmp1)
}

The regression happened between Rust 1.72.0 and Rust 1.73.0.

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 linked Godbolt example and compare the generated code from Rust 1.72.0 and 1.73.0 for the provided SIMD shuffle function. Trace the compiler codegen path responsible for these operations and identify the change that introduced the regression. Done means the example no longer produces significantly worse code than in Rust 1.72.0, with a regression test covering the behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.