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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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 ` pinskia at gcc dot gnu.org
  2021-07-30  2:41 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-30  2:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Trapping math is turned on by default ....
I wonder why ifcvt.c is doing the cmov ...

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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-30  2:41 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-30
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
if-conversion succeeded through noce_try_cmove_arith

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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-30  2:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=9651
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Simple fix:
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index ec7a062829c..1ff701d6d4f 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -3261,6 +3261,7 @@ may_trap_p_1 (const_rtx x, unsigned flags)
       break;

     case FIX:
+    case UNSIGNED_FIX:
       /* Conversion of floating point might trap.  */
       if (flag_trapping_math && HONOR_NANS (XEXP (x, 0)))
        return 1;

This has always been a bug .....

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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-30  6:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
eh, guess nothing implemented UNSIGNED_FIX ...

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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-30  6:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> eh, guess nothing implemented UNSIGNED_FIX ...

Just looked, no; just happened nobody ran into this until now.  Either because
of luck or really not many people care about floating point exceptions.

I think it is the later.

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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: bartoldeman at users dot sourceforge.net @ 2021-07-30 11:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from bartoldeman at users dot sourceforge.net ---
"really not many people care about floating point exceptions". I think more
people should :) but this is indeed the context.

We found this issue on a supercomputer running OpenFOAM (which can enable FP
exceptions, see https://cpp.openfoam.org/v3/a02284.html), and a small simple
MPI program with FP exceptions enabled. Even then it crashed in an underlying
library, and not OpenFOAM itself, see
https://github.com/ComputeCanada/software-stack/issues/74

In the end the combination of MPI and FP exceptions easily triggers it, but the
vast majority of jobs don't crash, so even on our cluster this is very rare
indeed. And many other clusters don't compile the UCX library with avx512
optimizations enabled or use precompiled binaries without those enabled.

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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-02 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:99b520f031c0e491d7e170916df11dd645d60617

commit r12-2659-g99b520f031c0e491d7e170916df11dd645d60617
Author: Andrew Pinski <apinski@marvell.com>
Date:   Thu Jul 29 19:48:46 2021 -0700

    Fix PR 101683: FP exceptions for float->unsigned

    Just like the old bug PR9651, unsigned_fix rtl should
    also be handled as a trapping instruction.

    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

    gcc/ChangeLog:

            PR rtl-optimization/101683
            * rtlanal.c (may_trap_p_1): Handle UNSIGNED_FIX.

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

* [Bug rtl-optimization/101683] Floating point exception for double->unsigned conversion on avx512 only
  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
                   ` (6 preceding siblings ...)
  2021-08-02 14:47 ` cvs-commit at gcc dot gnu.org
@ 2021-08-02 14:49 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-02 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 12.

^ 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).