-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Missing copysign(1., x) < 0. to std::signbit(x) fold #48523
Comments
I'm not sure those are equivalent if x is nan. |
Err nevermind I guess they would be. |
Not sure if Alive2 understands copysign (the LLVM instance seems to be dead currently). As IR, we have: define i1 @#49179 (double %x) { And we want to turn it into: %2 = bitcast double %0 to i64 So to generalize (this pattern was found in source code in the wild?): "1.0" can be any non-zero number and "0.0" could also be "-0.0"? |
Thanks for the links! So the "1.0" and "0.0" are the important special-cases to handle. We probably don't need to fully generalize (it would get complicated if we try to handle zeros/NaN as the copysign argument, arbitrary compare predicates, and arbitrary compare constants). |
Should be fixed in IR with: We have seen complications with these kinds of transforms because LLVM supports non-IEEE754-compliant targets, but I think this is always ok. If not, we'll have to move the transform to the backend. As noted in the comments, if variations of the specified pattern are found, please file other bugs. And finally (it's not clear from the description if we care about a particular target), if the performance is still not optimal, we may need to adjust codegen too. For x86, I'm seeing something like this currently:
|
Extended Description
#include
bool foo(double x)
{
return std::copysign(1., x) < 0.;
}
bool bar(double x)
{
return std::signbit(x);
}
https://godbolt.org/z/xPMzj9
The text was updated successfully, but these errors were encountered: