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

[TIR][Arith] Support negative coeff in ModularSet #13081

Merged
merged 1 commit into from
Oct 27, 2022

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, any use of negative coefficients in ModularSet would result in an error. This included cases where a constraint is being entered, such as floormod(i, -2)==0 appearing as the condition of an if/else block. These negative indices can also arise as intermediate simplification steps produced by CanonicalSimplifier, such as floormod(-i,2) being canonicalized to floormod(i,-2).

This commit adds support for negative coefficients in ModularSet, using the same sign convention as is used by CanonicalSimplifier for negative denominators, and adds unit tests to verify that sign convention.

@tvm-bot
Copy link
Collaborator

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

@Lunderberg
Copy link
Contributor Author

This was originally discovered in a failing unit test for #13024. An unrolled loop produced a T.if_then_else(floormod(-i,2)==0, ...), which resulted in an error thrown from ModularSet.

Prior to this commit, any use of negative coefficients in `ModularSet`
would result in an error.  This included cases where a constraint is
being entered, such as `floormod(i, -2)==0` appearing as the condition
of an if/else block.  These negative indices can also arise as
intermediate simplification steps produced by `CanonicalSimplifier`,
such as `floormod(-i,2)` being canonicalized to `floormod(i,-2)`.

This commit adds support for negative coefficients in `ModularSet`,
using the same sign convention as is used by `CanonicalSimplifier` for
negative denominators, and adds unit tests to verify that sign
convention.
@Lunderberg
Copy link
Contributor Author

Rebasing onto main to get the bug fix from #13067

@areusch areusch added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it and removed needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it labels Oct 19, 2022
@@ -97,6 +97,8 @@ def test_split_index_simplify():
# cannot simplify mixed case, unless we canonicalize into one mode.
ck.verify(tdiv(x, 6) * 2 + tmod(fld(x, 3), 2), tdiv(x, 6) * 2 + tmod(fld(x, 3), 2))

ck.verify(tmod(-x, 2), tmod(x, -2) * -1)
Copy link
Member

Choose a reason for hiding this comment

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

does this cover modular set analysis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test only covers the CanonicalSimplify behavior of negative indices, but the ModularSet's behavior should be consistent with the sign convention in CanonicalSimplify. Since CanonicalSimplify's sign convention for negative indices wasn't checked by any test I could find, I wanted to add a test for its behavior.

Copy link
Contributor

@jwfromm jwfromm left a comment

Choose a reason for hiding this comment

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

Nice fix, Thanks @Lunderberg!

@jwfromm jwfromm merged commit 0554a46 into apache:main Oct 27, 2022
@Lunderberg Lunderberg deleted the modular_set_negative_arg branch October 28, 2022 14:02
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
Prior to this commit, any use of negative coefficients in `ModularSet`
would result in an error.  This included cases where a constraint is
being entered, such as `floormod(i, -2)==0` appearing as the condition
of an if/else block.  These negative indices can also arise as
intermediate simplification steps produced by `CanonicalSimplifier`,
such as `floormod(-i,2)` being canonicalized to `floormod(i,-2)`.

This commit adds support for negative coefficients in `ModularSet`,
using the same sign convention as is used by `CanonicalSimplifier` for
negative denominators, and adds unit tests to verify that sign
convention.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
Prior to this commit, any use of negative coefficients in `ModularSet`
would result in an error.  This included cases where a constraint is
being entered, such as `floormod(i, -2)==0` appearing as the condition
of an if/else block.  These negative indices can also arise as
intermediate simplification steps produced by `CanonicalSimplifier`,
such as `floormod(-i,2)` being canonicalized to `floormod(i,-2)`.

This commit adds support for negative coefficients in `ModularSet`,
using the same sign convention as is used by `CanonicalSimplifier` for
negative denominators, and adds unit tests to verify that sign
convention.
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.

5 participants