[PATCH] Returns NaN for sqrt with negative fp argument

Jiangning Liu liujiangning1 at gmail.com
Fri Jun 13 00:02:32 PDT 2014


> Could we handle this the same way the cttz intrinsic is handled and add an
> i1 parameter for the < -0.0 behavior of sqrt? The given reason for having
> this be undefined is to allow it to be used for a wider variety of
> architectures’ misbehaving sqrt instructions, but on R600 for example the
> R600 the sqrt instructions always do “the right thing”

Are you saying R600 sqrt can return NaN for negative number? If yes, I
think both X86 and AArch64 can return NaN for sqrt with negative number.

I think llvm.sqrt is different from llvm.cttz. llvm.cttz needs a i1
argument, because some architectures don't have a real zero representation,
while for sqrt I can see all architectures are having NaN returned for
negative number, but the problem is -ffast-math semantic is to not having
NaN involved in program.

I think I'm convinced that we should return undef for sqrt with negative
number, to make static behavior in LLVM IR clearly highlighted.


> -Matt
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140613/cb4c273d/attachment.html>

More information about the llvm-commits mailing list