Lunderberg commented on code in PR #11373:
URL: https://github.com/apache/tvm/pull/11373#discussion_r881773847
##########
tests/python/unittest/test_tir_transform_simplify.py:
##########
@@ -133,9 +134,41 @@ def sls(n, d):
assert "if" not in str(stmt)
+def test_load_store_noop():
+ """Store of a value that was just read from the same location is a
no-op."""
+
+ @T.prim_func
+ def before(A: T.Buffer[(1,), "float32"]):
+ A[0] = A[0]
+
+ @T.prim_func
+ def expected(A: T.Buffer[(1,), "float32"]):
+ T.evaluate(0)
+
+ after =
tvm.tir.transform.Simplify()(tvm.IRModule.from_expr(before))["main"]
+ tvm.ir.assert_structural_equal(after, expected)
+
+
+def test_load_store_noop_after_simplify():
+ """As test_load_store_noop, but requiring simplification to identify.
+
+ Previously, a bug caused the self-assignment of a buffer to
+ checked based on the pre-simplification assignment, not the
+ post-simplification. This test is to identify any similar
+ regression.
+ """
+
+ @T.prim_func
+ def before(A: T.Buffer[(1,), "float32"]):
+ A[0] = A[0] + (5.0 - 5.0)
+
+ @T.prim_func
+ def expected(A: T.Buffer[(1,), "float32"]):
+ T.evaluate(0)
+
+ after =
tvm.tir.transform.Simplify()(tvm.IRModule.from_expr(before))["main"]
+ tvm.ir.assert_structural_equal(after, expected)
+
+
if __name__ == "__main__":
- test_stmt_simplify()
- test_thread_extent_simplify()
- test_if_likely()
- test_basic_likely_elimination()
- test_complex_likely_elimination()
+ sys.exit(pytest.main(sys.argv))
Review Comment:
Ooh, I like the change. Rebased to include #11393, and updated to use
`tvm.testing.main()`. Looks like this file was missed in #11393, which is why
it didn't appear as a conflict.
##########
tests/python/unittest/test_tir_transform_simplify.py:
##########
@@ -133,9 +134,41 @@ def sls(n, d):
assert "if" not in str(stmt)
+def test_load_store_noop():
+ """Store of a value that was just read from the same location is a
no-op."""
+
+ @T.prim_func
+ def before(A: T.Buffer[(1,), "float32"]):
+ A[0] = A[0]
+
+ @T.prim_func
+ def expected(A: T.Buffer[(1,), "float32"]):
+ T.evaluate(0)
+
+ after =
tvm.tir.transform.Simplify()(tvm.IRModule.from_expr(before))["main"]
+ tvm.ir.assert_structural_equal(after, expected)
+
+
+def test_load_store_noop_after_simplify():
+ """As test_load_store_noop, but requiring simplification to identify.
+
+ Previously, a bug caused the self-assignment of a buffer to
+ checked based on the pre-simplification assignment, not the
+ post-simplification. This test is to identify any similar
+ regression.
+ """
+
+ @T.prim_func
+ def before(A: T.Buffer[(1,), "float32"]):
+ A[0] = A[0] + (5.0 - 5.0)
+
+ @T.prim_func
+ def expected(A: T.Buffer[(1,), "float32"]):
+ T.evaluate(0)
+
+ after =
tvm.tir.transform.Simplify()(tvm.IRModule.from_expr(before))["main"]
+ tvm.ir.assert_structural_equal(after, expected)
+
+
if __name__ == "__main__":
- test_stmt_simplify()
- test_thread_extent_simplify()
- test_if_likely()
- test_basic_likely_elimination()
- test_complex_likely_elimination()
+ sys.exit(pytest.main(sys.argv))
Review Comment:
Ooh, I like the new utility. Rebased to include #11393, and updated to use
`tvm.testing.main()`. Looks like this file was missed in #11393, which is why
it didn't appear as a conflict.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]