llvm / llvm/llvm-project

failed to reduce pow() with sqrt() with -ffast-math

Open
#180,948 0 comments 0 reactions 0 assignees View on GitHub
floating-point llvm:optimizations
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```c
#include

double foo(double x) {
return pow(sqrt(x), 4.0);
}
```

This can be reduced to x*x:
https://godbolt.org/z/a78oraYoP

It looks like the special case of pow(N, 2.0) is handled, but all higher exponents are missed. If the pow() is converted to powi() in IR, then there could be another transform to divide the exponent in half?

It also doesn't reduce when the sqrt() follows the pow(), so there's probably a missing pow/sqrt canonicalization:
https://godbolt.org/z/4e1Phv8Y7

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.