-
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] Additional Stmt/Expr simplication rules #11373
Changes from 4 commits
e6f0238
f38b09c
bd7e8cd
c743559
069fba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,6 +256,14 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const SubNode* op) { | |
TVM_TRY_REWRITE(broadcast(x, lanes) - broadcast(y, lanes), broadcast(x - y, lanes)); | ||
} | ||
|
||
// cancelation rules | ||
TVM_TRY_REWRITE_IF(x - x, ZeroWithTypeLike(x), | ||
SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF((x + y) - y, x, SideEffect(y.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF((x + y) - x, y, SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF(x - (y + x), 0 - y, SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF(x - (x + y), 0 - y, SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
|
||
if (IsIndexType(op->dtype)) { | ||
// Index rules | ||
// cancelation rules | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The integer simplifcation should be fast path (and clean, hopefully without Nans), it would be better to put new rules in else branch even if it means some duplications, since (recursively) checking side effects is expensive.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable, and updated as requested. |
||
|
@@ -411,6 +419,15 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const SubNode* op) { | |
TVM_TRY_RECURSIVE_REWRITE((x + c1) - y, (x - y) + c1); | ||
TVM_TRY_RECURSIVE_REWRITE(x - (y - z), (x + z) - y); | ||
TVM_TRY_RECURSIVE_REWRITE(x - y * c1, x + y * (0 - c1)); | ||
} else if (op->dtype.is_float()) { | ||
// Cancellation rules. Deliberately off of the integer path, to | ||
// avoid introducing checks on the side effects for the fast path. | ||
TVM_TRY_REWRITE_IF(x - x, ZeroWithTypeLike(x), | ||
SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF((x + y) - y, x, SideEffect(y.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF((x + y) - x, y, SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF(x - (y + x), 0 - y, SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
TVM_TRY_REWRITE_IF(x - (x + y), 0 - y, SideEffect(x.Eval()) <= CallEffectKind::kReadState); | ||
} | ||
|
||
// condition rules. | ||
|
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.
should this be removed since you've added the else branch?
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.
Thank you for the catch, and they are now removed.