Skip to content
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

[Arith] Updated incorrect simplification rule #13922

Merged
merged 1 commit into from
Feb 7, 2023

Conversation

Lunderberg
Copy link
Contributor

The rules that rewrite min(floordiv(x + (A-1), A) * A, max(x, A)) and min(truncdiv(x + (A-1), A) * A, max(x, A)) into max(x, A) did not have sufficiently tight bounds. The truncdiv rule required that x >= 0, while the floordiv rule had no requirement on x. In both cases, the simplification was incorrect when x==0, as it would result in a rewrite from min(0, max(0, A)) into max(0, A).

This commit updates the rules to require that x >= 0 for each of these rules.

The rules that rewrite `min(floordiv(x + (A-1), A) * A, max(x, A))`
and `min(truncdiv(x + (A-1), A) * A, max(x, A))` into `max(x, A)` did
not have sufficiently tight bounds.  The `truncdiv` rule required that
`x >= 0`, while the `floordiv` rule had no requirement on `x`.  In
both cases, the simplification was incorrect when `x==0`, as it would
result in a rewrite from `min(0, max(0, A))` into `max(0, A)`.

This commit updates the rules to require that `x >= 0` for each of
these rules.
@tvm-bot
Copy link
Collaborator

tvm-bot commented Feb 6, 2023

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

@tqchen
Copy link
Member

tqchen commented Feb 6, 2023

cc @wrongtest-intellif

@wrongtest-intellif
Copy link
Contributor

x >= 0

Hi :) , is it a typo for x > 0? @Lunderberg

Copy link
Contributor

@wrongtest-intellif wrongtest-intellif left a comment

Choose a reason for hiding this comment

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

LGTM!

Another helper view is when x % A == 0, min(ceildiv(x, A), max(x, a)) == x, thus we should exclude the case x==0 when max(x, A) != x

@wrongtest-intellif wrongtest-intellif merged commit 282f175 into apache:main Feb 7, 2023
@Lunderberg
Copy link
Contributor Author

Hi :) , is it a typo for x > 0? @Lunderberg

Thank you, and yes, that was a typo. The condition was updated to require x > 0.

@Lunderberg Lunderberg deleted the update_min_of_div_rules branch February 7, 2023 14:24
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.

4 participants