https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101683
Bug ID: 101683 Summary: Floating point exception for double->unsigned conversion on avx512 only Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: bartoldeman at users dot sourceforge.net Target Milestone: --- Created attachment 51222 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51222&action=edit File to reproduce For this code: #define _GNU_SOURCE #include <fenv.h> int main(int argc, char **argv) { feenableexcept(FE_INVALID); double argcm10 = argc / -0.1; return (unsigned)(argcm10 < 0.0 ? 0 : argcm10); } $ gcc -O -march=skylake-avx512 fpexcept.c -lm $ ./a.out Floating point exception the instructions vcvttsd2usi %xmm0, %eax vxorpd %xmm1, %xmm1, %xmm1 vucomisd %xmm0, %xmm1 movl $0, %edx cmova %edx, %eax are generated just after the division, so the conversion happens before the comparison. "If a converted result cannot be represented in the destination format, the floating-point invalid exception is raised, and if this exception is masked, the integer value 2^w – 1 is returned, where w represents the number of bits in the destination format." so when masked, for argcm10 = -10.0 the value 2^w-1 is discarded and all is well, since it's < 0, but not when unmasked. I can reproduce this issue with 9.3 as well, but not with 8.4 (the generated code is correct for 8.4). I have not tried 11.1 yet. Note: I found this issue with the UCX library when compiled with -march=skylake-avx512, this example is stripped down from: https://github.com/openucx/ucx/blob/f5362f5e6f80d930b88c44c63b4d8d71cf91d214/src/ucp/core/ucp_ep.c#L2699