llvm.log/log2/log10 of 0 does not constant fold
Open
floating-point
missed-optimization
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/ehbP4z534
This does not fold out:
```
define float @fold_log2_0() {
%fold = call float @llvm.log2.f32(float 0.0)
ret float %fold
}
```
ConstantFoldFP gives up on this since this raises an exception in the host libcall:
```
2142 double Result = NativeFP(Input.convertToDouble());
2143 if (llvm_fenv_testexcept()) {
-> 2144 llvm_fenv_clearexcept();
2145 return nullptr;
2146 }
```
The constant folding should not care about exceptions. If anything this logic is backwards; it makes more sense to only constant fold the exact special cases of 0, 1 and infinity than rely on the host library implementation
Contributor guide
Assessment
This issue has not been assessed yet.