← Back to Pull requests

[TRITONGPU] FuseNestedLoops: only trust llvm.assume that dominates the loop #11521

Closed
unknown closed this pull request without merging on Sep 08, 2026 19:13 UTC
View on GitHub
unknown unknown commented on Aug 31, 2026 16:08 UTC
Author

[TRITONGPU] FuseNestedLoops: only trust llvm.assume that dominates the loop

Fixes #11519.

Problem

tritongpu-fuse-nested-loops proves an inner loop's trip count positive by
matching an llvm.assume(ub > lb) anywhere in the function — no dominance
or reachability query. When the assume sits on a branch the loop nest is not
reachable from (e.g. a shape-specialization branch that asserts something
about another parameter), the pass marks the inner loop as must-execute and
drops the zero-trip version split it would otherwise emit.

On a fully legal call (m=4, n=0 in the reproducer) the fused loop then runs
max(n, 1) * m times: the kernel returns a value the source program cannot
produce, and stores into a buffer the source program never writes (silent
memory corruption, no diagnostic).

The assumption is not being weighed and found probable: it is being read from
a program point the code under transformation cannot reach, which no
assumption-consuming analysis in LLVM or MLIR would consider valid
(llvm::isValidAssumeForContext is dominance-gated).

Fix

Thread DominanceInfo (already held by the pass and used two functions above
in the same file) into matchPositiveTripCount and require the matched
llvm.assume to properly dominate the loop. Otherwise fall through to the
existing version-split path, which is what every kernel without an in-scope
assume gets today. The in-tree _p_matmul idiom (tl.assume(loop_bound > 0)
immediately before the loop) keeps the fast path — nothing is lost there.

Verification

  • Reproduced on NVIDIA H200 (sm_90) with the reproducer from #11519: before

  • the fix out[:4] = [4.0, 8.0, 12.0, 16.0] and 256 spurious sink writes;
    after the fix out stays [0.0, 0.0, 0.0, 0.0] and sink is untouched.
  • The structural half (no GPU): before the fix the emitted LLVM IR for the

  • assume kernel contains no zero-trip test (icmp eq i32 %4, 0 absent); after
    the fix it is present, matching the assume-free control kernel.
  • Lit test test/TritonGPU/fuse-nested-loops.mlir: new @assume_not_dominating_loop

  • case asserts the zero-trip guard (scf.if (ub == 0)) is still emitted and no
    arith.constant true must-execute guard appears.

    Tests

  • /test for lit tests

  • /python/test for end-to-end tests
  • New contributor declaration

  • I am not making a trivial change, such as fixing a typo in a comment.

  • I have written a PR description following these

  • rules.
  • I have run pre-commit run --from-ref origin/main --to-ref HEAD

  • (the expand-yaml-anchors hook was skipped: it only applies to
    .github/workflows/integration-tests.yml and needs a network fetch of yq).

    Diff: 343 lines (+257 / -86) across 4 files Reviewer: LiRunGuo Review duration: 11705m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 343 lines diff across 4 files
    0.42
    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.349
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #11521"
    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: 42.3% (MEDIUM) · Higher = larger blast radius
    42.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: 16.7% · Safe to merge
    16.7%