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

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 28 17:01:34 PDT 2018


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

Vincent Lefevre <vincent-llvm at vinc17.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |---

--- Comment #3 from Vincent Lefevre <vincent-llvm at vinc17.net> ---
No need to access the floating-point environment to reproduce the bug:

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

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

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

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

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

  return 0;
}

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

With -O, one gets a signaling NaN instead of a quiet NaN.

The bug disappears if one explicitly uses a volatile double as an intermediate
variable (since fabs returns a double, this should not change anything):

#include <stdio.h>
#include <inttypes.h>
#include <math.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);

  d = fabs (x.f);
  y.f = d;
  printf ("2. %x (%g)\n", y.i, y.f);

  return 0;
}

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

-- 
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/20180929/c9ba684b/attachment.html>


More information about the llvm-bugs mailing list