Skip to content

Preserve AxisInfo hints on inlined jit call results - #11150

Open
39ali wants to merge 3 commits into
triton-lang:mainfrom
39ali:fix-jit-return-hints
Open

Preserve AxisInfo hints on inlined jit call results#11150
39ali wants to merge 3 commits into
triton-lang:mainfrom
39ali:fix-jit-return-hints

Conversation

@39ali

@39ali 39ali commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #8592.

tl.multiple_of, tl.max_contiguous, and tl.max_constancy attach their
hint attributes (tt.divisibility, tt.contiguity, tt.constancy) to the
operation that defines the hinted value. When that value is returned from a
@triton.jit helper function, the defining operation is the tt.call — and
the inliner erases the call without transferring the attributes to the
inlined value. The hints were silently dropped, so AxisInfo could not see
them and the backend missed optimizations such as vectorized loads. Factoring
pointer arithmetic into a helper function silently degraded generated code
even though the kernel author had provided the hints.

Implement handleResult on TritonInlinerInterface so that, when the
inliner replaces a call result with the corresponding inlined value, the
AxisInfo hint attributes on the call are copied onto the inlined value's
defining op. This makes hints on jit-call results survive inlining, matching
the behavior of writing the same code without a helper function.

The added end-to-end test applies all three hints to a value returned from a
jitted helper and asserts they are present on the inlined tt.addptr in
TTIR; it fails without this change.

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.

  • Select one of the following.

    • I have added tests.
      • /test for lit tests
      • /unittest for C++ tests
      • /python/test for end-to-end tests
    • This PR does not need a test because FILL THIS IN.
  • Select one of the following.

    • [] I have not added any lit tests.
    • The lit tests I have added follow these best practices,
      including the "tests should be minimal" section. (Usually running Python code
      and using the instructions it generates is not minimal.)

@39ali
39ali requested a review from ptillet as a code owner August 2, 2026 22:46
Comment thread python/test/unit/language/test_core.py Outdated
Comment on lines +1452 to +1476
def test_jit_call_result_preserves_hints(device):

@triton.jit
def get_ptrs(ptr, offsets):
return ptr + offsets

@triton.jit
def kernel(X, Z, BLOCK_SIZE: tl.constexpr):
offsets = tl.arange(0, BLOCK_SIZE)
ptrs = get_ptrs(X, offsets)
ptrs = tl.multiple_of(ptrs, 16)
ptrs = tl.max_contiguous(ptrs, 16)
ptrs = tl.max_constancy(ptrs, 1)
tl.store(Z + offsets, tl.load(ptrs))

block_size = 128
x = torch.randn(block_size, device=device, dtype=torch.float32)
z = torch.empty_like(x)
compiled = kernel[(1, )](x, z, BLOCK_SIZE=block_size, num_warps=1)

assert torch.equal(z, x)
ttir = compiled.asm["ttir"]
ptrs_line = next(line for line in ttir.splitlines() if re.match(r"\s*%ptrs(?:_\d+)? = tt.addptr", line))
for hint in ("tt.divisibility", "tt.contiguity", "tt.constancy"):
assert hint in ptrs_line, ttir

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you replace this by a lit test instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@39ali
39ali force-pushed the fix-jit-return-hints branch from 9da92a6 to 99b81a1 Compare August 3, 2026 08:18
@ThomasRaoux
ThomasRaoux enabled auto-merge (squash) August 6, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[triton frontend] tt.contiguity is missing in TTIR if appied to return value of a jit function

2 participants