public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/27045]  New: c++ is generating incorrect optimized code for xor operations on long long
@ 2006-04-05 15:14 l_heldt at poczta dot onet dot pl
  2006-04-05 15:17 ` [Bug c++/27045] " l_heldt at poczta dot onet dot pl
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: l_heldt at poczta dot onet dot pl @ 2006-04-05 15:14 UTC (permalink / raw)
  To: gcc-bugs

c++ is generating incorrect optimized code for xor operations on long long.
Version which is affected is:

g++ (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8)

Following (proper) code is inlined into bad assembly when optimization is
turned on:

namespace __gnu_cxx
{
        /**
                hash specialization for uint64
        */
        template <>
        class hash<uint64>
        {
                public:
                        size_t operator()(uint64 const & number) const
                        {
                                hash<uint32> uint32Hasher;
                                uint32 const *p = (uint32 *)&number;

                                return uint32Hasher(p[0]) ^ uint32Hasher(p[1]);
                        }
        };

        /**
                hash specialization for RequestId
        */
        template<>
        class hash<RequestId>
        {
                public:
                        size_t operator()(RequestId const & requestId) const
                        {
                                hash<uint64> uint64Hasher;
                                return uint64Hasher(requestId.getV1()) ^
uint64Hasher(requestId.getV2());
                        }
        };
}


Part of bad assembly:

        call    _ZNK9RequestId5getV1Ev
        movl    -20(%ebp), %ebx
        movl    %esi, (%esp)
        movl    %eax, -24(%ebp)
        movl    -24(%ebp), %eax
        movl    %edx, -20(%ebp)
        xorl    %eax, %ebx
        call    _ZNK9RequestId5getV2Ev
        movl    -16(%ebp), %ecx
        movl    %eax, -16(%ebp)
        movl    -12(%ebp), %eax
        movl    %edx, -12(%ebp)
        xorl    %ecx, %eax

and it probably should be something like:

        call    _ZNK9RequestId5getV1Ev
        movl    %eax, -24(%ebp)
        movl    %edx, -20(%ebp)
        movl    -20(%ebp), %ebx
        movl    %esi, (%esp)
        movl    -24(%ebp), %eax
        xorl    %eax, %ebx
        call    _ZNK9RequestId5getV2Ev
        movl    %eax, -16(%ebp)
        movl    %edx, -12(%ebp)
        movl    -16(%ebp), %ecx
        movl    -12(%ebp), %eax
        xorl    %ecx, %eax

It seems that compiler reads values from stack before setting them after call
to getV1() or getV2().

Bug shows up only when optimization is turned on.

I am attaching simple demo program which should run when optimization is set to
0 and crash when it is set to 2 or 3.


-- 
           Summary: c++ is generating incorrect optimized code for xor
                    operations on long long
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: l_heldt at poczta dot onet dot pl


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


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

* [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:14 [Bug c++/27045] New: c++ is generating incorrect optimized code for xor operations on long long l_heldt at poczta dot onet dot pl
@ 2006-04-05 15:17 ` l_heldt at poczta dot onet dot pl
  2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: l_heldt at poczta dot onet dot pl @ 2006-04-05 15:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from l_heldt at poczta dot onet dot pl  2006-04-05 15:17 -------
Created an attachment (id=11212)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11212&action=view)
File containing hash specifications


-- 


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


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

