Skip to content

Conversation

@Lunderberg
Copy link
Contributor

When simplifying a branch of a boolean AND or a boolean OR, the other branch may be assumed not to dominate the result of the operator. For example, when simplifying (A and B), A may be simplified on the assumption that B is true. Similarly, when simplifying (A or B), A may be simplified on the assumption that B is false.

Prior to this commit, these constraints were not used for simplifications. This commit introduced an optional extension, kApplyConstraintsToBooleanBranches, which exposes these constraints for simplification. This isn't enabled by default, as some cases require a second visit to each branch of a boolean operator. (e.g. Simplifying the LHS of an operator, using a constraint provided by the RHS, where the sub-analyzer that uses the constraint expects it to already be simplified.)

@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 19, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@areusch areusch added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it and removed needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it labels Oct 19, 2022
Copy link
Contributor

@csullivan csullivan left a comment

Choose a reason for hiding this comment

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

LGTM with only nits

// more than update. The loop condition allows each branch to be
// visited up to twice, but only if performs the second visit if
// necessary.
for (size_t i = 0, last_updated = 0; i < last_updated + 2 && i < 4; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Is there a way to make this for-loop more understandable? The multiple iterator makes it difficult to understand, possibly error prone, without detailed study.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wasn't sure the best way to express this one. I only wanted to perform one update per loop iteration, to avoid the fourth simplify (a -> b -> a -> b) if it converged earlier.

Hmm, maybe if I rewrite it as a fixed-length loop with early bail-out instead. I'd initially written it without the i < 4, so that it would iterate until convergence, but now that I know how the maximum number of loops required, that flexibility isn't needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten, and it definitely is more coherent this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And updated in the OrNode handler as well.

Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @Lunderberg

When simplifying a branch of a boolean AND or a boolean OR, the
other branch may be assumed not to dominate the result of the
operator.  For example, when simplifying `(A and B)`, `A` may be
simplified on the assumption that `B` is true.  Similarly, when
simplifying `(A or B)`, `A` may be simplified on the assumption
that `B` is false.

Prior to this commit, these constraints were not used for
simplifications.  This commit introduced an optional extension,
`kApplyConstraintsToBooleanBranches`, which exposes these
constraints for simplification.  This isn't enabled by default,
as some cases require a second visit to each branch of a boolean
operator.  (e.g. Simplifying the LHS of an operator, using a
constraint provided by the RHS, where the sub-analyzer that uses
the constraint expects it to already be simplified.)
@Lunderberg Lunderberg force-pushed the apply_constraints_to_boolean_branches branch from 9c67b40 to fdd7ada Compare October 28, 2022 14:05
@Lunderberg
Copy link
Contributor Author

Thank you!

(Rebased onto main to resolve conflict.)

@Lunderberg Lunderberg merged commit 602c194 into apache:main Oct 28, 2022
@Lunderberg Lunderberg deleted the apply_constraints_to_boolean_branches branch October 28, 2022 18:36
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
…pache#13129)

When simplifying a branch of a boolean AND or a boolean OR, the
other branch may be assumed not to dominate the result of the
operator.  For example, when simplifying `(A and B)`, `A` may be
simplified on the assumption that `B` is true.  Similarly, when
simplifying `(A or B)`, `A` may be simplified on the assumption
that `B` is false.

Prior to this commit, these constraints were not used for
simplifications.  This commit introduced an optional extension,
`kApplyConstraintsToBooleanBranches`, which exposes these
constraints for simplification.  This isn't enabled by default,
as some cases require a second visit to each branch of a boolean
operator.  (e.g. Simplifying the LHS of an operator, using a
constraint provided by the RHS, where the sub-analyzer that uses
the constraint expects it to already be simplified.)
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
…pache#13129)

When simplifying a branch of a boolean AND or a boolean OR, the
other branch may be assumed not to dominate the result of the
operator.  For example, when simplifying `(A and B)`, `A` may be
simplified on the assumption that `B` is true.  Similarly, when
simplifying `(A or B)`, `A` may be simplified on the assumption
that `B` is false.

Prior to this commit, these constraints were not used for
simplifications.  This commit introduced an optional extension,
`kApplyConstraintsToBooleanBranches`, which exposes these
constraints for simplification.  This isn't enabled by default,
as some cases require a second visit to each branch of a boolean
operator.  (e.g. Simplifying the LHS of an operator, using a
constraint provided by the RHS, where the sub-analyzer that uses
the constraint expects it to already be simplified.)
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.

5 participants