-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[Opt] Add strength reduction optimizations #1065
Conversation
What about |
Yes if the RHS is a const, then we should do it under fast math.
Sounds good. I think you can do that even without fast math. In Python
We can actually weaken |
What should be the type of
Shall we only optimize this when |
The type should be the return type of the original
Yes. For integeral n and |
Try out |
Cool, but probably doesn't make much sense on my laptop:
|
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.
LGTM! Thanks!
@@ -437,6 +437,23 @@ float64 TypedConstant::val_float() const { | |||
} | |||
} | |||
|
|||
TypedConstant TypedConstant::operator-() const { |
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.
This should be replaced by the JIT evaluator in the future.
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.
Yes. I need this operator because we don't do alg_simp
and constant_fold
iteratively together now.
Related issue = #944
This PR contains:
a * 2 -> a + a, 2 * a -> a + a
(for all types, cast to the original result type)a / const -> a * (1 / const)
(floating point only & fast_math only -- is this necessary?)a ** 1 -> a
(for all types)a ** 0 -> 1
(for all types & fast_math only, cast to the original result type)a ** 2 -> a * a
(for all types, cast to the original result type)Benchmark:
[Click here for the format server]