Skip to content
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

optimize pow(x, i1) / pow(x, i2) with fast-math #67216

Closed
k-arrows opened this issue Sep 23, 2023 · 0 comments
Closed

optimize pow(x, i1) / pow(x, i2) with fast-math #67216

k-arrows opened this issue Sep 23, 2023 · 0 comments

Comments

@k-arrows
Copy link

Consider the following:

#include <cmath>

double f1(double x)
{
    return pow(x, 2) / pow(x, 1);
}

double f2(double x)
{
    return pow(x, 3) / pow(x, 1);
}

https://godbolt.org/z/jjKE5n8o1
If -Ofast is specified, GCC just calculates x * x for f2, but Clang performs floating-point division.

When I lower the version to Clang 14.0.0, it behaves as expected, has anything changed?

vfdff added a commit to vfdff/llvm-project that referenced this issue Oct 21, 2023
Try to transform the powi(X, Y) / X into powi(X, Y-1) with Ofast.
For this case, when the Y is 3, then powi(X, 2) is replaced by X * X in
the further step.

Fixes llvm#67216
@vfdff vfdff closed this as completed in 7e3d110 Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants