public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math
@ 2004-12-21 20:36 Thomas dot Koenig at online dot de
  2004-12-21 20:45 ` [Bug middle-end/19116] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Thomas dot Koenig at online dot de @ 2004-12-21 20:36 UTC (permalink / raw)
  To: gcc-bugs

$ cat nan-find.f90
program main
  real :: a,b,c
  logical :: l
  b = 0.
  c = 0.
  a = b/c
  call nanfind(a,a,l)
  if (l) then
     print *,a,"compares equal to itself"
  else
     print *,a,"compares unequal to itself"
  end if
end program main

subroutine nanfind(a,b,l)
  real,intent(in) :: a,b
  logical, intent(out) :: l
  l = a == b
end subroutine nanfind
$ gfortran -O3 -ffast-math -fno-finite-math-only nan-find.f90
$ ./a.out
            NaN compares equal to itself
$ gfortran -v
Using built-in specs.
Configured with: ../gcc/configure --prefix=/home/ig25
--enable-languages=c,c++,f95 : (reconfigured) ../gcc/configure
--prefix=/home/ig25 --enable-languages=c,c++,f95
Thread model: posix
gcc version 4.0.0 20041221 (experimental)
$

Then again, I never liked the fact that NaNs can compare
equal with any compiler option...

-- 
           Summary: -fno-finite-math-only does not override -ffast-math
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: driver
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Thomas dot Koenig at online dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug middle-end/19116] -fno-finite-math-only does not override -ffast-math
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
@ 2004-12-21 20:45 ` pinskia at gcc dot gnu dot org
  2004-12-21 21:03 ` Thomas dot Koenig at online dot de
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-21 20:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-21 20:45 -------
Hmm, this works for me on the mainline on powerpc-darwin.  What target is this?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|driver                      |middle-end
            Summary|-fno-finite-math-only does  |-fno-finite-math-only does
                   |not override -ffast-math    |not override -ffast-math


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug middle-end/19116] -fno-finite-math-only does not override -ffast-math
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
  2004-12-21 20:45 ` [Bug middle-end/19116] " pinskia at gcc dot gnu dot org
@ 2004-12-21 21:03 ` Thomas dot Koenig at online dot de
  2004-12-25 14:32 ` Thomas dot Koenig at online dot de
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas dot Koenig at online dot de @ 2004-12-21 21:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From Thomas dot Koenig at online dot de  2004-12-21 21:02 -------
(In reply to comment #1)
> Hmm, this works for me on the mainline on powerpc-darwin.  What target is this?

I was used to gfortran -v telling me that... i686-pc-linux-gnu.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug middle-end/19116] -fno-finite-math-only does not override -ffast-math
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
  2004-12-21 20:45 ` [Bug middle-end/19116] " pinskia at gcc dot gnu dot org
  2004-12-21 21:03 ` Thomas dot Koenig at online dot de
@ 2004-12-25 14:32 ` Thomas dot Koenig at online dot de
  2004-12-25 22:17 ` Thomas dot Koenig at online dot de
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas dot Koenig at online dot de @ 2004-12-25 14:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From Thomas dot Koenig at online dot de  2004-12-25 14:32 -------
I find strange that the C equivalent does not
compare an NaN equal to itself, even with
-O3 -ffast-math :
$ cat nan-check.c
#include <stdio.h>
#include <math.h>

int equality(double a, double b);

int main()
{
    double a, b, c;
    a = 0.0;
    b = 0.0;
    c = a/b;
    if (equality(c,c)) {
        printf("%f compares equal to itself\n",c);
    }
    else {
        printf("%f compares unequal to itself\n",c);
    }
    return 0;
}

int equality(double a, double b)
{
    return a==b;
}
$ gcc -O3 -ffast-math nan-check.c
$ ./a.out
nan compares unequal to itself
$ gcc -v
Using built-in specs.
Configured with: ../gcc/configure --prefix=/home/ig25 --enable-languages=c,c++,f95
Thread model: posix
gcc version 4.0.0 20041224 (experimental)

... with i686-pc-linux-gnu.

Maybe the Fortran frontend does something different with FP
comparisons.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug middle-end/19116] -fno-finite-math-only does not override -ffast-math
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
                   ` (2 preceding siblings ...)
  2004-12-25 14:32 ` Thomas dot Koenig at online dot de
