Closed
Description
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);
}