public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/101683] New: Floating point exception for double->unsigned conversion on avx512 only
@ 2021-07-30  2:30 bartoldeman at users dot sourceforge.net
  2021-07-30  2:40 ` [Bug rtl-optimization/101683] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bartoldeman at users dot sourceforge.net @ 2021-07-30  2:30 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-02 14:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30  2:30 [Bug target/101683] New: Floating point exception for double->unsigned conversion on avx512 only bartoldeman at users dot sourceforge.net
2021-07-30  2:40 ` [Bug rtl-optimization/101683] " pinskia at gcc dot gnu.org
2021-07-30  2:41 ` pinskia at gcc dot gnu.org
2021-07-30  2:47 ` pinskia at gcc dot gnu.org
2021-07-30  6:17 ` rguenth at gcc dot gnu.org
2021-07-30  6:24 ` pinskia at gcc dot gnu.org
2021-07-30 11:25 ` bartoldeman at users dot sourceforge.net
2021-08-02 14:47 ` cvs-commit at gcc dot gnu.org
2021-08-02 14:49 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).