Skip to content

Commit d1dea13

Browse files
authored
[Bugfix][TVMScript] Preserve variable names in LetStmt (#14319)
When the TVMScript parser generates a `tir::LetStmt` to represent assignment to a variable, the name of the variable should be used as the name of the `tir::Var` in the `tir::LetStmt`. This bug was introduced in #14207.
1 parent 32e500b commit d1dea13

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

python/tvm/script/parser/tir/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def bind_assign_value(self: Parser, node: doc.expr, var_name: str, value: Any) -
145145
elif isinstance(value, PrimExpr):
146146
frame = T.LetStmt(value)
147147
var = frame.var
148+
IRBuilder.name(var_name, var)
148149
frame.add_callback(partial(frame.__exit__, None, None, None))
149150
frame.__enter__()
150151
return var

tests/python/unittest/test_tvmscript_syntax_sugar.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,18 @@ def implicit(A: T.Buffer(1, "int32")):
399399
assert_structural_equal(implicit, explicit)
400400

401401

402+
def test_preserve_variable_name():
403+
"""Use variable name when generating tir::LetStmt"""
404+
405+
@T.prim_func
406+
def func():
407+
for i in T.serial(16):
408+
j = i // 4
409+
T.evaluate(j)
410+
411+
var_name = func.body.body.var.name
412+
assert var_name == "j"
413+
414+
402415
if __name__ == "__main__":
403416
tvm.testing.main()

0 commit comments

Comments
 (0)