Repository navigation
Keep Julia allocation zeroing bundles on shadow allocations - #3426
Merged
Merged
Conversation
wsmoses
reviewed
Oct 6, 2026
Since julia#60924 (1.14.0-DEV.1697), Julia codegen no longer emits null
stores for the GC pointer fields of a new object. It attaches operand
bundles to the allocation call instead, and late-gc-lowering zeroes the
fields right after it lowers the allocation:
julia.gc_alloc_ptr_offsets(i64 off...) on julia.gc_alloc_obj
julia.gc_alloc_zeroinit(i64 off, i64 size) on julia.gc_alloc_obj
julia.gc_alloc_zeroinit_indirect(i64 off, i64 size)
on jl_alloc_genericmemory_unchecked
Accept these bundles in usedInRooting and getInvertedBundles, so that
calls that carry them no longer hit "unsupported tag". Also copy them
onto the shadow allocations that Enzyme creates for julia.gc_alloc_obj
in reverse mode and in loop rematerialization. Those calls had no
bundles before, so the GC pointer fields of the shadow were only
covered by the memset after the allocation, which LLVM may shorten or
remove when later stores overwrite the fields.
Assisted-by: Claude Code (Opus 5.5)
Assisted-by: Claude Code (Opus 5.5)
vchuravy
force-pushed
the
vc/julia-alloc-zeroing-bundles
branch
from
November 14, 2026 18:14
de29010 to
9f71d38
Compare
Julia's julia.gc_alloc_ptr_offsets bundle only nulls the GC pointer fields, so the shadow still needs Enzyme's full memset to zero the double at offset 0. Assisted-by: Claude Code (Opus 5.5)
vchuravy
force-pushed
the
vc/julia-alloc-zeroing-bundles
branch
2 times, most recently
from
November 14, 2026 18:52
ce20c18 to
69b4bdc
Compare
This was referenced Nov 14, 2026
Closed
vchuravy
force-pushed
the
vc/julia-alloc-zeroing-bundles
branch
from
November 14, 2026 20:04
69b4bdc to
19327f8
Compare
On LLVM 16 the cache and tape allocations keep the names of CallInst::CreateMalloc (%malloccall...), simplifycfg names the select %p instead of %spec.select, and the extractvalues of the tape and the frees of the tape caches come in the other order. Match those values by FileCheck variable and the reordered pairs with CHECK-DAG. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015RAaewsVwF5wyRBfErBEEr
Member
Author
|
Fixes EnzymeAD/Enzyme.jl#4051 |
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.
Requested by Valentin
Needed for EnzymeAD/Enzyme.jl#4051. Follow-up: #3881.
Before: Julia 1.13.4 backported julia#60924, which 1.14 has had since 1.14.0-DEV.1697. Julia allocation calls now carry
julia.gc_alloc_ptr_offsets,julia.gc_alloc_zeroinitorjulia.gc_alloc_zeroinit_indirectoperand bundles. Enzyme aborts with "unsupported tag" when it meets one inusedInRootingorgetInvertedBundles. This breaks every Enzyme.jl test run on Julia 1.13.4. For example,Enzyme.gradient(Forward, Const(x -> sum([x][1])), [1.0, 2.0])aborts withunsupported tag julia.gc_alloc_zeroinit. The reverse-mode shadow of ajulia.gc_alloc_objwas also created without any bundles, so only the memset after the allocation covered its GC pointer fields.After: these bundles pass through like
gc-transition. Every shadow allocation ofjulia.gc_alloc_objcarries the primal's zeroing bundles, so late-gc-lowering nulls its GC pointer fields right after the allocation.julia#60924 moved the null stores out of codegen because LLVM may sink or shorten them past a safepoint. The memset that Enzyme puts on a reverse-mode shadow has the same risk: later shadow stores overwrite the fields, and DSE can shorten it. The memset stays because the bundles only null the GC pointer fields. The rest of the shadow, such as the
Float64of aTuple{Float64,Any}, must still be zeroed. #3881 narrows the memset to those bytes.How: a new
GradientUtils::getAllocationZeroingBundlesreturns the zeroing bundles of the original call, remapped, and looked up in loop rematerialization. The two places that build a shadow allocation without bundles now pass them:CallDerivatives.cppand the loop rematerialization inGradientUtils.cpp. The tags are literal names, so older Julia, which never emits them, sees no change.Companion Enzyme.jl PR: EnzymeAD/Enzyme.jl#3766 drops the explicit GC-field stores in
shadow_alloc_rewritefor allocations that carry one of these bundles. It is not required for this PR.Testing:
ReverseMode/julia_gc_alloc_zeroing_bundles.llandForwardMode/julia_gc_alloc_zeroing_bundles.llcheck the copied bundles and the full memset, including aTuple{Float64,Any}layout (a pointer at offset 8). Against LLVM 20, the lit suite has the same results asmain.push!into a vector of vectors, and aTuple{Float64,Any}.basic,array,typeunstable,applyiter,mixedapplyiter,absint,sugar,rules/inactive_kwrules,runtime_calls,typetree,threads,callconv,core/abi.advanced, segfaults in "Broadcast noalias" (bc1_loss_function). It does so on 1.13.2 with the released Enzyme_jll 0.0.308 too, so it is unrelated to this PR.dda42805ec(LLVM 22, assertions), with the same per-file results as an earlier prototype.🤖 Generated with Claude Code