I have a question about the latest GCC compilers (version >= 5) with this code:
#include <math.h>void test_nan ( const float * const __restrict__ in, const int n, char * const __restrict__ out ){ for (int i = 0; i < n; ++i) out[i] = isnan(in[i]);}
The assembly listing from GCC:
test_nan: movq %rdx, %rdi testl %esi, %esi jle .L1 movslq %esi, %rdx xorl %esi, %esi jmp memset.L1: ret
This looks like memset(out, 0, n)
.Why does GCC assume that no entries can be NaN with -Ofast ?With the same compilation options, ICC does not show this issue.With GCC, the issue goes away with "-O3".
Note that with "-O3", this query gcc -c -Q -O3 --help=optimizers | egrep -i nan
gives -fsignaling-nans [disabled]
.
I verified this both locally and on godbolt, with the additional option "-std=c99".
Edit: by following the helpful answers below I can confirm that -Ofast -std=c99 -fno-finite-math-only
properly addresses this issue.