[llvm] Constant Fold Logf128 calls (PR #84501)

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 08:41:55 PDT 2024


MDevereau wrote:

To give some context as to why this is desirable, there's been instances where calls to long double have been generated when they should be constant folded. As they are 128-bit floats on aarch64 these calls end up being particularly slow compared to targets where the `long double` type is 64 bits in length.

The mersenne twister in libstdc++ contains this code:
```c++
const long double __r = static_cast<long double>(__urng.max())        
                      - static_cast<long double>(__urng.min()) + 1.0L;
const size_t __log2r = std::log(__r) / std::log(2.0L);  
```
GCC will constant fold both calls to logl here but clang will keep the calls. The proposed approach in the pull request is in thoery an easy-win which other systems could also benefit from.

https://github.com/llvm/llvm-project/pull/84501


More information about the llvm-commits mailing list