rust-lang / rust-lang/rust

[ICE]: autodiff fails compiling gemm-f32 microkernel

Open
#160,635 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-autodiff I-ICE T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I have some code using the nightly autodiff feature, and compiling one of my dependencies (gemm-f32) fails with an ICE. With the help of an LLM I put together an MRE based on gemm-f32's fma x1x1 microkernel, which is below, compiled with:

CARGO_PROFILE_RELEASE_LTO=fat RUSTFLAGS='-Z autodiff=Enable' cargo +nightly test --release
Code
use core::arch::x86_64::{_mm256_fmadd_ps, _mm256_set1_ps};

const N: usize = 8;
type Pack = [f32; N];

unsafe fn splat(x: f32) -> Pack {
    unsafe { core::mem::transmute(_mm256_set1_ps(x)) }
}

unsafe fn mul_add(a: Pack, b: Pack, c: Pack) -> Pack {
    unsafe {
        core::mem::transmute(_mm256_fmadd_ps(
            core::mem::transmute(a),
            core::mem::transmute(b),
            core::mem::transmute(c),
        ))
    }
}

#[target_feature(enable = "fma")]
// Reduced from gemm-f32 0.19.0's FMA x1x1 microkernel.
// https://docs.rs/gemm-common/0.19.0/src/gemm_common/microkernel.rs.html#428-495
pub unsafe fn kernel(dst: *mut f32, lhs: *const f32, rhs: f32) {
    let mut storage = [[unsafe { splat(0.0) }; 1]; 1];
    let accum = storage.as_mut_ptr() as *mut Pack;
    #[derive(Copy, Clone)]
    struct KernelIter {
        lhs: *const f32,
        rhs: f32,
        accum: *mut Pack,
    }
    impl KernelIter {
        unsafe fn execute(self, i: usize) {
            unsafe {
                *self.accum = mul_add(
                    *(self.lhs.add(i * N) as *const Pack),
                    splat(self.rhs),
                    *self.accum,
                )
            }
        }
    }
    let iter = KernelIter { lhs, rhs, accum };
    unsafe {
        iter.execute(0);
        iter.execute(1)
    };
    unsafe { (dst as *mut Pack).write_unaligned(*accum) };
}
Meta

rustc +nightly --version --verbose:

rustc 1.99.0-nightly (7608eb7b0 2026-08-05)
binary: rustc
commit-hash: 7608eb7b07eaf93f16d7cf5bcb2098eca87503df
commit-date: 2026-08-05
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0
Error output
thread 'rustc' (1155723) panicked at /rustc-dev/7608eb7b07eaf93f16d7cf5bcb2098eca87503df/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:76:13:
assertion `left == right` failed
  left: [f32; AliasConst(No, Alias { kind: Anon { def_id: DefId(0:8 ~ diffsol_gemm_ice[9671]::Pack::{constant#0}) }, args: [], .. })]
 right: [f32; 8_usize]
stack backtrace:
   0:     0x76420d302f76 - <<std[1d42cb0d866aa333]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[4e7ceada952a6ea0]::fmt::Display>::fmt
   1:     0x76420da1114f - core[4e7ceada952a6ea0]::fmt::write
   2:     0x76420d317e9c - <std[1d42cb0d866aa333]::sys::stdio::unix::Stderr as core[4e7ceada952a6ea0]::io::write::Write>::write_fmt
   3:     0x76420d2d5d5a - std[1d42cb0d866aa333]::panicking::default_hook::{closure#0}
   4:     0x76420d2f6af3 - std[1d42cb0d866aa333]::panicking::default_hook
   5:     0x76420c240b9a - std[1d42cb0d866aa333]::panicking::update_hook::<alloc[571f99e20346f6ba]::boxed::Box<rustc_driver_impl[f766a19ff37a9559]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x76420d2f6f92 - std[1d42cb0d866aa333]::panicking::panic_with_hook
   7:     0x76420d2d5e12 - std[1d42cb0d866aa333]::panicking::panic_handler::{closure#0}
   8:     0x76420d2ccf79 - std[1d42cb0d866aa333]::sys::backtrace::__rust_end_short_backtrace::<std[1d42cb0d866aa333]::panicking::panic_handler::{closure#0}, !>
   9:     0x76420d2d77ed - __rustc[e79ffd21e4789ee5]::rust_begin_unwind
  10:     0x764209f40c7c - core[4e7ceada952a6ea0]::panicking::panic_fmt
  11:     0x76420bbd3e73 - core[4e7ceada952a6ea0]::panicking::assert_failed_inner
  12:     0x76420c809396 - core[4e7ceada952a6ea0]::panicking::assert_failed::<rustc_middle[760f81c9f8f0fdc5]::ty::Ty, rustc_middle[760f81c9f8f0fdc5]::ty::Ty>
  13:     0x76420e2d96df - <rustc_middle[760f81c9f8f0fdc5]::ty::context::TyCtxt>::struct_tail_for_codegen
  14:     0x76420c85b7a5 - rustc_middle[760f81c9f8f0fdc5]::ty::typetree::handle_indirection
  15:     0x76420c85c40e - rustc_middle[760f81c9f8f0fdc5]::ty::typetree::typetree_from_ty_impl_inner
  16:     0x76420c85c547 - rustc_middle[760f81c9f8f0fdc5]::ty::typetree::typetree_from_ty_impl_inner
  17:     0x76420df80f94 - <rustc_codegen_ssa[cfbee05c377dfbef]::mir::operand::OperandValue<&rustc_codegen_llvm[c56b079047732da9]::llvm::ffi::Value>>::store_with_flags::<rustc_codegen_llvm[c56b079047732da9]::builder::GenericBuilder<rustc_codegen_llvm[c56b079047732da9]::context::FullCx>>
  18:     0x76420df7fbd3 - <rustc_codegen_ssa[cfbee05c377dfbef]::mir::operand::OperandRef<&rustc_codegen_llvm[c56b079047732da9]::llvm::ffi::Value>>::store_with_annotation_and_flags::<rustc_codegen_llvm[c56b079047732da9]::builder::GenericBuilder<rustc_codegen_llvm[c56b079047732da9]::context::FullCx>>
  19:     0x76420ee78f65 - rustc_codegen_ssa[cfbee05c377dfbef]::mir::codegen_mir::<rustc_codegen_llvm[c56b079047732da9]::builder::GenericBuilder<rustc_codegen_llvm[c56b079047732da9]::context::FullCx>>
  20:     0x76420dfa190b - rustc_codegen_llvm[c56b079047732da9]::base::compile_codegen_unit::module_codegen
  21:     0x76420ea9a578 - <rustc_codegen_llvm[c56b079047732da9]::LlvmCodegenBackend as rustc_codegen_ssa[cfbee05c377dfbef]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  22:     0x76420ea9649a - rustc_codegen_ssa[cfbee05c377dfbef]::base::codegen_crate::<rustc_codegen_llvm[c56b079047732da9]::LlvmCodegenBackend, rustc_codegen_llvm[c56b079047732da9]::ModuleLlvm>
  23:     0x76420ea94eeb - <rustc_codegen_llvm[c56b079047732da9]::LlvmCodegenBackend as rustc_codegen_ssa[cfbee05c377dfbef]::traits::backend::CodegenBackend>::codegen_crate
  24:     0x76420ec70d25 - <rustc_interface[fcf9d59e9eac587f]::queries::Linker>::codegen_and_build_linker
  25:     0x76420ec686d5 - rustc_interface[fcf9d59e9eac587f]::interface::run_compiler::<(), rustc_driver_impl[f766a19ff37a9559]::run_compiler::{closure#0}>::{closure#2}
  26:     0x76420ec9a424 - std[1d42cb0d866aa333]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[fcf9d59e9eac587f]::util::run_in_thread_with_globals<rustc_interface[fcf9d59e9eac587f]::util::run_in_thread_pool_with_globals<rustc_interface[fcf9d59e9eac587f]::interface::run_compiler<(), rustc_driver_impl[f766a19ff37a9559]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27:     0x76420ec9a1ed - <std[1d42cb0d866aa333]::thread::lifecycle::spawn_unchecked<rustc_interface[fcf9d59e9eac587f]::util::run_in_thread_with_globals<rustc_interface[fcf9d59e9eac587f]::util::run_in_thread_pool_with_globals<rustc_interface[fcf9d59e9eac587f]::interface::run_compiler<(), rustc_driver_impl[f766a19ff37a9559]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[4e7ceada952a6ea0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x76420ec9733a - <std[1d42cb0d866aa333]::sys::thread::unix::Thread>::new::thread_start
  29:     0x76420828307a - start_thread
                               at ./nptl/pthread_create.c:454:8
  30:     0x764208316534 - clone
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:100:0
  31:                0x0 - <unknown>

error: the compiler unexpectedly panicked. This is a bug

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/mrobins/git/diffsol-gemm-ice/rustc-ice-2026-08-06T12_28_40-1155718.txt` to your bug report

note: rustc 1.99.0-nightly (7608eb7b0 2026-08-05) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C opt-level=3 -C linker-plugin-lto -C strip=debuginfo -Z autodiff=Enable

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `diffsol-gemm-ice` (lib)

Caused by:
  process didn't exit successfully: `/home/mrobins/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name diffsol_gemm_ice --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=135 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=b07a6737c808e529 -C extra-filename=-3e15a5b336437cad --out-dir /home/mrobins/git/diffsol-gemm-ice/target/release/build/diffsol-gemm-ice/3e15a5b336437cad/out -C strip=debuginfo -Z autodiff=Enable` (exit status: 101)

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 by reproducing the ICE from the provided MRE in src/lib.rs with the nightly toolchain and the shown cargo command. Inspect the panic at compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:76 and the attached rustc ICE log; done means the reproduction no longer causes rustc to panic and the test compiles successfully.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.