-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Missed optimization in math expression: sin(asin(a)) == a #34951
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
Comments
The same issue about cos(acos(x)). |
See a lot of optimizations here: https://github.com/gcc-mirror/gcc/blob/07b69d3f1cd3dd8ebb0af1fbff95914daee477d2/gcc/match.pd |
Is this right? sin is periodic, so there's some range reduction here. Maybe this is true only if we know the value is between 0 and 2*pi? |
sin(asin(a)) = a requires: -1 <= a <= 1. Implementing this requires introducing additional cmp instructions, so the question would it actually be better? |
It could be. asin is likely non-trivial to compute. In any case, -ffast-math implies no NaNs, and asin returns NaN outside of [-1:1], so sin(asin(a)) = a seems like a fine fast-math optimization. |
mentioned in issue #34959 |
Extended Description
clang(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags for this code:
generates this assembly:
But sin(asin(a)) == a. So there is no reason to call anything.
The text was updated successfully, but these errors were encountered: