← Back to Pull requests

Prune dead affine.if results in affine-cfg #3984

Closed
unknown closed this pull request without merging on Nov 17, 2026 15:36 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 14:53 UTC
Author

Fixes raising to scatter/gather regression in https://numericalearth.github.io/BreezeBenchmarks/

---

affine-cfg can leave an affine.if result with no users: once it sinks the loads that read through a selected index into the branches, the index result is dead but still yielded.

On a kernel over a flattened 16x16 thread index with a periodic halo read (i == 1 ? Nx : i - 1), that dead index kept the non-affine iv - (iv / 16) * 16 alive. This stopped SplitParallelInductions from splitting the index into its two dimensions, so every access stayed in terms of j floordiv 16 / j mod 16 and the kernel raised to gathers and a scatter:

%9:3 = affine.if #set(%arg5) -> (i64, f64, f64) {   // %9#0 unused
  ...
  affine.yield %c16_i64, %13, %14 : i64, f64, f64
} else {
  ...
  affine.yield %7, %13, %14 : i64, f64, f64          // %7 = iv - (iv / 16) * 16
}

llvm-to-affine-access already has a pattern for this (AffineIfDeadResults, #2932), but there the result is still in use. This PR exposes it as populateAffineIfDeadResultsPatterns and runs it in affine-cfg too. The kernel now raises to slices, a concatenate for the wrap-around, and a dynamic_update_slice.

Test updates:

  • affinecfg_if_dead_result.mlir: new, a cut-down version of the kernel.

  • liftintoif, northsouth{,2,3}: the dead index result and the constants feeding it are gone.

  • affinecfg_select_hoist_capture: the whole if-nest was unused and is now removed, along with the hoisting the test covers. I added a store of its value to keep it in use.
  • 🤖 Generated with Claude Code

    Diff: 206 lines (+154 / -52) across 2 files Reviewer: wsmoses Review duration: 42m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 206 lines diff across 2 files
    0.36
    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.319
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3984"
    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: 36.4% (MEDIUM) · Higher = larger blast radius
    36.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: 14.4% · Safe to merge
    14.4%