EnzymeAD / EnzymeAD/Enzyme

assertion cast<Ty>() argument of incompatible type!

Open
#3,128 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
LLVM
Stars
1.7k
Forks
188
Avg merge
1d 22h
Merged PRs (30d)
26

Description

https://tinyurl.com/27srmb39
```llvm
; Enzyme: cast() argument of incompatible type
;
; opt castconst-reduced.ll -load-pass-plugin=libEnzyme-23.so -passes=enzyme -S
;
; opt: llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From *)
; [To = llvm::Constant, From = llvm::Value]:
; Assertion `isa(Val) && "cast() argument of incompatible type!"'
;
; GradientUtils.cpp, the ConstantDataArray case of invertPointerM:
;
; Value *val = invertPointerM(el, BuilderM, subTT);
; Vals.push_back(cast(val)); ; <-- fires here
;
; @tab holds two packed doubles as bytes, so its ConstantDataArray elements are
; i8. Element 0 is byte 0x55 ('U') of 1/3 = 0x3FD5555555555555. Its one-byte
; TypeTree window overlaps a float without covering the whole double, so
; inverting that element falls into the generic partially-float path, which
; emits an alloca/store/load and hands back a LoadInst rather than a Constant.
;
; The store makes @tab active, so Enzyme builds a shadow global and inverts its
; initializer; without it the global stays constant and is never inverted.
;
; Reduced with llvm-reduce from repro/castconst-single.rs (a no_std Rust file).
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@tab = global [16 x i8] c"UUUUUU\D5?\00\00\00\00\00\00\D0?"
@enzyme_const = external global ptr
@enzyme_dup = external global ptr

define void @f(ptr %0, i64 %1, ptr %2, i64 %3, i32 %4) {
store i32 0, ptr @tab, align 4
ret void
}

define {} @entry() {
%1 = tail call {} (...) @__enzyme_autodiff(ptr @f, ptr @enzyme_dup, ptr null, ptr null, ptr @enzyme_const, i64 0, ptr @enzyme_dup, ptr null, ptr null, ptr @enzyme_const, i64 0, ptr @enzyme_const, i32 0)
ret {} %1
}

declare {} @__enzyme_autodiff(...)
```
@wsmoses

Contributor guide

Open the contributing guide

Research direction

Start with GradientUtils.cpp, specifically the ConstantDataArray case of invertPointerM, and reproduce the assertion using the reduced LLVM IR with opt and the Enzyme pass plugin. Trace why the inversion result is passed to cast when the partial-float path returns a LoadInst. Done means the provided reduced repro no longer triggers the incompatible cast assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.