Skip to content

Crash on an i128 accumulation loop at -C opt-level=3 with AVX2 #164298

Closed

Description

@zxt5

Compiler Explorer: https://godbolt.org/z/3nPG3e51e

small.rs

pub fn f(count: u16, seed: u8, q: i8) -> i128 {
    let mut score: i128 = -1;
    for k in 0..(count as usize).min(16) {
        match k % 8 {
            0 => {
                if (k as u16).is_power_of_two() {
                    match (q.rem_euclid(3), matches!(count, 17..=21 | 26)) {
                        (0, true) => {}
                        _ => score += k as i128 + i128::from(q),
                    }
                }
            }
            _ => score = score.wrapping_add(seed as i128 + 1198),
        }
    }
    score
}

Reproduce:

Correct:

$ rustc --edition 2024 --crate-type=lib -C opt-level=2 -C target-cpu=x86-64-v3 small.rs

Crash:

$ rustc --edition 2024 --crate-type=lib -C opt-level=3 -C target-cpu=x86-64-v3 small.rs

ReplaceNodeResults: t62: v1i128 = X86ISD::VSHLI t67, TargetConstant:i8<1>
Do not know how to custom type legalize this operation!
UNREACHABLE executed at /data/x27zhou/compiler-nightly/src/rust/src/llvm-project/llvm/lib/Target/X86/X86ISelLowering.cpp:34649!

Stable 1.99.0 dies with SIGILL on the same command; 1.98.0 compiles it. The LLVM bug is llvm/llvm-project#228829, fixed on LLVM main by llvm/llvm-project#228840, which is not in Rust's LLVM yet.

Meta

rustc --version --verbose:

rustc 1.101.0-nightly (91e426a05 2026-10-13)
binary: rustc
commit-hash: 91e426a0518d5bb3672330c5238ccda6fd26fb54
commit-date: 2026-10-13
host: x86_64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.3

Activity

  1. added
    needs-triage
    on Oct 14, 2026
  2. added
    A-LLVM
    T-compiler
    llvm-fixed-upstream
    I-miscompile
    on Oct 14, 2026
  3. added
    I-prioritize
    on Oct 14, 2026
  4. added
    C-bug
    and removed
    needs-triage
    on Oct 14, 2026
  5. nikic commented on Oct 14, 2026

    @nikic
    Contributor

    I assume that this is a fuzzer generated issue? If so, please do mention that in the PR description (also for all your other issues).

  6. added a commit that references this issue on Oct 22, 2026
  7. removed
    I-prioritize
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMC-bugI-miscompileT-compilerllvm-fixed-upstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions