[PATCH] Returns NaN for sqrt with negative fp argument
t.p.northover at gmail.com
Mon Jun 9 23:17:30 PDT 2014
On 10 June 2014 02:45, Jiangning Liu <liujiangning1 at gmail.com> wrote:
> IEEE-754 standard requires to return NaN for sqrt with negative fp value
> argument, while llvm now is returning fp zero instead. This patch is to fix
> this issue and spec2006/483.xanlancbmk can pass with -ffast-math for AArch64
> target, but the fix itself is a general one rather than target specific.
This sounds like an expected consequence of -ffast-math. The language
reference specifically says that using @llvm.sqrt on negative numbers
is undefined, and indeed that intrinsic call is only formed from sqrtf
in -ffast-math mode.
> Also, sqrt in glibc behaves like this, and clang is defining __GNUC__, so it
> means we need to keep compatibility with GCC around this as well.
I don't find that compelling, either. Particularly when -ffast-math is
involved, we shouldn't be expected to replicate the precise points
where GCC decides to ignore NaNs and how it does so.
More information about the llvm-commits