public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/52352] New: [x32] - Wrong code to access addresses 0x80000000 to 0xFFFFFFFF using registers
@ 2012-02-23 11:38 steffen-schmidt at siemens dot com
  2012-02-23 11:39 ` [Bug target/52352] " steffen-schmidt at siemens dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: steffen-schmidt at siemens dot com @ 2012-02-23 11:38 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52352
           Summary: [x32] - Wrong code to access addresses 0x80000000 to
                    0xFFFFFFFF using registers
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: steffen-schmidt@siemens.com


Created attachment 26727
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26727
C code resulting in wrong instructions when compiled with -mx32 and -O2 or
higher

The example C code defines a structure in memory at address 0xFEE00000
Compilation of this example with -mx32 and -O2 or higher (seems to be related
to -fgcse) results in faulty assembler instructions.

For accessing several members of the structure loads the signed address of one
member of the structure (-18874360 = 0xFEE00008) into register %rax. This
actually results in a 64bit negative address of 0xFFFFFFFFFEE00008, which is
incorrect when later using complete %rax register for memory access.

// -mx32 -O3
movq    $-18874360, %rax
movl    (%rax), %edx
xorb    %al, %al
movl    %edx, 4(%eax)

When optimizing with -O1 register %eax is used instead of %rax which results in
correct behaviour:

// -mx32 -O1
movl    $-18874368, %eax
movl    8(%eax), %edx
movl    %edx, 4(%eax)


The x64 compiler produces correct code with -O1 and -O3 loading the address
into %eax not %rax:

// -m64 -O1
movl    $4276092928, %eax
movl    8(%rax), %edx
movl    %edx, 4(%rax)

// -m64 -O3
movl    $4276092936, %eax
movl    (%rax), %edx
xorb    %al, %al
movl    %edx, 4(%rax)


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

end of thread, other threads:[~2012-02-27 23:05 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-23 11:38 [Bug target/52352] New: [x32] - Wrong code to access addresses 0x80000000 to 0xFFFFFFFF using registers steffen-schmidt at siemens dot com
2012-02-23 11:39 ` [Bug target/52352] " steffen-schmidt at siemens dot com
2012-02-23 11:40 ` steffen-schmidt at siemens dot com
2012-02-23 11:40 ` steffen-schmidt at siemens dot com
2012-02-23 11:50 ` steffen-schmidt at siemens dot com
2012-02-23 16:47 ` ubizjak at gmail dot com
2012-02-23 16:58 ` ubizjak at gmail dot com
2012-02-23 17:36 ` pinskia at gcc dot gnu.org
2012-02-24  4:53 ` hjl.tools at gmail dot com
2012-02-24  5:01 ` hjl.tools at gmail dot com
2012-02-24 19:14 ` ubizjak at gmail dot com
2012-02-24 19:15 ` hjl.tools at gmail dot com
2012-02-24 19:34 ` ubizjak at gmail dot com
2012-02-24 20:25 ` hjl.tools at gmail dot com
2012-02-27 16:50 ` hjl at gcc dot gnu.org
2012-02-27 23:07 ` 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).