This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/52352] New: [x32] - Wrong code to access addresses 0x80000000 to 0xFFFFFFFF using registers
- From: "steffen-schmidt at siemens dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 23 Feb 2012 11:36:58 +0000
- Subject: [Bug target/52352] New: [x32] - Wrong code to access addresses 0x80000000 to 0xFFFFFFFF using registers
- Auto-submitted: auto-generated
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)