Skip to content

Other patterns where clang is not optimal for powi (with fast-math) #77171

Closed
@k-arrows

Description

@k-arrows

There have been a few missed-optimization issues with pow(x, n) where n is an integer. Here, I will provide some other patterns which aren't mentioned in the existing issues.

Test case(1):
https://godbolt.org/z/WGdxTWK6G

#include<math.h>

double f1(double a)
{
   return pow(a, 5) / pow(a, 2);
}

double g1(double a)
{
   return pow(a, 3);
}

If we rewrite / pow(a, 2) as * pow(a, -2), we won't have a problem.

Test case(2):
https://godbolt.org/z/W6nWzhfss

#include<math.h>

double f2(double a, double b)
{
   return pow(a, -2) * pow(b, -2);
}

double g2(double a, double b)
{
   return pow(a * b, -2);
}

Related existing issues:
#67216
#69862

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions