Conversation
wsmoses
reviewed
Apr 28, 2026
| return Constant::getNullValue(getShadowType(oval->getType())); | ||
| } | ||
|
|
||
| if (looseTypeAnalysis && oval->getType()->isIntOrIntVectorTy()) { |
Member
There was a problem hiding this comment.
This is the wrong place for the fix imo, you should instead make a special binop case for umax (like there is for (inteegr) Add, etc)
Co-authored-by: Copilot <copilot@github.com>
wsmoses
reviewed
May 5, 2026
| switch (II->getIntrinsicID()) { | ||
| default: | ||
| goto end; | ||
| #if LLVM_VERSION_MAJOR >= 12 |
Member
There was a problem hiding this comment.
don't modify invertPointerM
instead do a special case handling for these intrinsics in visitIntrinsicInst, similar to how the binary operator handling is for some interger instructions like on AdjointGenerator.h:2614
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enzyme Crash:
invertPointerMassertion failure on@llvm.umax.i32with-enzyme-loose-typesSummary
This is to fix #2794
Enzyme crashes with
assert(0 && "cannot find deal with ptr that isnt arg")inGradientUtils::invertPointerM()when differentiating code that uses the@llvm.umax.i32intrinsic in reverse mode with-enzyme-loose-types=1enabled.Root Cause
When a struct passed as
enzyme_dupcontains both floating-point and integer pointer fields, and the function stores the result of@llvm.umax.i32to an integer pointer loaded from that struct:visitCommonStorehandles the store of thei32umax result to the dup pointeri32value as potentially activevisitCommonStorecallsinvertPointerM()on thei32umax result to obtain its shadowinvertPointerM()cannot find or create a shadow for the@llvm.umax.i32call resultGradientUtils.cpp:6601The
@llvm.umax.i32intrinsic arises fromSerialOperations::AtomicMax(dest, flag), which the LLVM optimizer lowers to aload → @llvm.umax.i32 → storepattern.Reproducer
LLVM IR reproducer (standalone)
File:
test/Enzyme/ReverseMode/loosetypes_umax.llThe IR models a struct with
float*output data,i32*flags, and afloatscalar. The function:i32flag from a float comparisoni32from the flags pointer, calls@llvm.umax.i32, stores result backOriginal failing code
Cromwell's
ComputeAlpha.cxxboundary operation using Oak'sDualFixedNeighborMapIterationreverse-mode template withSerialOperations.The explicit template instantiation
flux_map_kernel_cuda_reverse<OperationBoundaryComputeAlpha, ...>triggers the bug during x86 host compilation when the__enzyme_autodiffcall inside the reverse kernel is processed with-enzyme-loose-types=1.Stack trace
Proposed Fix
In
GradientUtils::invertPointerM(), before theCustomErrorHandlerfallback and the assertion, add a guard for integer/integer-vector values under loose type analysis:This returns a zero shadow for integer values that cannot have meaningful floating-point derivatives, which is correct because:
visitCommonStoreAffected versions
-enzyme-loose-typessupportTest
The regression test
test/Enzyme/ReverseMode/loosetypes_umax.llguards against this issue.