← Back to Pull requests

Use the shadow global under global activity #3883

Closed
unknown closed this pull request without merging on Nov 24, 2026 09:19 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 20:01 UTC
Author

<!-- claude-projects-attribution: {"github_login":"vchuravy"} -->
_Requested by Valentin · project thread_

Replaces #3342.

What

In combined and forward mode, invertPointerM gives a global without enzyme_shadow a zeroed local alloca as its shadow when no call in the function may touch it. With -enzyme-global-activity set, this PR skips that shortcut and always uses the shadow global.

Why

Under global activity the derivative held in a global outlives the call. In the test, @f writes @g and calls @leaf, which reads it. @diffeleaf added its adjoint into a local zeroed copy of @g, while @diffef read the adjoint from @g_shadow after the call, so the gradient was 0. The same happens across repeated calls of one function and for Fortran SAVE/COMMON state. Found differentiating MITgcm with LLVM flang and full LTO.

#3342 kept the shortcut and checked whether any other function uses the global. Under global activity every global derivative may be read by a caller or a later call, so this PR drops the shortcut in that mode instead. Without global activity nothing changes.

Test

enzyme/test/Enzyme/ReverseMode/global-activity-callee-global-shadow.ll checks that @diffeleaf has no alloca and accumulates into @g_shadow, and that @diffef reads the adjoint from there. It fails on main and passes here on LLVM 24 (df0a91f6). The other global tests in ReverseMode and ForwardMode give the same results with and without the change. On that LLVM, 10 of them fail on main too.

---
_Generated by Claude Code_

Diff: 208 lines (+156 / -52) across 2 files Reviewer: vchuravy Review duration: 13758m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.41) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.41 · 208 lines diff across 2 files
0.41
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.320
Shallow Review Depth shallow_review_depth
0.289
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #3883"
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: 41.4% (MEDIUM) · Higher = larger blast radius
41.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.4% · Safe to merge
16.4%