Issue 77171
Summary Other patterns where clang is not optimal for powi (with fast-math)
Labels clang
Assignees
Reporter 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
```c
#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
```c
#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:
https://github.com/llvm/llvm-project/issues/67216
https://github.com/llvm/llvm-project/issues/69862
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to