[llvm-bugs] [Bug 39112] New: incorrect optimization with signaling NaN and implicit conversion in fabs: missing exception

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 28 04:48:14 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39112

            Bug ID: 39112
           Summary: incorrect optimization with signaling NaN and implicit
                    conversion in fabs: missing exception
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vincent-llvm at vinc17.net
                CC: llvm-bugs at lists.llvm.org

With a code that does something like

  float f = fabs (double_snan)

one does not get the FE_INVALID exception with -O.

Details:

#include <stdio.h>
#include <inttypes.h>
#include <math.h>
#include <fenv.h>

typedef union { float f; uint32_t i; } ieee_float_t;

int main (void)
{
  volatile ieee_float_t x, y;
  volatile double d;

  x.i = 0x7f800001;
  printf ("0. %x (%g)\n", x.i, x.f);

  feclearexcept (FE_INVALID);
  y.f = fabs (x.f);
  if (fetestexcept (FE_INVALID))
    printf ("2. FE_INVALID\n");
  printf ("2. %x (%g)\n", y.i, y.f);

  return 0;
}

yields:

cventin% clang-8 snan.c -o snan -lm
cventin% ./snan
0. 7f800001 (nan)
2. FE_INVALID
2. 7fc00001 (nan)

which is correct (due to the float-to-double conversion of sNaN), but

cventin% clang-8 snan.c -o snan -lm -O
cventin% ./snan                       
0. 7f800001 (nan)
2. 7f800001 (nan)

The FE_INVALID exception is missing, and the result is a signaling NaN instead
of a quiet NaN.

Tested with the clang-8 1:8~svn342638-1 Debian package (x86_64 architecture).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180928/ccc90013/attachment.html>


More information about the llvm-bugs mailing list