fast-math: fix a bug related to square roots of negatives

Octav Zlatior via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 11:15:39 PDT 2016


Hi,

I have noticed the following behaviour while running the SPEC benchmark suite (built with llvm, of course). One of the tests was failing (Xalanc) with a segfault (because of stack overflow) because the terminating condition for a recursion involved NaN.

I've checked a little further and I have noticed that, with fast-math, the square roots of negative numbers will sometimes be replaced with "return undef". But only sometimes, and only the square roots (for example, log(x) does not manifest this behaviour).

It turns out a rather common way of getting the value of NaN in code is to assign it the return value of sqrt(<negative number>). Because of this bug, any such assignments will basically result undefined values.

These two patches should provide a fix for this. The first is a test to illustrate the situation (the negative functions will be replaced with return undef in the IR), while the other is a fix for this bug.

Best regards,
Octav


—
Octav Zlatior
Theobroma Systems Design und Consulting GmbH
Seestadtstrasse 27, 1220 Wien, Austria
Phone: +43 1 2369893-407
http://www.theobroma-systems.com






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161104/2fbc1252/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-test-Implements-test-for-sqrt-with-ffast-math.patch
Type: application/octet-stream
Size: 2143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161104/2fbc1252/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161104/2fbc1252/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-codegen-Fixes-undefined-value-for-sqrt-negative-with.patch
Type: application/octet-stream
Size: 1277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161104/2fbc1252/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161104/2fbc1252/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161104/2fbc1252/attachment.sig>


More information about the llvm-commits mailing list