public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/51446] New: -fno-trapping-math generates NaN constant with different sign
@ 2011-12-07  1:38 lucier at math dot purdue.edu
  2011-12-07 12:52 ` [Bug tree-optimization/51446] " rguenth at gcc dot gnu.org
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: lucier at math dot purdue.edu @ 2011-12-07  1:38 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51446
           Summary: -fno-trapping-math generates NaN constant with
                    different sign
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: lucier@math.purdue.edu


With this compiler:

[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% /pkgs/gcc-4.6.1/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/pkgs/gcc-4.6.1/bin/gcc
COLLECT_LTO_WRAPPER=/pkgs/gcc-4.6.1/libexec/gcc/x86_64-apple-darwin10.8.0/4.6.1/lto-wrapper
Target: x86_64-apple-darwin10.8.0
Configured with: ../../gcc-4.6.1/configure --prefix=/pkgs/gcc-4.6.1
Thread model: posix
gcc version 4.6.1 (GCC) 

and this code:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  union double_or_long {double d; long l;}
  infinity, nan1, nan2;
  double temp;
  infinity.d = 1.0 / 0.0;
  nan1.d = infinity.d - infinity.d;
  temp = 0.0 / 0.0;
  nan2.d = temp;
  printf("%ld %ld\n", nan1.l, nan2.l);
  return 1;
}

You get

[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% /pkgs/gcc-4.6.1/bin/gcc -O1
-Wall -W nan-test-c.c
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% ./a.out 
-2251799813685248 -2251799813685248
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% /pkgs/gcc-4.6.1/bin/gcc -O1
-Wall -W -fno-trapping-math  nan-test-c.c
[Bradley-Luciers-MacBook-Pro:~/Downloads] lucier% ./a.out
9221120237041090560 9221120237041090560

If you look at the assembly, without -fno-trapping-math you get

_main:
LFB4:
        subq    $8, %rsp
LCFI0:
        xorpd   %xmm0, %xmm0
        movsd   LC0(%rip), %xmm1
        divsd   %xmm0, %xmm1
        divsd   %xmm0, %xmm0
        movd    %xmm0, %rdx
        subsd   %xmm1, %xmm1
        movd    %xmm1, %rsi
        leaq    LC2(%rip), %rdi
        movl    $0, %eax
        call    _printf
        movl    $1, %eax
        addq    $8, %rsp
LCFI1:
        ret

i.e., the divisions and subtractions are actually executed; with
-fno-trapping-math you get

_main:
LFB4:
        subq    $8, %rsp
LCFI0:
        movabsq $9221120237041090560, %rdx
        movq    %rdx, %rsi
        leaq    LC0(%rip), %rdi
        movl    $0, %eax
        call    _printf
        movl    $1, %eax
        addq    $8, %rsp
LCFI1:
        ret

i.e., it just loads a constant for both NaNs for which the sign differs from
the value that is computed with the divsd and the subsd instructions.


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

end of thread, other threads:[~2023-10-02 17:23 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-07  1:38 [Bug tree-optimization/51446] New: -fno-trapping-math generates NaN constant with different sign lucier at math dot purdue.edu
2011-12-07 12:52 ` [Bug tree-optimization/51446] " rguenth at gcc dot gnu.org
2011-12-07 19:56 ` lucier at math dot purdue.edu
2011-12-07 21:07 ` lucier at math dot purdue.edu
2011-12-08 10:41 ` [Bug middle-end/51446] " rguenth at gcc dot gnu.org
2011-12-08 14:31 ` lucier at math dot purdue.edu
2011-12-08 14:38 ` lucier at math dot purdue.edu
2011-12-08 15:32 ` kargl at gcc dot gnu.org
2011-12-08 16:19 ` dominiq at lps dot ens.fr
2011-12-08 17:08 ` lucier at math dot purdue.edu
2011-12-08 18:36 ` lucier at math dot purdue.edu
2011-12-08 19:01 ` jakub at gcc dot gnu.org
2011-12-08 20:46 ` joseph at codesourcery dot com
2011-12-08 20:55 ` lucier at math dot purdue.edu
2011-12-08 22:33 ` joseph at codesourcery dot com
2013-01-10  1:05 ` joel at gcc dot gnu.org
2021-12-17 20:22 ` lucier at math dot purdue.edu
2021-12-17 20:23 ` lucier at math dot purdue.edu
2022-03-12 15:22 ` roger at nextmovesoftware dot com
2023-10-02  0:02 ` pinskia at gcc dot gnu.org
2023-10-02  0:58 ` eggert at cs dot ucla.edu
2023-10-02 11:09 ` amonakov at gcc dot gnu.org
2023-10-02 17:23 ` joseph at codesourcery 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).