public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/44261]  New: Multiplying -1 by NaN is not valid.
@ 2010-05-24 16:23 carlos at codesourcery dot com
  2010-05-24 17:55 ` [Bug target/44261] " rguenth at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: carlos at codesourcery dot com @ 2010-05-24 16:23 UTC (permalink / raw)
  To: gcc-bugs

The following testcase is an example of code used in a glibc testcase. I'm
trying hard to shake out the bugs in the glibc testsuite for debian, and one
testsuite failure looks like a compiler issue.

The expected behaviour is for the testcase to print the raw IEEE754 value of
-NAN.

The observed behaviour, when -DALT is on the command line, is that the testcase
prints the incorrect raw value e.g. NAN.

GCC 4.4.3 in debian doesn't compile this code correctly.

cat >> tst-mul-nan.c <<EOF
#include <stdio.h>
#include <math.h>

#ifdef ALT
volatile double nanval;
#else
#define nanval NAN
#endif

int
main ()
{
#ifdef ALT
 nanval = NAN;
#endif
 printf ("0x%llx\n", -nanval);
 return 0;
}
EOF

gcc -g3 -O0 -save-temps -o test-mul-nan-OK test-mul-nan.c; ./test-mul-nan-OK
0xfff7ffffffffffff

This is the correct result e.g. -NAN. In the correct case the compiler has
already computer -NAN and it's loaded directly from the local symbol e.g.

.LC1:
       .word   -524289
       .word   -1

This is the case that is not working correctly:

gcc -g3 -O0 -save-temps -DALT -o test-mul-nan-NG test-mul-nan.c;
./test-mul-nan-NG
0x7ff7ffffffffffff

That result is not -NAN, it is NAN. This is incorrect.

In the incorrect compilation the compiler loads NAN from a local constant:

.LC0:
       .word   2146959359
       .word   -1

This is 0x7ff7ffffffffffff e.g. NAN.

Then it loads a 64-bit double -1.0.

.LC2:
       .word   -1074790400
       .word   0

In the incorrect case the compiler tries to multiply -1.0 by NAN to get a
result of -NAN.

       addil LR'nanval-$global$,%r27
       copy %r1,%r19
       ldo RR'nanval-$global$(%r19),%r19
       fldds 0(%r19),%fr23
       ldil LR'.LC2,%r19
       ldo RR'.LC2(%r19),%r19
       fldds 0(%r19),%fr22
       fmpy,dbl %fr23,%fr22,%fr22

This is not going to work because -1.0 times NAN is NAN, and the sign of the
input will be ignored.

See: PA-RISC 2.0 Architecture, Floating Coprocessor 8-23 "Operations With
NaNs", and 8-24 "Sign Bit" can be referenced for information on NANs.

After the multiplication fr22 still contains NAN, and that is what is printed
instead of the expected result of -NAN.

John David Anglin indicates:

This is a bug.

The code should xor the sign bit when doing negation.  The existing code
doesn't work for NANs.  I'll try to fix negdf2 and negsf2.

The problem is PA1.1 doesn't have a fneg instruction, so the above takes a bit
of work to implement.  You will get the correct result if you specify
-march=2.0.

Unfortunately I can't use -march=2.0 in this case, the C library has to work on
PA1.1 class systems.


-- 
           Summary: Multiplying -1 by NaN is not valid.
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carlos at codesourcery dot com
 GCC build triplet: hppa-linux-gnu
  GCC host triplet: hppa-linux-gnu
GCC target triplet: hppa-linux-gnu


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


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

* [Bug target/44261] Multiplying -1 by NaN is not valid.
  2010-05-24 16:23 [Bug target/44261] New: Multiplying -1 by NaN is not valid carlos at codesourcery dot com
@ 2010-05-24 17:55 ` rguenth at gcc dot gnu dot org
  2010-05-24 18:11 ` dave at hiauly1 dot hia dot nrc dot ca
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-24 17:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-05-24 17:55 -------
Well - GCC has fallback expansions for some sign-related instructions by doing
bit-fiddling instead.  I think that's whats required if the arch cannot do
a IEEE negate.


-- 


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


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

* [Bug target/44261] Multiplying -1 by NaN is not valid.
  2010-05-24 16:23 [Bug target/44261] New: Multiplying -1 by NaN is not valid carlos at codesourcery dot com
  2010-05-24 17:55 ` [Bug target/44261] " rguenth at gcc dot gnu dot org
@ 2010-05-24 18:11 ` dave at hiauly1 dot hia dot nrc dot ca
  2010-05-29 14:16 ` danglin at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dave at hiauly1 dot hia dot nrc dot ca @ 2010-05-24 18:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dave at hiauly1 dot hia dot nrc dot ca  2010-05-24 18:11 -------
Subject: Re:  Multiplying -1 by NaN is not valid.

On Mon, 24 May 2010, rguenth at gcc dot gnu dot org wrote:

