Skip to content

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.

@tqchen tqchen merged commit 9f0f301 into apache:main Jul 24, 2024
@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.

4 participants