* [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:14 [Bug c++/27045] New: c++ is generating incorrect optimized code for xor operations on long long l_heldt at poczta dot onet dot pl
  2006-04-05 15:17 ` [Bug c++/27045] " l_heldt at poczta dot onet dot pl
@ 2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
  2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: l_heldt at poczta dot onet dot pl @ 2006-04-05 15:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from l_heldt at poczta dot onet dot pl  2006-04-05 15:17 -------
Created an attachment (id=11213)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11213&action=view)
Implementation of RequestId


-- 


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


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

* [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:14 [Bug c++/27045] New: c++ is generating incorrect optimized code for xor operations on long long l_heldt at poczta dot onet dot pl
  2006-04-05 15:17 ` [Bug c++/27045] " l_heldt at poczta dot onet dot pl
  2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
@ 2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
  2006-04-05 16:00   ` Graham Stott
  2006-04-05 16:00   ` Graham Stott
  2006-04-05 16:00 ` graham dot stott at btinternet dot com
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 9+ messages in thread
From: l_heldt at poczta dot onet dot pl @ 2006-04-05 15:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from l_heldt at poczta dot onet dot pl  2006-04-05 15:18 -------
After compilation:

g++ test.cpp req.cpp -O0

program works fine. After compilation with:

g++ test.cpp req.cpp -O2

it breaks with SIGABRT.


-- 


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


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

* [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:14 [Bug c++/27045] New: c++ is generating incorrect optimized code for xor operations on long long l_heldt at poczta dot onet dot pl
                   ` (3 preceding siblings ...)
  2006-04-05 16:00 ` graham dot stott at btinternet dot com
@ 2006-04-05 16:00 ` graham dot stott at btinternet dot com
  2006-04-05 16:14 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 9+ messages in thread
From: graham dot stott at btinternet dot com @ 2006-04-05 16:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from graham dot stott at btinternet dot com  2006-04-05 16:00 -------
Subject: Re:  c++ is generating incorrect optimized code for xor operations on
long long

All,

Not a bug, this is yet another case of type pruning.

Use -fno-strict-aliasing or fix your code.

Graham


-- 


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


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

* Re: [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
@ 2006-04-05 16:00   ` Graham Stott
  2006-04-05 16:00   ` Graham Stott
  1 sibling, 0 replies; 9+ messages in thread
From: Graham Stott @ 2006-04-05 16:00 UTC (permalink / raw)
  To: gcc-bugzilla, gcc-bugs

All,

Not a bug, this is yet another case of type pruning.

Use -fno-strict-aliasing or fix your code.

Graham


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

* [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:14 [Bug c++/27045] New: c++ is generating incorrect optimized code for xor operations on long long l_heldt at poczta dot onet dot pl
                   ` (2 preceding siblings ...)
  2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
@ 2006-04-05 16:00 ` graham dot stott at btinternet dot com
  2006-04-05 16:00 ` graham dot stott at btinternet dot com
  2006-04-05 16:14 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 9+ messages in thread
From: graham dot stott at btinternet dot com @ 2006-04-05 16:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from graham dot stott at btinternet dot com  2006-04-05 16:00 -------
Subject: Re:  c++ is generating incorrect optimized code for xor operations on
long long

All,

Not a bug, this is yet another case of type pruning.

Use -fno-strict-aliasing or fix your code.

Graham


-- 


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


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

* Re: [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
  2006-04-05 16:00   ` Graham Stott
@ 2006-04-05 16:00   ` Graham Stott
  1 sibling, 0 replies; 9+ messages in thread
From: Graham Stott @ 2006-04-05 16:00 UTC (permalink / raw)
  To: gcc-bugzilla, gcc-bugs

All,

Not a bug, this is yet another case of type pruning.

Use -fno-strict-aliasing or fix your code.

Graham


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

* [Bug c++/27045] c++ is generating incorrect optimized code for xor operations on long long
  2006-04-05 15:14 [Bug c++/27045] New: c++ is generating incorrect optimized code for xor operations on long long l_heldt at poczta dot onet dot pl
                   ` (4 preceding siblings ...)
  2006-04-05 16:00 ` graham dot stott at btinternet dot com
@ 2006-04-05 16:14 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-05 16:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2006-04-05 16:13 -------


*** This bug has been marked as a duplicate of 21920 ***


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2006-04-05 16:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-05 15:14 [Bug c++/27045] New: c++ is generating incorrect optimized code for xor operations on long long l_heldt at poczta dot onet dot pl
2006-04-05 15:17 ` [Bug c++/27045] " l_heldt at poczta dot onet dot pl
2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
2006-04-05 15:18 ` l_heldt at poczta dot onet dot pl
2006-04-05 16:00   ` Graham Stott
2006-04-05 16:00   ` Graham Stott
2006-04-05 16:00 ` graham dot stott at btinternet dot com
2006-04-05 16:00 ` graham dot stott at btinternet dot com
2006-04-05 16:14 ` pinskia 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).