Repository navigation
[TRITONGPU] FuseNestedLoops: only trust llvm.assume that dominates the loop - #11521
Merged
peterbell10 merged 3 commits intoSep 8, 2026
Merged
peterbell10 merged 3 commits into
peterbell10 merged 3 commits into
Conversation
…e loop tritongpu-fuse-nested-loops proved an inner loop's trip count positive by matching an llvm.assume(ub > lb) anywhere in the function, without checking that the assume dominates the loop. When the assume sat on a branch the loop nest was not reachable from (e.g. a shape-specialization branch), the pass dropped the zero-trip version split and marked the inner loop as must-execute, so a legal call with n == 0 ran the fused loop max(n, 1) * m times, returned a value the source cannot produce, and stored into memory the source never writes. Only trust the assume when it properly dominates 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 (assume immediately before the loop) keeps the fast path. Fixes triton-lang#11519
ThomasRaoux
reviewed
Aug 31, 2026
- Remove the four-line comment in matchPositiveTripCount; the properlyDominates check is clear from the code. - Remove the python regression test; the lit test in test/TritonGPU/fuse-nested-loops.mlir already covers the fix.
Contributor
Author
|
Hi @ThomasRaoux, thanks for the review! I've addressed both comments in commit
Could you take another look? Thanks! |
ThomasRaoux
approved these changes
Sep 1, 2026
Contributor
Author
|
Hi @ThomasRaoux, The PR is approved and in sync with Could you (or another maintainer) please approve the workflow so the checks can run? Thanks a lot! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[TRITONGPU] FuseNestedLoops: only trust
llvm.assumethat dominates the loopFixes #11519.
Problem
tritongpu-fuse-nested-loopsproves an inner loop's trip count positive bymatching an
llvm.assume(ub > lb)anywhere in the function — no dominanceor 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=0in the reproducer) the fused loop then runsmax(n, 1) * mtimes: the kernel returns a value the source program cannotproduce, 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::isValidAssumeForContextis dominance-gated).Fix
Thread
DominanceInfo(already held by the pass and used two functions abovein the same file) into
matchPositiveTripCountand require the matchedllvm.assumeto properly dominate the loop. Otherwise fall through to theexisting version-split path, which is what every kernel without an in-scope
assume gets today. The in-tree
_p_matmulidiom (tl.assume(loop_bound > 0)immediately before the loop) keeps the fast path — nothing is lost there.
Verification
the fix
out[:4] = [4.0, 8.0, 12.0, 16.0]and 256 spurioussinkwrites;after the fix
outstays[0.0, 0.0, 0.0, 0.0]andsinkis untouched.assume kernel contains no zero-trip test (
icmp eq i32 %4, 0absent); afterthe fix it is present, matching the assume-free control kernel.
test/TritonGPU/fuse-nested-loops.mlir: new@assume_not_dominating_loopcase asserts the zero-trip guard (
scf.if (ub == 0)) is still emitted and noarith.constant truemust-execute guard appears.Tests
/testforlittests/python/testfor end-to-end testsNew contributor declaration
rules.
pre-commit run --from-ref origin/main --to-ref HEAD(the
expand-yaml-anchorshook was skipped: it only applies to.github/workflows/integration-tests.ymland needs a network fetch ofyq).