From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23278 invoked by alias); 23 Feb 2012 11:37:40 -0000 Received: (qmail 23269 invoked by uid 22791); 23 Feb 2012 11:37:39 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,LOTS_OF_MONEY,TW_OV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Feb 2012 11:37:26 +0000 From: "steffen-schmidt at siemens dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/52352] New: [x32] - Wrong code to access addresses 0x80000000 to 0xFFFFFFFF using registers Date: Thu, 23 Feb 2012 11:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: steffen-schmidt at siemens dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-02/txt/msg02300.txt.bz2 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)