-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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] Use TryCompare to narrow inequalities if possible #13024
Conversation
Last failing unit test requires #13081 to resolve. An unrolled loop produced a |
271aa65
to
8dfa33b
Compare
8dfa33b
to
2c6d75c
Compare
Rebased onto main to resolve conflicts. Because this dev branch includes and depends on the changes made in #13023, that PR should be landed before this one. Therefore, marking this PR as a draft to avoid a weird git history from incorrect merge order. |
2c6d75c
to
6087e6e
Compare
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 |
Prior to this commit, the result of TryCompare would only be used if it could definitively prove a conditional to be either true or false. For example, if it is known that `0 <= i`, a conditional of `i <= 0` would be left as-is. This commit introduces rewrite rules to preferentially simplify into more restrictive conditions. Using the same example, if it is known that `0 <= i`, a conditional of `i <= 0` would be simplified into `i == 0`. Similarly, if it is known that `0 <= i`, a conditional of `i != 0` would be simplified into `0 < i`. Because this change does not introduce significant overhead, as the results of `RewriteSimplifier::Impl::TryCompare` are already available, this change is enabled for all use cases and does not require a call to `RewriteSimplifier::SetEnabledExtensions`.
6087e6e
to
507c1c5
Compare
Rebased onto main, which now includes #13023 to resolve the last failing unit test, and this PR is now ready for review. |
@tvm-bot rerun |
@tvm-bot rerun |
1 similar comment
@tvm-bot rerun |
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.
PR looks sound to me; thank you Eric for the contribution
…e#13024) Prior to this commit, the result of TryCompare would only be used if it could definitively prove a conditional to be either true or false. For example, if it is known that `0 <= i`, a conditional of `i <= 0` would be left as-is. This commit introduces rewrite rules to preferentially simplify into more restrictive conditions. Using the same example, if it is known that `0 <= i`, a conditional of `i <= 0` would be simplified into `i == 0`. Similarly, if it is known that `0 <= i`, a conditional of `i != 0` would be simplified into `0 < i`. Because this change does not introduce significant overhead, as the results of `RewriteSimplifier::Impl::TryCompare` are already available, this change is enabled for all use cases and does not require a call to `RewriteSimplifier::SetEnabledExtensions`.
…e#13024) Prior to this commit, the result of TryCompare would only be used if it could definitively prove a conditional to be either true or false. For example, if it is known that `0 <= i`, a conditional of `i <= 0` would be left as-is. This commit introduces rewrite rules to preferentially simplify into more restrictive conditions. Using the same example, if it is known that `0 <= i`, a conditional of `i <= 0` would be simplified into `i == 0`. Similarly, if it is known that `0 <= i`, a conditional of `i != 0` would be simplified into `0 < i`. Because this change does not introduce significant overhead, as the results of `RewriteSimplifier::Impl::TryCompare` are already available, this change is enabled for all use cases and does not require a call to `RewriteSimplifier::SetEnabledExtensions`.
Prior to this commit, the result of TryCompare would only be used if it could definitively prove a conditional to be either true or false. For example, if it is known that
0 <= i
, a conditional ofi <= 0
would be left as-is.This commit introduces rewrite rules to preferentially simplify into more restrictive conditions. Using the same example, if it is known that
0 <= i
, a conditional ofi <= 0
would be simplified intoi == 0
. Similarly, if it is known that0 <= i
, a conditional ofi != 0
would be simplified into0 < i
.Because this change does not introduce significant overhead, as the results of
RewriteSimplifier::Impl::TryCompare
are already available, this change is enabled for all use cases and does not require a call toRewriteSimplifier::SetEnabledExtensions
.