Skip to content

Conversation

@Lunderberg
Copy link
Contributor

Previously, RewriteSimplifier inspected the top branch of each And and Or node, but didn't perform simplifications that would require inspection across branches nested structures. This commit introduces SimplifyAsAndOfOrs, which converts to an internal representation as conjunctive normal form, performs simplifications while in that form, then converts back to a PrimExpr.

This utility is designed for data-propagation simplifications as part of #12261. To avoid increasing the CPU load unnecesarily, this utility is only used on an opt-in basis, either by using RewriteSimplifer::SetEnabledFeatureswhen called directly, or by usingPassContextwhen used as part oftir::transform::Simplify`.

@Lunderberg
Copy link
Contributor Author

This PR is expected to have some merge conflicts with #12863, as they both introduce the same pass context for tir::transform::Simplify, and the same enum RewriteSimplifier::Feature. After whichever one lands first, the other will be rebased on top of it to resolve.

This is related to the closed #12942. The simplifications in this PR only require a single non-recursive rewrite, but we decided that refactoring this functionality out of RewriteSimplifier wasn't worth the change at the moment.

Previously, `RewriteSimplifier` inspected the top branch of each `And`
and `Or` node, but didn't perform simplifications that would require
inspection across branches nested structures.  This commit introduces
`SimplifyAsAndOfOrs`, which converts to an internal representation as
conjunctive normal form, performs simplifications while in that form,
then converts back to a `PrimExpr`.

This utility is designed for data-propagation simplifications as part
of apache#12261.  To avoid increasing
the CPU load unnecesarily, this utility is only used on an opt-in
basis, either using `RewriteSimplifer::SetEnabledFeatures` when called
directly, or using `PassContext` when used as part of
`tir::transform::Simplify`.
@Lunderberg
Copy link
Contributor Author

@tvm-bot rerun

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.

Looks great! Just a few minor nits and changes requested.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 12, 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

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! Thanks @Lunderberg

@csullivan csullivan merged commit 29a8f06 into apache:main Oct 13, 2022
@Lunderberg Lunderberg deleted the cnf_simplification branch October 14, 2022 01:54
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
…#12972)

Previously, `RewriteSimplifier` inspected the top branch of each `And`
and `Or` node, but didn't perform simplifications that would require
inspection across branches nested structures.  This commit introduces
`SimplifyAsAndOfOrs`, which converts to an internal representation as
conjunctive normal form, performs simplifications while in that form,
then converts back to a `PrimExpr`.

This utility is designed for data-propagation simplifications as part
of apache#12261.  To avoid increasing
the CPU load unnecesarily, this utility is only used on an opt-in
basis, either using `RewriteSimplifer::SetEnabledFeatures` when called
directly, or using `PassContext` when used as part of
`tir::transform::Simplify`.

* [Arith][UnitTest] Unittests displaying desired behavior

* Corrected example in analyzer.h

* Added underscore for private members

* Rename Cleanup() to RemoveTrueFalse()

* Added comments for conversion to internal representation

* Updated comment in test case

* Preferentially order clauses according to first occurrence

* Added more unit tests
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.

3 participants