Lunderberg commented on code in PR #12972:
URL: https://github.com/apache/tvm/pull/12972#discussion_r993704527


##########
tests/python/unittest/test_tir_transform_simplify.py:
##########
@@ -686,5 +688,52 @@ def before(A: T.Buffer[1, "bool"], i: T.int32, j: T.int32, 
k: T.int32):
     expected = before
 
 
+class TestRewriteAsAndOfOrs(BaseBeforeAfter):
+    """If enabled, rewrite boolean expressions into AND of OR"""
+
+    convert_boolean_to_and_of_ors = True
+
+    def before(A: T.Buffer[3, "bool"]):
+        T.evaluate(A[0] or (A[1] and A[2]))
+
+    def expected(A: T.Buffer[3, "bool"]):
+        T.evaluate((A[0] or A[1]) and (A[0] or A[2]))
+
+
+class TestSuppressRewriteAsAndOfOrs(BaseBeforeAfter):
+    """Only rewrite into AND of OR when allowed"""
+
+    convert_boolean_to_and_of_ors = False
+
+    def before(A: T.Buffer[3, "bool"]):
+        T.evaluate(A[0] or (A[1] and A[2]))
+
+    expected = before
+
+
+class TestRewriteAsAndOfOrsWithTopLevelAnd(BaseBeforeAfter):
+    """The expression being rewritten may start with an AND
+
+    Like TestRewriteAsAndOfOrs, but with an AndNode as the outermost
+    booelan operator.  Even though it is primarily OR nodes that are
+    being rewritten, the call to SimplifyAsAndOfOrs should apply to
+    the outermost AndNode or OrNode in order to enable better
+    simplification.
+    """
+
+    convert_boolean_to_and_of_ors = True
+
+    def before(A: T.Buffer[4, "bool"]):
+        T.evaluate((A[0] or A[1]) and (A[1] or (A[0] and A[2] and A[3])))
+
+    def expected(A: T.Buffer[4, "bool"]):
+        # If the simplification is applied to the OrNode, then the
+        # redundant `(A[1] or A[0])` isn't canceled out
+        #
+        # T.evaluate((A[0] or A[1]) and ((A[1] or A[0]) and (A[1] or A[2]) and 
(A[1] or A[3])))
+        #

Review Comment:
   It was intended to show what would occur if the delegation to 
`SimplifyAsAndOfOrs` were applied for each OR, rather than being applied at the 
top-level AND.  Updating the comment to state that this is what would occur if 
insufficiently simplified, and to distinguish between internal representation 
and what is expected as output.



-- 
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]

Reply via email to