Skip to content

copied().min() performance regression on nightly #140207

Open
@DaniPopes

Description

@DaniPopes

Code

I tried this code (godbolt, from this video):

#[no_mangle]
pub fn f(a: &[u16; 8]) -> u16 {
    a.iter().copied().min().unwrap()
}

I expected to see this happen: compiles to vphminposuw x86 instruction (+avx feature)

Instead, this happened: compiles to unrolled cmp + cmov

Note that a manual min loop is unaffected, even with the slice iterator:

#[no_mangle]
pub fn f(a: &[u16; 8]) -> u16 {
    let mut min = u16::MAX;
    for &x in a {
        if x < min {
            min = x;
        }
    }
    min
}

Version it worked on

It most recently worked on: 1.86

Version with regression

rustc --version --verbose:

rustc 1.88.0-nightly (6bc57c6bf 2025-04-22)
binary: rustc
commit-hash: 6bc57c6bf7d0024ad9ea5a2c112f3fc9c383c8a4
commit-date: 2025-04-22
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged


searched nightlies: from nightly-2025-02-15 to nightly-2025-04-23
regressed nightly: nightly-2025-04-16
searched commit range: 2da29db...38c560a
regressed commit: 58c2dd9

Weirdly: #139745 cc @thaliaarchi

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start 1.86.0 -vv --without-cargo --script ./asm.sh 

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.P-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions