Skip to content

[ICE]: std::autodiff regression in integer slice-length argument #160470

Open

Description

@GermanHeim

Hello, in the last nightly version of Enzyme, it rejects an integer slice-length argument while canonicalizing LLVM IR.
See the MWE below.

Code

#![feature(autodiff)]

use std::autodiff::autodiff_reverse;

#[autodiff_reverse(d_eval, Const, Duplicated, Duplicated)]
#[inline(never)]
fn eval(ops: &[u32], x: &[f64], output: &mut [f64]) {
    output[0] = f64::from(ops[0]) * x[0];
}

fn main() {
    let ops = [1_u32];
    let x = [4.0];
    let mut x_shadow = [0.0];
    let mut output = [0.0];
    let mut output_shadow = [1.0];

    d_eval(&ops, &x, &mut x_shadow, &mut output, &mut output_shadow);

    assert_eq!(x_shadow, [1.0]);
}

Using:

inherits = "release"
lto = "fat"
codegen-units = 16

The program should exit successfully after checking that the derivative is 1.0.
Actual nightly 2026-08-01:

bad enzyme_type {[0]:Integer} RegSize=0 I: call void @diffe_...(ptr ..., i64 ...)
rustc-LLVM ERROR: Canonicalization failed

It works fine in rustc 1.99.0-nightly (dc3f85158 2026-07-26) with the enzyme component, using the same command and profile.

Meta (failing)

rustc --version --verbose:

rustc 1.99.0-nightly (ad3d0bc14 2026-07-31)
binary: rustc
commit-hash: ad3d0bc141a02cf446e384136d250a1f6950fed5
commit-date: 2026-07-31
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Activity

  1. added
    I-ICE
    T-compiler
    C-bug
    on Aug 3, 2026
  2. added
    needs-triage
    on Aug 3, 2026
  3. added a commit that references this issue on Aug 3, 2026
  4. ZuseZ4 commented on Aug 4, 2026

    @ZuseZ4
    Member

    Can you please add the actual command you're running, and maybe the OS? I'm unable to reproduce it with
    RUSTFLAGS="-Z autodiff=Enable" cargo +nightly-2026-08-01 run

    ➜  bar git:(main) ✗ rustc +nightly-2026-08-01 --version --verbose
    rustc 1.99.0-nightly (ad3d0bc14 2026-07-31)
    binary: rustc
    commit-hash: ad3d0bc141a02cf446e384136d250a1f6950fed5
    commit-date: 2026-07-31
    host: x86_64-unknown-linux-gnu
    release: 1.99.0-nightly
    LLVM version: 22.1.8
    
  5. ZuseZ4 commented on Aug 4, 2026

    @ZuseZ4
    Member

    I feel like that' s been an issue that Enzyme fixed in the past. Do you by chance have older nightly toolchains with Enzyme that you could delete? Also, can you delete and re-install enzyme (and run cargo clean)

  6. added
    F-autodiff
    and removed
    needs-triage
    on Aug 4, 2026
  7. GermanHeim commented on Aug 4, 2026

    @GermanHeim
    Author

    Huh, I just retried the MWE and it is compiling fine (I didn't reinstall enzyme).
    I am not sure what happened or whether I did something wrong.

    oximo is still failing in main with 2026-08-01, while rustc 1.99.0-nightly (dc3f85158 2026-07-26) does fine:

    RUSTFLAGS="-Z autodiff=Enable" cargo +nightly test-2026-08-01 --features enzyme --profile enzyme
    

    Here my CI was failing:
    oximo-rs/oximo@40e5c43

    Switching toolchain versions worked fine:
    oximo-rs/oximo@0d74ae1

    I will try to create another MWE or try to find what I was doing differently.

    Edit: I am using Fedora 44 KDE Linux 7.1.5-201.fc44.x86_64

  8. ZuseZ4 commented on Aug 4, 2026

    @ZuseZ4
    Member

    You're the second person today running into this issue with outdated toolchain. Let's see if more people encounter it, and if yes what we can do about it.

    I'm not sure what's the difference from nightly to Master, but it sounds like you now have a working solution everywhere?

  9. GermanHeim commented on Aug 4, 2026

    @GermanHeim
    Author

    I mean, if I just do nightly with oximo, it fails. Both CI and locally. I am not sure why it works with master and with the older toolchain and not with latest.

    If you try to run oximo, do you get incorrect autodiff typetree handling for slice: [u8]?

    Edit:
    Just to add more context, creating a rust-toolchain.toml in oximo with:

    [toolchain]
    channel = "nightly-2026-07-26"
    components = ["enzyme"]

    Makes oximo-autodiff work. Switching to channel = "nightly-2026-08-02" ICEs.

    ping @ZuseZ4 because of edit.

  10. ZuseZ4 commented on Aug 5, 2026

    @ZuseZ4
    Member

    Huh, I just retried the MWE and it is compiling fine (I didn't reinstall enzyme).

    But if you still can't compile your main application, I guess something just went wrong while creating the MWE, right? Can you try again and update the MWE, once you find some time?

  11. GermanHeim commented on Aug 5, 2026

    @GermanHeim
    Author

    I updated the MWE to match what is in oximo:

    #![feature(autodiff)]
    
    use std::autodiff::{autodiff_forward, autodiff_reverse};
    
    #[autodiff_reverse(
        d_eval,
        Const,
        Const,
        Const,
        Const,
        Const,
        Const,
        Duplicated,
        Const,
        Const,
        Duplicated,
        Duplicated
    )]
    #[inline(never)]
    fn eval(
        ops: &[u32],
        a: &[u32],
        b: &[u32],
        consts: &[f64],
        lin_vars: &[u32],
        lin_coeffs: &[f64],
        x: &[f64],
        params: &[f64],
        mults: &[f64],
        regs: &mut [f64],
        out: &mut [f64],
    ) {
        let _ = (a, b, lin_vars, lin_coeffs, params, regs);
        out[0] = consts[0] + f64::from(ops[0]) * x[0] + mults[0];
    }
    
    #[autodiff_forward(
        hvp_eval,
        Const,
        Const,
        Const,
        Const,
        Const,
        Const,
        Dual,
        Const,
        Const,
        Dual,
        Dual,
        Dual,
        Dual,
        Dual
    )]
    #[inline(never)]
    fn grad(
        ops: &[u32],
        a: &[u32],
        b: &[u32],
        consts: &[f64],
        lin_vars: &[u32],
        lin_coeffs: &[f64],
        x: &[f64],
        params: &[f64],
        mults: &[f64],
        regs: &mut [f64],
        dregs: &mut [f64],
        out: &mut [f64],
        dout: &mut [f64],
        grad_out: &mut [f64],
    ) {
        grad_out.fill(0.0);
        dregs.fill(0.0);
        dout[0] = 1.0;
        d_eval(
            ops, a, b, consts, lin_vars, lin_coeffs, x, grad_out, params, mults, regs, dregs, out,
            dout,
        );
    }
    
    fn main() {
        let ops = [1_u32];
        let empty_u32: [u32; 0] = [];
        let consts = [2.0];
        let empty_f64: [f64; 0] = [];
        let x = [4.0];
        let dx = [1.0];
        let mults = [0.0];
        let mut regs = [0.0];
        let mut regs_t = [0.0];
        let mut dregs = [0.0];
        let mut dregs_t = [0.0];
        let mut out = [0.0];
        let mut out_t = [0.0];
        let mut dout = [0.0];
        let mut dout_t = [0.0];
        let mut grad_out = [0.0];
        let mut grad_t = [0.0];
        let mut hess_out = [0.0];
        hvp_eval(
            &ops,
            &empty_u32,
            &empty_u32,
            &consts,
            &empty_u32,
            &empty_f64,
            &x,
            &dx,
            &empty_f64,
            &mults,
            &mut regs,
            &mut regs_t,
            &mut dregs,
            &mut dregs_t,
            &mut out,
            &mut out_t,
            &mut dout,
            &mut dout_t,
            &mut grad_out,
            &mut grad_t,
        );
        println!("{grad_out:?} {grad_t:?}");
    }

    Cargo.toml:

    [package]
    name = "enzyme-mwe"
    version = "0.1.0"
    edition = "2024"
    
    [dependencies]
    
    [profile.enzyme]
    inherits = "release"
    lto = "fat"
    codegen-units = 16
    

    Reproducing commands:

    • Passing: RUSTFLAGS='-Zautodiff=Enable' cargo +nightly-2026-07-26 run --profile enzyme
    • Failing: RUSTFLAGS='-Zautodiff=Enable' cargo +nightly-2026-08-01 run --profile enzyme

    Output passing:

    germanheim@german:~/Desktop/enzyme-mwe$ RUSTFLAGS='-Zautodiff=Enable' cargo +nightly-2026-07-26 run --profile enzyme
    warning: variable does not need to be mutable
      --> src/main.rs:98:9
       |
    98 |     let mut hess_out = [0.0];
       |         ----^^^^^^^^
       |         |
       |         help: remove this `mut`
       |
       = note: `#[warn(unused_mut)]` (part of `#[warn(unused)]`) on by default
    
    warning: unused variable: `hess_out`
      --> src/main.rs:98:9
       |
    98 |     let mut hess_out = [0.0];
       |         ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_hess_out`
       |
       = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
    
    warning: `enzyme-mwe` (bin "enzyme-mwe") generated 2 warnings (run `cargo fix --bin "enzyme-mwe" -p enzyme-mwe` to apply 2 suggestions)
        Finished `enzyme` profile [optimized] target(s) in 0.03s
         Running `target/enzyme/enzyme-mwe`
    [1.0] [0.0]

    Output failing:

    germanheim@german:~/Desktop/enzyme-mwe$ RUSTFLAGS='-Zautodiff=Enable' cargo +nightly-2026-08-01 run --profile enzyme
       Compiling enzyme-mwe v0.1.0 (/home/germanheim/Desktop/enzyme-mwe)
    warning: variable does not need to be mutable
      --> src/main.rs:98:9
       |
    98 |     let mut hess_out = [0.0];
       |         ----^^^^^^^^
       |         |
       |         help: remove this `mut`
       |
       = note: `#[warn(unused_mut)]` (part of `#[warn(unused)]`) on by default
    
    warning: unused variable: `hess_out`
      --> src/main.rs:98:9
       |
    98 |     let mut hess_out = [0.0];
       |         ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_hess_out`
       |
       = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
    
     bad enzyme_type {[0]:Integer} RegSize=0 I:  call void @diffe_RNvCs7uBthmQWLUV_10enzyme_mwe4eval(ptr %0, i64 %1, ptr %2, i64 %3, ptr %4, i64 %5, ptr %6, i64 %7, ptr %8, i64 %9, ptr %10, i64 %11, ptr %12, ptr %14, i64 %13, ptr %15, i64 %16, ptr %17, i64 %18, ptr %19, ptr %21, i64 %20, ptr %22, ptr %24, i64 %23)
    rustc-LLVM ERROR: Canonicalization failed
    warning: `enzyme-mwe` (bin "enzyme-mwe") generated 2 warnings (run `cargo fix --bin "enzyme-mwe" -p enzyme-mwe` to apply 2 suggestions)
    error: could not compile `enzyme-mwe` (bin "enzyme-mwe"); 2 warnings emitted
    
    Caused by:
      process didn't exit successfully: `/home/germanheim/.rustup/toolchains/nightly-2026-08-01-x86_64-unknown-linux-gnu/bin/rustc --crate-name enzyme_mwe --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=157 --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto=fat -C codegen-units=16 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=b0d55cd2f28d1ae6 --out-dir /home/germanheim/Desktop/enzyme-mwe/target/enzyme/build/enzyme-mwe/19d2faeaf4ed04ba/out -C strip=debuginfo -Zautodiff=Enable` (exit status: 101)
  12. GermanHeim commented on Oct 11, 2026

    @GermanHeim
    Author

    Hey @ZuseZ4,

    The original MWE now passes using the nightly-2026-10-11 toolchain. I believe this was fixed by EnzymeAD/Enzyme#3272.
    However, oximo-autodiff's CI is still failing on the latest nightly. It looks like passing [(1_u64, &42_u64)] by value to black_box triggers a crash when -Zautodiff=Enable is set, even without any active autodiff functions.

    Should we close this issue and open a new one?

  13. added 2 commits that reference this issue on Oct 27, 2026
  14. added a commit that references this issue on Oct 28, 2026
  15. ZuseZ4 commented on Oct 28, 2026

    @ZuseZ4
    Member

    @GermanHeim Can you retry again tomorrow? Enzyme just landed a fix which should be in the next nightly. But yeah, if its happening even without autodiff calls it's likely a different bug, so a new issue would be good.

  16. GermanHeim commented on Nov 1, 2026

    @GermanHeim
    Author

    Hi @ZuseZ4,

    I just tried it. The original MWE passes on latest nightly. However, there is the other issue I mentioned.
    Whenever I use std::hint::black_box on an array of (integer, reference) tuples, with no autodiff attributes or dependencies, it aborts on native and WASM (TypeTree.h).

    This should fail:

    fn main() {
        std::hint::black_box([(1_u64, &42_u64)]);
    }

    Using:

    rustc +nightly -Zautodiff=Enable main.rs
    

    And also RUSTFLAGS='-Zautodiff=Enable' cargo +nightly run --profile enzyme (release optimization, fat LTO, and 16 codegen units).

    July 26 nightly passes.

    Should I open a new issue?
    (I can easily move to using a vector, but this should be fixed)

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

    C-bugF-autodiffI-ICET-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions