public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception
@ 2020-05-17  0:23 samuel.thibault@ens-lyon.org
  2020-05-17  0:25 ` [Bug c/95169] " samuel.thibault@ens-lyon.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: samuel.thibault@ens-lyon.org @ 2020-05-17  0:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95169
           Summary: i386 comparison between nan and 0.0 triggers Invalid
                    operation exception
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: samuel.thibault@ens-lyon.org
  Target Milestone: ---

Created attachment 48549
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48549&action=edit
testcase

Hello,

On building the attached testcase with 

gcc-10 -m32 test.c -o test -march=i386 -mtune=generic -lm

its execution prints "0 1", i.e. an Invalid operation exception is raised by
the mere comparison of y (that contains NaN) against 0.0.

This was tested with Debian's gcc-10 10.1.0-1.
This does not happen with previous versions of gcc. This happens with half of
the  values of -mtune (I'll attach the details) ; this also happens with
-march=i486, i586, pentium ; this does not happen with -march=i686 or
pentiumpro etc. (whatever the value of -mtune).

Samuel

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

* [Bug c/95169] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
@ 2020-05-17  0:25 ` samuel.thibault@ens-lyon.org
  2020-05-17  0:26 ` samuel.thibault@ens-lyon.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: samuel.thibault@ens-lyon.org @ 2020-05-17  0:25 UTC (permalink / raw)
  To: gcc-bugs

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

Samuel Thibault <samuel.thibault@ens-lyon.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |9.3.0
      Known to fail|                            |10.1.0
             Target|                            |i386-linux-gnu
              Build|                            |i386-linux-gnu
               Host|                            |i386-linux-gnu

--- Comment #1 from Samuel Thibault <samuel.thibault@ens-lyon.org> ---
Here is the disassemble of -march=i386 -mtune=generic, which raises the
exception:

Dump of assembler code for function f:
   0x000011b9 <+0>:     push   %ebp
   0x000011ba <+1>:     mov    %esp,%ebp
   0x000011bc <+3>:     push   %ebx
   0x000011bd <+4>:     sub    $0x14,%esp
   0x000011c0 <+7>:     call   0x11b5 <__x86.get_pc_thunk.dx>
   0x000011c5 <+12>:    add    $0x2e3b,%edx
   0x000011cb <+18>:    mov    0x8(%ebp),%eax
   0x000011ce <+21>:    mov    %eax,-0x10(%ebp)
   0x000011d1 <+24>:    mov    0xc(%ebp),%eax
   0x000011d4 <+27>:    mov    %eax,-0xc(%ebp)
   0x000011d7 <+30>:    fldl   -0x10(%ebp)
   0x000011da <+33>:    fldz   
   0x000011dc <+35>:    fucompp 
   0x000011de <+37>:    fnstsw %ax
   0x000011e0 <+39>:    sahf   
   0x000011e1 <+40>:    setnp  %cl
   0x000011e4 <+43>:    fldz   
   0x000011e6 <+45>:    fcompl -0x10(%ebp)
   0x000011e9 <+48>:    fnstsw %ax
   0x000011eb <+50>:    sahf   
   0x000011ec <+51>:    setne  %al
   0x000011ef <+54>:    sub    $0x1,%eax
   0x000011f2 <+57>:    and    %ecx,%eax
   0x000011f4 <+59>:    movzbl %al,%eax
   0x000011f7 <+62>:    test   %eax,%eax
   0x000011f9 <+64>:    je     0x120f <f+86>
   0x000011fb <+66>:    sub    $0xc,%esp
   0x000011fe <+69>:    lea    -0x1ff8(%edx),%eax
   0x00001204 <+75>:    push   %eax
   0x00001205 <+76>:    mov    %edx,%ebx
   0x00001207 <+78>:    call   0x1040 <puts@plt>
   0x0000120c <+83>:    add    $0x10,%esp
   0x0000120f <+86>:    nop
   0x00001210 <+87>:    mov    -0x4(%ebp),%ebx
   0x00001213 <+90>:    leave  
   0x00001214 <+91>:    ret

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

* [Bug c/95169] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
  2020-05-17  0:25 ` [Bug c/95169] " samuel.thibault@ens-lyon.org
