← Back to Pull requests

Drop constant-memory alias claims from functions Enzyme inlines #4046

Closed
unknown closed this pull request without merging on Nov 17, 2026 18:32 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 20:59 UTC
Author

Julia tags a load from an immutable object reached through an argument as a read of constant memory (jtbaa_const TBAA and the jnoalias_const alias scope), which no store in the same function may alias. That holds for a Julia function on its own. It stops holding once LLVM inlines the function into a caller that constructs the object: the caller's initializing stores (tagged jnoalias_data) and the callee's loads then share a function, and LLVM is entitled to fold the loads to undef.

Enzyme always-inlines rule functions, so this can miscompile a custom rule that reads a boxed immutable argument built in the differentiated function. This PR removes the claim (!tbaa, !alias.scope, !noalias) from such loads in any alwaysinline function, in remove_alwaysinline_roots!, which already runs before each AlwaysInlinerPass. Loads without the constant-memory claim, and functions that are not inlined, are left alone.

How it was found

#4026 lets a boxed immutable with mixed activity reach a reverse rule. On Julia 1.13 this returns NaN:

struct Node
    value::Float64
    children::Union{Nothing, Vector{Node}}
end
f(n::Node) = n.value^2            # with augmented_primal/reverse rules taping `n.val`
g(x) = f(Node(x, nothing))
autodiff(ReverseWithPrimal, g, Active, Active(3.0))   # ((NaN,), 9.0) on 1.13

The optimized IR has the rule's tape.value load folded to a constant. Julia 1.12 emits the same metadata; the optimizer does not happen to exploit it there. With this change the reproducer returns ((6.0,), 9.0) on 1.13.

Testing

  • New IR-level test in test/passes.jl: passes on 1.10, 1.12 and 1.13.

  • There is no end-to-end test here: on main a boxed immutable rule argument hits the assertion that #4026 fixes first, so the reproducer above only runs on top of #4026. With both applied, rules/rules.jl, the mixed-activity tests, the keyword-rule tests and rules/rule_inlining.jl pass locally on 1.10 through 1.13.

  • Not measured: any performance effect of the removed alias information in inlined rules. The full test suite was not run locally.
  • Diff: 264 lines (+198 / -66) across 3 files Reviewer: vchuravy Review duration: 7053m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 264 lines diff across 3 files
    0.39
    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.334
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4046"
    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: 39.3% (MEDIUM) · Higher = larger blast radius
    39.3%
    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: 15.5% · Safe to merge
    15.5%