rust-lang / rust-lang/portable-simd

Bounds check is not eliminated

Open
#356 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
1.1k
Forks
108
Avg merge
22h 53m
Merged PRs (30d)
3

Description

I tried this code:
Godbolt

#![feature(portable_simd)]
use std::simd::*;
pub fn increment(idx: Simd<u32, 8>, arr: &mut [u32]) {
    assert!(
        (arr.len() >= u32::MAX as usize)
            || idx.simd_lt(Simd::splat(arr.len() as u32)).all()
    );
    idx.as_array().iter().for_each(|i| arr[*i as usize] += 1);
}

I expected to see this happen: Bounds checks are eliminated and there is the vpcmpltd instruction

Instead, this happened: Bounds checks are not eliminated and a vpmaxud and vpcmpeqd pair is used

Meta

RUSTC_BOOTSTRAP=1 rustc --version --verbose:

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2

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 inline Rust reproducer in the issue or its Godbolt link, using rustc 1.70.0 with the shown optimization and target options. Compare the generated instructions with the expected vpcmpltd sequence; done means the bounds checks are eliminated rather than producing the reported vpmaxud and vpcmpeqd pair.

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.