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][Analyzer] Simplify x==x expressions for all dtypes #17158

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, there was no rule to simplify x == x into True. In some cases, despite not having an explicit rewrite rule in RewriteSimplifier, the RewriteSimplifier::CanProve function would check if x-x simplifies to zero, relying on the rewrite rules used for tir::Sub. However, the rule to rewrite x-x into zero was only enabled for int32, int64, and floating-point types, so relying on this behavior was inconsistent.

This commit updates the rewrite rules for both tir::EQ and tir::Sub to check for simplification of x-x or x==x, regardless of the datatype. This change preserves the fast-path for index data-types, in which int32 and int64 expressions may be simplified without checking for side effects. For all other dtypes, the cancellation only applies when evaluating x has no side effects.

Prior to this commit, there was no rule to simplify `x == x` into
`True`.  In some cases, despite not having an explicit rewrite rule in
`RewriteSimplifier`, the `RewriteSimplifier::CanProve` function would
check if `x-x` simplifies to zero, relying on the rewrite rules used
for `tir::Sub`.  However, the rule to rewrite `x-x` into zero was only
enabled for `int32`, `int64`, and floating-point types, so relying on
this behavior was inconsistent.

This commit updates the rewrite rules for both `tir::EQ` and
`tir::Sub` to check for simplification of `x-x` or `x==x`, regardless
of the datatype.  This change preserves the fast-path for index
data-types, in which `int32` and `int64` expressions may be simplified
without checking for side effects.  For all other dtypes, the
cancellation only applies when evaluating `x` has no side effects.
@Lunderberg Lunderberg requested a review from sunggg July 15, 2024 21:02
Copy link
Contributor

@sunggg sunggg left a comment

Choose a reason for hiding this comment

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

Great catch, @Lunderberg!
LGTM, one question.

src/arith/rewrite_simplify.cc Show resolved Hide resolved
@tqchen tqchen merged commit 9f0f301 into apache:main Jul 24, 2024
19 checks passed
@Lunderberg Lunderberg deleted the tir_simplify_x_equals_x branch July 24, 2024 14:09
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.

None yet

4 participants