LateLowerGCFrame: coalesce dead-slot resets and recompute alloca slot addresses per block #64681
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 347 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.350
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #64681"
general
weight: 0.35
topolarity
Summary
When compiling functions with $N$ sequential allocations and $O(N)$ inlined error/throw blocks or inlined
sretcalls (such asEnzymeAD/Reactant.jl#3511/EnzymeAD/Reactant.jl#3679),LateLowerGCFrameexhibits quadratic IR emission and induces quadratic downstream work in LLVM's backend passes:1. Coalesce contiguous dead GC frame slot resets into
llvm.memset:-
PlaceGCFrameReset(added in #52935) zeroes out GC frame slots that die across safepoints so dead objects aren't conservatively retained across long-running calls.- When each step $k \in \{1, \dots, N\}$ along the hot path has $\Theta(k)$ live GC roots, each of the $\Theta(N)$ cold/throw blocks inherits
LiveInof size $\Theta(k)$ from its predecessor and hasNowLive = \emptyset, previously causingPlaceGCFrameStoresto emit $\Theta(N^2)$ individual@julia.get_gc_frame_slot+store ptr addrspace(10) nullpairs (190,742null stores at $N=250$;756,932at $N=500$).- Preserving master's exact reset behavior,
PlaceGCFrameStoressorts the dead slot colors at each safepoint and callsPlaceGCFrameReseton each contiguous run, emitting a single@julia.get_gc_frame_slot+llvm.memsetfor runs of $\ge 4$ adjacent slots (and individual null stores for runs $< 4$).2. Recompute
S.ArrayAllocasslot addresses per using block and placeS.TrackedStoresslots locally:-
replace_allocapreviously inserted@julia.get_gc_frame_slotonly in the entry block right after%gcframe, andS.TrackedStoresdid the same even though each shadow store occurs at a singleStoreInst.- When $O(N)$ calls with local root allocas are inlined into a function, keeping all $O(N)$
getelementptrs in the entry block preventsCodeGenPreparefrom sinking them (as they feed calls), causingSelectionDAGISelto emit $O(N)$LEAinstructions inbb.0and triggering $\Theta(N^2)$MachineSinkingin the backend.- Recomputing
@julia.get_gc_frame_slotonce per using block (SlotInBB, usingPHINode::getIncomingBlockfor PHI operands and cleaning up the unused entryslotAddresswhile preservingdbg.declaremetadata) and placingS.TrackedStoresslot calls right before eachStoreInstkeeps slot address materialization local to its uses.Benchmark (
Reactant.jl#3679Thunk with $N$ buffers)Measured with
opt -passes=julia+llc -mcpu=native -O2:| Workload |
opt(before → after) |llc(before → after) | Post-optIR lines ||---|---|---|---|
|
thunk($N=250$) |3.92s → 2.45s(1.60x) |9.93s → 3.46s(2.87x) |236,101 → 49,499(4.77x smaller) ||
thunk($N=500$) |13.67s → 5.88s(2.32x) |53.70s → 10.47s(5.13x) |846,657 → 99,027(8.55x smaller) |Assisted-by: Gemini