← Back to Pull requests

fixLCSSA: cache collapsed LCSSA values (exponential recursion in MITgcm) #3944

Open
unknown opened this pull request with 253 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 30, 2026 20:45 UTC
Author

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

When the manual LCSSA phi that fixLCSSA builds for (inst, forwardBlock) collapses to a single value, the cache entry for forwardBlock was erased. Every later query for that block then walked all its predecessors again. Across a chain of if/else joins this is exponential in the number of joins.

Where it shows up

MITgcm adjoint builds (Fortran, full-LTO Enzyme link). createInvertedTerminator → branchToCorrespondingTarget unwraps a branch condition. The condition depends on a Fortran string-compare loop (preprocess_exf_wind_, lab_sea), and its llvm.ucmp result is looked up far below the loop. The query recursed 229 blocks deep. The links of lab_sea, global_ocean.cs32x15 and offline_exf_seaice ran 2.5 to 4.5 h in fixLCSSA without finishing.

Fix

  • Keep the collapsed value in the cache when it is available in forwardBlock: either it is not an instruction, or it dominates the block. Erase the entry only otherwise.

  • lcssaFixes holds WeakTrackingVH, so a cached value that is erased later reads back as null. Treat that as a cache miss instead of returning null. Without this, 1D_ocean_ice_column hit a null isa<UndefValue> in lookupM.
  • Testing

  • With this change, the lab_sea opt -passes='lto<O3>' repro finishes Enzyme in under 27 minutes. Before, it ran for more than 4.5 h without finishing.

  • With this fix in place, tutorial_global_oce_optim matches TAF to 1.1e-14.

  • check-enzyme on LLVM 16: 1210 passed, 10 expectedly failed.

  • No lit test yet. Small synthetic IR (diamond chains after loops, guarded string-compare loops) did not reach the recursion. Enzyme cached the loop-carried values instead of unwrapping them. Only the full MITgcm module reproduces it so far.
  • 🤖 Generated with Claude Code

    Diff: 253 lines (+189 / -64) across 3 files Reviewer: wsmoses Review duration: 926m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.44) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 253 lines diff across 3 files
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.331
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #3944"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 44% (MEDIUM) · Higher = larger blast radius
    44%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 23.5% · Safe to merge
    23.5%