Triton generates incorrect MLIR code when assigning values to elements of a tuple
in the body of an if
statement
#5446
Labels
tuple
in the body of an if
statement
#5446
Describe the bug
I noticed that Triton introduced support for
tuple
s in a recent commit (#5220). However, the Triton frontend does not handle the case where a user modifies atuple
inside anif
statement. For example, consider the following code:In this code, I modify
values[1]
in both the true and false branches of theif
statement, and finally store the result inout
. When I run this program withexport MLIR_ENABLE_DUMP=1
, Triton generates the following MLIR (with adjusted formatting and location information removed):The generated
scf.if
contains code that checks for overflow during the addition operation. Notably:scf.if
does not return any result. The correct behavior should be to return the modified value ofvalues[1]
.%6 = arith.extsi(%25)
incorrectly uses%25
, which is defined in another region.tt.store
incorrectly uses%14
, which is defined within theif
block.I suspect the error arises from the
local_defs
statistics incode_generator.py
, where only the names of definitions are counted, without accounting for the modification oftuple
elements. Similarly, I believe a similar error could occur when modifying a property access.If possible, I would be happy to contribute a fix for this issue to Triton. However, I am not sure how Triton would prefer to handle such cases — whether to simply prohibit users from modifying
tuple
elements, or if there is a better strategy for tracking values modified inside anif
statement.Environment details
Triton: commit 24b8d43
System: Ubuntu 22.04
The text was updated successfully, but these errors were encountered: