← Back to Pull requests

TypeAnalysis: keep a zext's Anything off its i1 operand #3947

Closed
unknown closed this pull request without merging on Dec 02, 2026 11:43 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 11:19 UTC
Author

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

MITgcm hits this in lab_sea (seaice_growth): the vectorizer emits zext <2 x i1> (fcmp ogt <2 x double> ...) and stores it to an integer mask array, and Enzyme fails with

Enzyme: Cannot deduce adding type (cast) of   %2850 = zext <2 x i1> %2849 to <2 x i32>

Cause. visitZExtInst types the zext of an i1 as Anything and then hands the result's type back to its operand. Anything replaces Integer when type trees are merged, so the fcmp loses the Integer that visitCmpInst gave it. For a scalar i1 this goes unnoticed, because getAnalysis reports every scalar integer under 16 bits as Integer whatever is stored. A vector of i1 is returned as stored, so activity analysis sees a value of unknown type computed from active floats and treats the mask as active.

Fix. The Anything of an extended i1 was not derived from the operand, so visitZExtInst no longer propagates it up to an i1 (or vector of i1) operand. The vector case then matches the scalar one: the compare stays Integer, and the mask and its store are inactive.

This replaces the earlier version of this PR, which skipped i1 operands in the cast adjoint. That left the mask active, so storing it to active memory still failed:

GradientUtils.cpp: invertPointerM: Assertion `0 && "cannot find deal with ptr that isnt arg"' failed.

Tests.

  • TypeAnalysis/zexti1vector.ll: the compare feeding the zext stays Integer.

  • ReverseMode/zext-i1-vector.ll: the reduced lab_sea pattern, with the mask stored to inactive and to active memory.
  • Both fail on main and pass with the fix. On an LLVM 18 build the Enzyme, TypeAnalysis and ActivityAnalysis lit suites show no new failures against main (the typed-pointer tests cannot run there). The LLVM 16 suite and the MITgcm lab_sea build have not been rerun with this version.

    https://claude.ai/code/session_01HgDfyh5CxbdWra5FFgUy6M

    ---
    _Generated by Claude Code_

    Diff: 273 lines (+204 / -69) across 3 files Reviewer: wsmoses Review duration: 1464m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 273 lines diff across 3 files
    0.45
    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.336
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #3947"
    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: 44.5% (MEDIUM) · Higher = larger blast radius
    44.5%
    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: 17.6% · Safe to merge
    17.6%