https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127649

            Bug ID: 127649
           Summary: wrong code at -O{2,3} loses FE_INVALID on a quiet NaN
                    vectorization
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---

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

#define N 64

static float a[N], b[N];
static int   r[N];

static void ltgt (float *x, float *y, int *z, int n)
{
  for (int i = 0; i < n; i++)
    z[i] = (x[i] < y[i]) | (x[i] > y[i]);
}

int main (void)
{
  for (int i = 0; i < N; i++)
    {
      a[i] = __builtin_nanf ("");   /* quiet NaN */
      b[i] = 1.0f;
    }

  feclearexcept (FE_ALL_EXCEPT);
  ltgt (a, b, r, N);
  printf ("FE_INVALID = %d\n", fetestexcept (FE_INVALID));
  return 0;
}

The code with -O{0,1} sets FE_INVALID after the ltgt call because a is NaN, but
the flag is not set with -O{2,3}.

https://gcc.godbolt.org/z/8q8on8a1e

Reply via email to