-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[TIR][Arith] Implement kApplyConstraintsToBooleanBranches extension #13129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIR][Arith] Implement kApplyConstraintsToBooleanBranches extension #13129
Conversation
|
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 |
csullivan
left a comment
There was a problem hiding this 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
src/arith/rewrite_simplify.cc
Outdated
| // 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++) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Hzfengsy
left a comment
There was a problem hiding this 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.)
9c67b40 to
fdd7ada
Compare
|
Thank you! (Rebased onto main to resolve conflict.) |
…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.)
…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.)
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),Amay be simplified on the assumption thatBis true. Similarly, when simplifying(A or B),Amay be simplified on the assumption thatBis 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.)