-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
"square can be computed more efficiently" is wrong #7058
Comments
@clarfonthey or @thiagoarrais do you have any input? |
I believe that this may be a new optimisation -- does it really always generate the same code now? |
I actually checked with Godbolt and In fact, even |
Could it be architecture-dependant? |
Not sure - it's certainly possible, but I haven't found one where this wouldn't hold on any mainstream arch. Plus, as noted above, it uses a compiler intrinsic under the hood, which I'd assume to always be implemented whatever's most efficient on each supported platform. |
Seems like we have sufficient info to not lint this case. |
@rustbot claim |
Lint name:
suboptimal_flops
I tried this code:
I expected to see this happen: it should pass.
Instead, this happened: it says "square can be computed more efficiently" and suggests to use
x * x
instead.This is incorrect, because, unlike
powf
,powi
produces exactly same native code asx * x
, and is more natural to read (IMO). If anything, due to usage of intrinsic, it might be optimised even more than bare expression, although they're unlikely to be different on practice.Meta
cargo clippy -V
: clippy 0.1.53 (2e495d2 2021-04-08)rustc -Vv
:The text was updated successfully, but these errors were encountered: