← Back to Pull requests

LateLowerGCFrame: coalesce dead-slot resets and recompute alloca slot addresses per block #64681

Closed
unknown closed this pull request without merging on Nov 07, 2026 15:41 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 16:32 UTC
Author

Summary

When compiling functions with $N$ sequential allocations and $O(N)$ inlined error/throw blocks or inlined sret calls (such as EnzymeAD/Reactant.jl#3511 / EnzymeAD/Reactant.jl#3679), LateLowerGCFrame exhibits 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 LiveIn of size $\Theta(k)$ from its predecessor and has NowLive = \emptyset, previously causing PlaceGCFrameStores to emit $\Theta(N^2)$ individual @julia.get_gc_frame_slot + store ptr addrspace(10) null pairs (190,742 null stores at $N=250$; 756,932 at $N=500$).
- Preserving master's exact reset behavior, PlaceGCFrameStores sorts the dead slot colors at each safepoint and calls PlaceGCFrameReset on each contiguous run, emitting a single @julia.get_gc_frame_slot + llvm.memset for runs of $\ge 4$ adjacent slots (and individual null stores for runs $< 4$).

2. Recompute S.ArrayAllocas slot addresses per using block and place S.TrackedStores slots locally:
- replace_alloca previously inserted @julia.get_gc_frame_slot only in the entry block right after %gcframe, and S.TrackedStores did the same even though each shadow store occurs at a single StoreInst.
- When $O(N)$ calls with local root allocas are inlined into a function, keeping all $O(N)$ getelementptrs in the entry block prevents CodeGenPrepare from sinking them (as they feed calls), causing SelectionDAGISel to emit $O(N)$ LEA instructions in bb.0 and triggering $\Theta(N^2)$ MachineSinking in the backend.
- Recomputing @julia.get_gc_frame_slot once per using block (SlotInBB, using PHINode::getIncomingBlock for PHI operands and cleaning up the unused entry slotAddress while preserving dbg.declare metadata) and placing S.TrackedStores slot calls right before each StoreInst keeps slot address materialization local to its uses.

Benchmark (Reactant.jl#3679 Thunk with $N$ buffers)

Measured with opt -passes=julia + llc -mcpu=native -O2:

| Workload | opt (before → after) | llc (before → after) | Post-opt IR 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

Diff: 347 lines (+260 / -87) across 4 files Reviewer: topolarity Review duration: 2828m
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
0.42
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.4% (MEDIUM) · Higher = larger blast radius
42.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.8% · Safe to merge
16.8%