@ 2004-12-25 22:17 ` Thomas dot Koenig at online dot de
  2004-12-25 22:29 ` [Bug target/19116] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas dot Koenig at online dot de @ 2004-12-25 22:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From Thomas dot Koenig at online dot de  2004-12-25 22:17 -------
It is actually possible to reproduce the
Fortran behavior in C:

$ cat nan-check2.c
#include <stdio.h>
#include <math.h>

int equality(double *a, double *b);

int main()
{
    double a, b, c;
    a = 0.0;
    b = 0.0;
    c = a/b;
    if (equality(&c,&c)) {
        printf("%f compares equal to itself\n",c);
    }
    else {
        printf("%f compares unequal to itself\n",c);
    }
    return 0;
}

int equality(double *a, double *b)
{
    return *a==*b;
}
$ gcc nan-check2.c
$ ./a.out
nan compares unequal to itself
$ gcc -ffast-math nan-check2.c
$ ./a.out
nan compares equal to itself
$ gcc -ffast-math -fno-finite-math-only nan-check2.c
$ ./a.out
nan compares equal to itself
$ gcc -v
Using built-in specs.
Configured with: ../gcc/configure --prefix=/home/ig25 --enable-languages=c,c++,f95
Thread model: posix
gcc version 4.0.0 20041224 (experimental)
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug target/19116] -fno-finite-math-only does not override -ffast-math
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
                   ` (3 preceding siblings ...)
  2004-12-25 22:17 ` Thomas dot Koenig at online dot de
@ 2004-12-25 22:29 ` pinskia at gcc dot gnu dot org
  2004-12-27  0:41 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-25 22:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-25 22:29 -------
Hmm, again this works for me on powerpc-darwin.
This is a target bug.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|middle-end                  |target
     Ever Confirmed|                            |1
 GCC target triplet|                            |i686-pc-linux-gnu
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2004-12-25 22:29:49
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug target/19116] -fno-finite-math-only does not override -ffast-math
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
                   ` (4 preceding siblings ...)
  2004-12-25 22:29 ` [Bug target/19116] " pinskia at gcc dot gnu dot org
@ 2004-12-27  0:41 ` pinskia at gcc dot gnu dot org
  2004-12-27 10:26 ` Thomas dot Koenig at online dot de
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-27  0:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-27 00:41 -------
Can you try just -funsafe-math-optimizations and see what happens I think you will get the same 
results as "-ffast-math -fno-finite-math-only" as I think an instruction in the .md file checks the wrong 
flag.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug target/19116] -fno-finite-math-only does not override -ffast-math
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
                   ` (5 preceding siblings ...)
  2004-12-27  0:41 ` pinskia at gcc dot gnu dot org
@ 2004-12-27 10:26 ` Thomas dot Koenig at online dot de
  2004-12-27 14:00 ` [Bug target/19116] -funsafe-math-optimizations make nan compares equal to one another (-finite-math-only should be doing that) pinskia at gcc dot gnu dot org
  2005-01-17 13:42 ` hunor at cs dot bme dot hu
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas dot Koenig at online dot de @ 2004-12-27 10:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From Thomas dot Koenig at online dot de  2004-12-27 10:26 -------
(In reply to comment #6)
> Can you try just -funsafe-math-optimizations and see what happens I think you
will get the same 
> results as "-ffast-math -fno-finite-math-only" as I think an instruction in
the .md file checks the wrong 
> flag.

$ gcc -funsafe-math-optimizations nan-check2.c
$ ./a.out
nan compares equal to itself
$ gcc -S -funsafe-math-optimizations nan-check2.c
$ cat nan-check2.s
        .file   "nan-check2.c"
        .section        .rodata
.LC1:
        .string "%f compares equal to itself\n"
        .align 4
.LC2:
        .string "%f compares unequal to itself\n"
        .text
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $56, %esp
        andl    $-16, %esp
        movl    $0, %eax
        addl    $15, %eax
        addl    $15, %eax
        shrl    $4, %eax
        sall    $4, %eax
        subl    %eax, %esp
        fldz
        fstpl   -16(%ebp)
        fldz
        fstpl   -8(%ebp)
        fldl    -16(%ebp)
        fdivl   -8(%ebp)
        fstpl   -24(%ebp)
        leal    -24(%ebp), %eax
        movl    %eax, 4(%esp)
        leal    -24(%ebp), %eax
        movl    %eax, (%esp)
        call    equality
        testl   %eax, %eax
        je      .L2
        fldl    -24(%ebp)
        fstpl   4(%esp)
        movl    $.LC1, (%esp)
        call    printf
        jmp     .L4
.L2:
        fldl    -24(%ebp)
        fstpl   4(%esp)
        movl    $.LC2, (%esp)
        call    printf
.L4:
        movl    $0, %eax
        leave
        ret
        .size   main, .-main
.globl equality
        .type   equality, @function
equality:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        fldl    (%eax)
        movl    12(%ebp), %eax
        fldl    (%eax)
        fcompp
        fnstsw  %ax
        sahf
        sete    %al
        movzbl  %al, %eax
        popl    %ebp
        ret
        .size   equality, .-equality
        .ident  "GCC: (GNU) 4.0.0 20041224 (experimental)"
        .section        .note.GNU-stack,"",@progbits
$                                                                       

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug target/19116] -funsafe-math-optimizations make nan compares equal to one another (-finite-math-only should be doing that)
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
                   ` (6 preceding siblings ...)
  2004-12-27 10:26 ` Thomas dot Koenig at online dot de
@ 2004-12-27 14:00 ` pinskia at gcc dot gnu dot org
  2005-01-17 13:42 ` hunor at cs dot bme dot hu
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-27 14:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-27 14:00 -------
Yep, I was right, thanks for testing.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|-fno-finite-math-only does  |-funsafe-math-optimizations
                   |not override -ffast-math    |make nan compares equal to
                   |                            |one another (-finite-math-
                   |                            |only should be doing that)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

* [Bug target/19116] -funsafe-math-optimizations make nan compares equal to one another (-finite-math-only should be doing that)
  2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
                   ` (7 preceding siblings ...)
  2004-12-27 14:00 ` [Bug target/19116] -funsafe-math-optimizations make nan compares equal to one another (-finite-math-only should be doing that) pinskia at gcc dot gnu dot org
@ 2005-01-17 13:42 ` hunor at cs dot bme dot hu
  8 siblings, 0 replies; 10+ messages in thread
From: hunor at cs dot bme dot hu @ 2005-01-17 13:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From hunor at cs dot bme dot hu  2005-01-17 13:42 -------
Are you sure this is wrong? It seems to me that the RS6000 port has just been
changed to behave liked this two days ago.
If you still think this is a bug, though... This is caused by -mno-ieee-fp
being implied by -funsafe-math-optimizations on i386:

  /* If we're doing fast math, we don't care about comparison order
     wrt NaNs.  This lets us use a shorter comparison sequence.  */
  if (flag_unsafe_math_optimizations)
    target_flags &= ~MASK_IEEE_FP;

If I interpret the documentation correctly, NaN == NaN may happen if either
-mno-ieee-fp or -ffinite-math-only is given (-ffinite-math-only should not
imply -mno-ieee-fp either as that changes the behavior of square root
calculations too). I can send you my patch if you reach the conclusion that
this is a bug.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hunor at cs dot bme dot hu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116


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

end of thread, other threads:[~2005-01-17 13:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-21 20:36 [Bug driver/19116] New: -fno-finite-math-only does not override -ffast-math Thomas dot Koenig at online dot de
2004-12-21 20:45 ` [Bug middle-end/19116] " pinskia at gcc dot gnu dot org
2004-12-21 21:03 ` Thomas dot Koenig at online dot de
2004-12-25 14:32 ` Thomas dot Koenig at online dot de
2004-12-25 22:17 ` Thomas dot Koenig at online dot de
2004-12-25 22:29 ` [Bug target/19116] " pinskia at gcc dot gnu dot org
2004-12-27  0:41 ` pinskia at gcc dot gnu dot org
2004-12-27 10:26 ` Thomas dot Koenig at online dot de
2004-12-27 14:00 ` [Bug target/19116] -funsafe-math-optimizations make nan compares equal to one another (-finite-math-only should be doing that) pinskia at gcc dot gnu dot org
2005-01-17 13:42 ` hunor at cs dot bme dot hu

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