@ 2020-05-17  0:26 ` samuel.thibault@ens-lyon.org
  2020-05-17  1:06 ` [Bug target/95169] " samuel.thibault@ens-lyon.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: samuel.thibault@ens-lyon.org @ 2020-05-17  0:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Samuel Thibault <samuel.thibault@ens-lyon.org> ---
Here are the results with -march=i386 -mtune=$i.

"0 1" thus means an exception is raised

i386 0 0                  
i486 0 0
i586 0 0
pentium 0 0
lakemont 0 0
pentium-mmx 0 0
winchip-c6 0 0
winchip2 0 0
c3 0 0
samuel-2 0 0
c3-2 0 0
nehemiah 0 0
c7 0 0
esther 0 0
i686 0 0
pentiumpro 0 0
pentium2 0 0
pentium3 0 0
pentium3m 0 0
pentium-m 0 0
pentium4 0 0
pentium4m 0 0
prescott 0 0
nocona 0 0
core2 0 1
nehalem 0 1
corei7 0 1
westmere 0 1
sandybridge 0 1
corei7-avx 0 1
ivybridge 0 1
core-avx-i 0 1
haswell 0 1
core-avx2 0 1
broadwell 0 1
skylake 0 1
skylake-avx512 0 1
cannonlake 0 1
icelake-client 0 1
icelake-server 0 1
cascadelake 0 1
tigerlake 0 1
cooperlake 0 1
bonnell 0 1
atom 0 1
silvermont 0 1
slm 0 1
goldmont 0 1
goldmont-plus 0 1
tremont 0 1
knl 0 1
knm 0 1
intel 0 1
geode 0 0
k6 0 0
k6-2 0 0
k6-3 0 0
athlon 0 0
athlon-tbird 0 0
athlon-4 0 0
athlon-xp 0 0
athlon-mp 0 0
x86-64 cc1: warning: ‘-mtune=x86-64’ is deprecated; use ‘-mtune=k8’ or
‘-mtune=generic’ instead as appropriate [-Wdeprecated]
0 1
eden-x2 0 1
nano 0 1
nano-1000 0 1
nano-2000 0 1
nano-3000 0 1
nano-x2 0 1
eden-x4 0 1
nano-x4 0 1
k8 0 1
k8-sse3 0 1
opteron 0 1
opteron-sse3 0 1
athlon64 0 1
athlon64-sse3 0 1
athlon-fx 0 1
amdfam10 0 0
barcelona 0 0
bdver1 0 0
bdver2 0 0
bdver3 0 0
bdver4 0 0
znver1 0 0
znver2 0 0
btver1 0 0
btver2 0 0
generic 0 1
native 0 1

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

* [Bug target/95169] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
  2020-05-17  0:25 ` [Bug c/95169] " samuel.thibault@ens-lyon.org
  2020-05-17  0:26 ` samuel.thibault@ens-lyon.org
@ 2020-05-17  1:06 ` samuel.thibault@ens-lyon.org
  2020-05-17  1:59 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: samuel.thibault@ens-lyon.org @ 2020-05-17  1:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Samuel Thibault <samuel.thibault@ens-lyon.org> ---
And for comparison, here is the disassemble of -march=i686 -mtune=generic,
which does not raise the exception:

Dump of assembler code for function f:
   0x000011b9 <+0>:     push   %ebp
   0x000011ba <+1>:     mov    %esp,%ebp
   0x000011bc <+3>:     push   %ebx
   0x000011bd <+4>:     sub    $0x14,%esp
   0x000011c0 <+7>:     call   0x1292 <__x86.get_pc_thunk.ax>
   0x000011c5 <+12>:    add    $0x2e3b,%eax
   0x000011ca <+17>:    mov    0x8(%ebp),%edx
   0x000011cd <+20>:    mov    %edx,-0x10(%ebp)
   0x000011d0 <+23>:    mov    0xc(%ebp),%edx
   0x000011d3 <+26>:    mov    %edx,-0xc(%ebp)
   0x000011d6 <+29>:    fldl   -0x10(%ebp)
   0x000011d9 <+32>:    fldz   
   0x000011db <+34>:    fucomip %st(1),%st
   0x000011dd <+36>:    fstp   %st(0)
   0x000011df <+38>:    setnp  %dl
   0x000011e2 <+41>:    mov    $0x0,%ecx
   0x000011e7 <+46>:    fldl   -0x10(%ebp)
   0x000011ea <+49>:    fldz   
   0x000011ec <+51>:    fucomip %st(1),%st
   0x000011ee <+53>:    fstp   %st(0)
   0x000011f0 <+55>:    cmovne %ecx,%edx
   0x000011f3 <+58>:    movzbl %dl,%edx
   0x000011f6 <+61>:    test   %edx,%edx
   0x000011f8 <+63>:    je     0x120e <f+85>
   0x000011fa <+65>:    sub    $0xc,%esp
   0x000011fd <+68>:    lea    -0x1ff8(%eax),%edx
   0x00001203 <+74>:    push   %edx
   0x00001204 <+75>:    mov    %eax,%ebx
   0x00001206 <+77>:    call   0x1040 <puts@plt>
   0x0000120b <+82>:    add    $0x10,%esp
   0x0000120e <+85>:    nop
   0x0000120f <+86>:    mov    -0x4(%ebp),%ebx
   0x00001212 <+89>:    leave  
   0x00001213 <+90>:    ret

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

* [Bug target/95169] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
                   ` (2 preceding siblings ...)
  2020-05-17  1:06 ` [Bug target/95169] " samuel.thibault@ens-lyon.org
@ 2020-05-17  1:59 ` pinskia at gcc dot gnu.org
  2020-05-17 18:32 ` ubizjak at gmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-17  1:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
   0x000011e6 <+45>:    fcompl -0x10(%ebp)
   0x000011e9 <+48>:    fnstsw %ax
   0x000011eb <+50>:    sahf   

That is what raises the invalid-operation exception

#(insn 23 56 24 2 (set (reg:HI 0 ax [99])
#        (unspec:HI [
#                (compare:CCFP (reg:DF 8 st)
#                    (mem/c:DF (plus:SI (reg/f:SI 6 bp)
#                            (const_int -16 [0xfffffffffffffff0])) [1 y+0 S8
A64]))
#            ] UNSPEC_FNSTSW)) "t6.c":6:25 23 {*cmpdf_i387}
#     (expr_list:REG_DEAD (reg:DF 8 st)
#        (nil)))
        fcompl  -16(%ebp)       # 23    [c=20 l=16]  *cmpdf_i387

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

* [Bug target/95169] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
                   ` (3 preceding siblings ...)
  2020-05-17  1:59 ` pinskia at gcc dot gnu.org
@ 2020-05-17 18:32 ` ubizjak at gmail dot com
  2020-05-17 18:58 ` ubizjak at gmail dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2020-05-17 18:32 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-05-17
   Target Milestone|---                         |10.2

--- Comment #5 from Uroš Bizjak <ubizjak at gmail dot com> ---
There are two places in i386-expand.c that say:

  /* We may be reversing unordered compare to normal compare, that
     is not valid in general (we may convert non-trapping condition
     to trapping one), however on i386 we currently emit all
     comparisons unordered.  */

This is not the case anymore.

The compilation hits this place.

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

* [Bug target/95169] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
                   ` (4 preceding siblings ...)
  2020-05-17 18:32 ` ubizjak at gmail dot com
@ 2020-05-17 18:58 ` ubizjak at gmail dot com
  2020-05-18 15:53 ` [Bug target/95169] [10/11 Regression] " cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2020-05-17 18:58 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ubizjak at gmail dot com
             Status|NEW                         |ASSIGNED

--- Comment #6 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 48551
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48551&action=edit
Prototype patch

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

* [Bug target/95169] [10/11 Regression] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
                   ` (5 preceding siblings ...)
  2020-05-17 18:58 ` ubizjak at gmail dot com
@ 2020-05-18 15:53 ` cvs-commit at gcc dot gnu.org
  2020-05-21 17:37 ` cvs-commit at gcc dot gnu.org
  2020-05-21 18:43 ` ubizjak at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-18 15:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:8f17461bdfeed758f2be71529fc3af55a76ea3e1

commit r11-457-g8f17461bdfeed758f2be71529fc3af55a76ea3e1
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Mon May 18 17:52:14 2020 +0200

    i386: Avoid reversing a non-trapping comparison to a trapping one [PR95169]

    gcc/ChangeLog:

            PR target/95169
            * config/i386/i386-expand.c (ix86_expand_int_movcc):
             Avoid reversing a non-trapping comparison to a trapping one.

    testsuite/ChangeLog:

            PR target/95169
            * gcc.target/i386/pr95169.c: New test.

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

* [Bug target/95169] [10/11 Regression] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
                   ` (6 preceding siblings ...)
  2020-05-18 15:53 ` [Bug target/95169] [10/11 Regression] " cvs-commit at gcc dot gnu.org
@ 2020-05-21 17:37 ` cvs-commit at gcc dot gnu.org
  2020-05-21 18:43 ` ubizjak at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-21 17:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:ddfb80adbd91a0e45cc6e04a8b0dbe3ca15ba45f

commit r10-8167-gddfb80adbd91a0e45cc6e04a8b0dbe3ca15ba45f
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Thu May 21 19:36:32 2020 +0200

    i386: Avoid reversing a non-trapping comparison to a trapping one [PR95169]

    2020-05-21  Uroš Bizjak  <ubizjak@gmail.com>

    gcc/ChangeLog:
            PR target/95169
            * config/i386/i386-expand.c (ix86_expand_int_movcc):
             Avoid reversing a non-trapping comparison to a trapping one.

    gcc/testsuite/ChangeLog:
            PR target/95169
            * gcc.target/i386/pr95169.c: New test.

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

* [Bug target/95169] [10/11 Regression] i386 comparison between nan and 0.0 triggers Invalid operation exception
  2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
                   ` (7 preceding siblings ...)
  2020-05-21 17:37 ` cvs-commit at gcc dot gnu.org
@ 2020-05-21 18:43 ` ubizjak at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2020-05-21 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #9 from Uroš Bizjak <ubizjak at gmail dot com> ---
Fixed for gcc-10.2+.

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

end of thread, other threads:[~2020-05-21 18:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-17  0:23 [Bug c/95169] New: i386 comparison between nan and 0.0 triggers Invalid operation exception samuel.thibault@ens-lyon.org
2020-05-17  0:25 ` [Bug c/95169] " samuel.thibault@ens-lyon.org
2020-05-17  0:26 ` samuel.thibault@ens-lyon.org
2020-05-17  1:06 ` [Bug target/95169] " samuel.thibault@ens-lyon.org
2020-05-17  1:59 ` pinskia at gcc dot gnu.org
2020-05-17 18:32 ` ubizjak at gmail dot com
2020-05-17 18:58 ` ubizjak at gmail dot com
2020-05-18 15:53 ` [Bug target/95169] [10/11 Regression] " cvs-commit at gcc dot gnu.org
2020-05-21 17:37 ` cvs-commit at gcc dot gnu.org
2020-05-21 18:43 ` ubizjak at gmail dot com

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