> Well - GCC has fallback expansions for some sign-related instructions by doing
> bit-fiddling instead.  I think that's whats required if the arch cannot do
> a IEEE negate.

I am testing the attached change to fiddle the sign bit.  It is probably
more efficient than a generic fallback.

Dave


------- Comment #3 from dave at hiauly1 dot hia dot nrc dot ca  2010-05-24 18:11 -------
Created an attachment (id=20737)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20737&action=view)


-- 


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


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

* [Bug target/44261] Multiplying -1 by NaN is not valid.
  2010-05-24 16:23 [Bug target/44261] New: Multiplying -1 by NaN is not valid carlos at codesourcery dot com
  2010-05-24 17:55 ` [Bug target/44261] " rguenth at gcc dot gnu dot org
  2010-05-24 18:11 ` dave at hiauly1 dot hia dot nrc dot ca
@ 2010-05-29 14:16 ` danglin at gcc dot gnu dot org
  2010-05-29 14:33 ` danglin at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: danglin at gcc dot gnu dot org @ 2010-05-29 14:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from danglin at gcc dot gnu dot org  2010-05-29 14:16 -------
Subject: Bug 44261

Author: danglin
Date: Sat May 29 14:16:11 2010
New Revision: 160027

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160027
Log:
        PR target/44261
        config/pa/pa.md (negdf2_slow, negsf2_slow): New patterns.
        (negdf2): Adjust expander pattern and use negdf2_slow.
        (negsf2): Likewise.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/pa/pa.md


-- 


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


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

* [Bug target/44261] Multiplying -1 by NaN is not valid.
  2010-05-24 16:23 [Bug target/44261] New: Multiplying -1 by NaN is not valid carlos at codesourcery dot com
                   ` (2 preceding siblings ...)
  2010-05-29 14:16 ` danglin at gcc dot gnu dot org
@ 2010-05-29 14:33 ` danglin at gcc dot gnu dot org
  2010-06-19 18:26 ` danglin at gcc dot gnu dot org
  2010-06-19 18:28 ` danglin at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: danglin at gcc dot gnu dot org @ 2010-05-29 14:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from danglin at gcc dot gnu dot org  2010-05-29 14:33 -------
Fixed on trunk.


-- 

danglin at gcc dot gnu dot org changed:

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


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


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

* [Bug target/44261] Multiplying -1 by NaN is not valid.
  2010-05-24 16:23 [Bug target/44261] New: Multiplying -1 by NaN is not valid carlos at codesourcery dot com
                   ` (3 preceding siblings ...)
  2010-05-29 14:33 ` danglin at gcc dot gnu dot org
@ 2010-06-19 18:26 ` danglin at gcc dot gnu dot org
  2010-06-19 18:28 ` danglin at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: danglin at gcc dot gnu dot org @ 2010-06-19 18:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from danglin at gcc dot gnu dot org  2010-06-19 18:25 -------
Subject: Bug 44261

Author: danglin
Date: Sat Jun 19 18:25:28 2010
New Revision: 161034

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161034
Log:
        Backport from mainline
        2010-05-29  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

        PR target/44261
        config/pa/pa.md (negdf2_slow, negsf2_slow): New patterns.
        (negdf2): Adjust expander pattern and use negdf2_slow.
        (negsf2): Likewise.


Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/config/pa/pa.md


-- 


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


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

* [Bug target/44261] Multiplying -1 by NaN is not valid.
  2010-05-24 16:23 [Bug target/44261] New: Multiplying -1 by NaN is not valid carlos at codesourcery dot com
                   ` (4 preceding siblings ...)
  2010-06-19 18:26 ` danglin at gcc dot gnu dot org
@ 2010-06-19 18:28 ` danglin at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: danglin at gcc dot gnu dot org @ 2010-06-19 18:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from danglin at gcc dot gnu dot org  2010-06-19 18:28 -------
Subject: Bug 44261

Author: danglin
Date: Sat Jun 19 18:28:28 2010
New Revision: 161035

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161035
Log:
        Backport from mainline
        2010-05-29  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

        PR target/44261
        config/pa/pa.md (negdf2_slow, negsf2_slow): New patterns.
        (negdf2): Adjust expander pattern and use negdf2_slow.
        (negsf2): Likewise.


Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/config/pa/pa.md


-- 


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


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

end of thread, other threads:[~2010-06-19 18:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-24 16:23 [Bug target/44261] New: Multiplying -1 by NaN is not valid carlos at codesourcery dot com
2010-05-24 17:55 ` [Bug target/44261] " rguenth at gcc dot gnu dot org
2010-05-24 18:11 ` dave at hiauly1 dot hia dot nrc dot ca
2010-05-29 14:16 ` danglin at gcc dot gnu dot org
2010-05-29 14:33 ` danglin at gcc dot gnu dot org
2010-06-19 18:26 ` danglin at gcc dot gnu dot org
2010-06-19 18:28 ` danglin at gcc dot gnu dot 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).