[PATCH] D40150: [LibCallSimplifier] fix pow(x, 0.5) -> sqrt() transforms

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 16:33:25 PST 2017


hfinkel added a comment.

In https://reviews.llvm.org/D40150#928114, @efriedma wrote:

> > This would be a lot simpler if we could disregard errno when we have relaxed FP math, but I'm assuming it's possible to do something like '-ffast-math -fmath-errno' and still expect errno to be set for domain errors?
>
> nnan implies we don't care about the result in cases where it would be nan, so it's probably okay if we lower an nnan "pow(x, 0.5)" to something which never sets errno.  But there's still the underlying problem that the backend can't lower the intrinsics correctly for targets where libm sets errno, so we shouldn't generate libm intrinsics for code which isn't already using them.


We should, at some point soon, come up with a real plan to handle this problem. On systems that don't have appropriate functions, we might generate wrappers that save/restore errno and call those wrappers instead of the libm functions directly. For -gnu systems, we can/should generate calls to __pow_finite instead of pow and similar for other functions (these are in /usr/include/bits/math-finite.h and are what you generally get from math.h when __FINITE_MATH_ONLY__ is positive).


https://reviews.llvm.org/D40150





More information about the llvm-commits mailing list