-
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
[Arith] Simplify cast #7045
[Arith] Simplify cast #7045
Conversation
cc @merrymercy @yzhliu @kazum @ZihengJiang can you please help to take a look? |
cc @hzfan please update per review comments |
@junrushao1994 I just fixed the macro thing and CI's green. Please take another look. |
It looks good on my side. @yzhliu would you mind taking a look? Thanks! |
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.
Some more comments to improve readability after carefully read the PR.
src/arith/canonical_simplify.cc
Outdated
@@ -77,6 +77,25 @@ inline PrimExpr DivImpl(PrimExpr a, PrimExpr b, DivMode mode) { | |||
} | |||
} | |||
|
|||
bool CheckCastImpl(DataType dtype, PrimExpr value, Analyzer* analyzer) { |
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.
Perhaps rename to UpcastIsSafe?
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.
document this function
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.
I guess CastIsSafe seems better, since it checks both upcast and downcast
Thanks @hzfan for keep polishing the code :) Arith analysis is quite core to most of our transformations so it is important to make sure code is clean and readable I have carefully read the PR and add a few more comments to improve readability. @junrushao1994 @yzhliu It would be great to also have you take another look as well. |
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.
some final comments
Thanks @hzfan @junrushao1994 ! This is now merged |
Follow up of #6691
Simplify
cast(i32, c * 2 + 1) + 1 - cast(i32, c * 2)
to2
by first transforming tocast(i32, c * 2) + cast(i32, 1) + 1 - cast(i32, c * 2)