[Bug c/95329] fmaxf(inf, nan) does not always work

2020-05-26 Thread florian at schanda dot org.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95329

--- Comment #3 from Florian Schanda  ---
I have created https://sourceware.org/bugzilla/show_bug.cgi?id=26045

[Bug c/95329] fmaxf(inf, nan) does not always work

2020-05-26 Thread florian at schanda dot org.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95329

--- Comment #2 from Florian Schanda  ---
Cool, thanks for the pointer to their bug tracker. I'll bother them instead ;)

[Bug c/95329] New: fmaxf(inf, nan) does not always work

2020-05-26 Thread florian at schanda dot org.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95329

Bug ID: 95329
   Summary: fmaxf(inf, nan) does not always work
   Product: gcc
   Version: 8.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: florian at schanda dot org.uk
  Target Milestone: ---

Created attachment 48601
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48601&action=edit
Reduced testcase of the fmaxf issue

I've been creating some floating point benchmarks for SMT-LIB. I have noticed
that gcc (or something else) does not produce the same result in some specific
examples. I am on amd64 Debian, but I've also reproduced this on a recent amd64
Ubuntu. Below is a reduced test-case showing this:

#include 
#include 
#include 
#include 

int main()
{
  uint32_t bv = 0x7FACBA7E;
  // (0  0101100101110100110)

  float a, b;
  a = -INFINITY;
  memcpy(&b, &bv, 4);

  printf("max(%f, %f) = %f\n", a, b, fmaxf(a, b));

  b = NAN;
  printf("max(%f, %f) = %f\n", a, b, fmaxf(a, b));
}

When compiling and running this program you get:

max(-inf, nan) = nan
max(-inf, nan) = -inf

I've tried with both:
  gcc bug.c -lm
and
  gcc -std=c99 -frounding-math -fsignaling-nans -ffp-contract=off -mfma
-mno-fma4 -pedantic -Wall -W -msse2 -mfpmath=sse -fstrict-aliasing bug.c -lm


However, IEEE-754 says that max(something not NaN, NaN) should get you the
thing that is not NaN. With the built-in constant it works, but with my
hand-crafted NaN it does not.

I've also tried replacing fmaxf by __builtin_fmaxf, with no success.


I also realise this likely may not be a gcc bug, but something deeper down in
libm or elsewhere. I do note that with clang-9 this works though. However I
suspect you guys will know where exactly this report needs to go to.