-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Arith] Implemented PMatchesOneOf and matches_one_of #13933
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
Conversation
Frequently, several related rewrite rules will have identical output
patterns and preconditions, differing only by the form of the input
pattern. For example, both `(x + y) - y` and `(y + x) - y` can be
simplified to `x`. Previously, these would be written as separate
rewrite rules, which required duplicating the output and
preconditions.
This commit introduces `PMatchesOneOf`, which attempts a series of
pattern matches, stopping after the first successful match. The
`PMatchesOneOf` instance can be used as the input pattern for rewrite
rules. A helper function `matches_one_of` is also added, which
returns an instance of `PMatchesOneOf`.
```c++
// Before
TVM_TRY_REWRITE( (x + y) - y, x);
TVM_TRY_REWRITE( (y + x) - y, x);
// After
TVM_TRY_REWRITE( matches_one_of( (x + y) - y,
(y + x) - y),
x);
```
|
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 |
|
This arose from some experiments regarding RewriteSimplifier that didn't end up materializing. During development, it was error prone to make identical updates across several related rules, so I put this utility together. The performance when using |
f286f87 to
ac22e3e
Compare
wrongtest-intellif
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.
All rules are checked compatible with previous. Many thanks!
This simplification was introduced in apache#13217, and was erroneously removed in apache#13933. This commit re-enables this simplification, and adds unit tests to prevent any future regression.
Follow-up to apache#13933, where a comment pointed out a few rewrite rules that were nearly redundant. These were rules that needed to distinguish between output of `max(x-y, 0)` and `max(0, x-y)`, to match previously expected output. This commit adds explicit collection of constants to the RHS of add/mul/min/max.


Frequently, several related rewrite rules will have identical output patterns and preconditions, differing only by the form of the input pattern. For example, both
(x + y) - yand(y + x) - ycan be simplified tox. Previously, these would be written as separate rewrite rules, which required duplicating the output and preconditions.This commit introduces
PMatchesOneOf, which attempts a series of pattern matches, stopping after the first successful match. ThePMatchesOneOfinstance can be used as the input pattern for rewrite rules. A helper functionmatches_one_ofis also added, which returns an instance ofPMatchesOneOf.