[llvm] [InstCombine] - Extend simplifyLibCalls to fold pow(x,2/3f) -> cbrt(x) (PR #214202)

Rohit Aggarwal via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 22:53:18 PDT 2026


rohitaggarwal007 wrote:

> Given that this requires `afn`, I think `cbrt(x) * cbrt(x)` is the nicest choice here since it properly handles zero and infinity, and avoids both underflow/overflow.
> 
> The other "mathematically equivalent" version you could consider is `cbrt(x * x)`. It would be slightly more accurate at 0.667 ulp versus 1.5 ulp, but `x * x` can overflow/underflow.
> 
> The error of `cbrt(x)` is `ulp(x) / 3 + 0.5` and the error of `x * x` is `ulp(x) * 2 + 0.5`:
> 
> * `cbrt(x) * cbrt(x)` is `(ulp(x) / 3 + 0.5) * 2 + 0.5` = `2/3 * ulp(x) + 1.5`
> * `cbrt(x * x)` is `(ulp(x) * 2 + 0.5) / 3 + 0.5` = `2/3 * ulp(x) + 0.667`

Agreed — this patch uses cbrt(x) * cbrt(x) for that reason (signed zero / inf stay well-defined, and we never square x first). I can add a short comment next to the multiply so we don’t later “improve” it to cbrt(x * x) as `x * x` can overflow/underflow

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


More information about the llvm-commits mailing list