From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23032 invoked by alias); 30 Dec 2011 02:14:46 -0000 Received: (qmail 23022 invoked by uid 22791); 30 Dec 2011 02:14:45 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_DQ,TW_DR,TW_OV,TW_VH 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; Fri, 30 Dec 2011 02:14:33 +0000 From: "johnvb at broadcom dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) Date: Fri, 30 Dec 2011 02:27: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: johnvb at broadcom 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: 2011-12/txt/msg02791.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51709 Bug #: 51709 Summary: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned@gcc.gnu.org ReportedBy: johnvb@broadcom.com armv7 target is not always producing unaligned access to packed fields using the appropriate half and full word instructions. Rather sometimes it uses bytes accesses with shifts and or's. Below is a program which produces the problem: typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; #define HALFWORD 1 #define ADD_BYTE 0 #define PACKED 1 #if HALFWORD #define FIELD_T uint16 #else #define FIELD_T uint32 #endif #if PACKED #define PACKED_ATTRIBUTE __attribute__ ((packed)) #else #define PACKED_ATTRIBUTE #endif typedef struct PACKED_ATTRIBUTE { #if ADD_BYTE uint8 field0; #endif FIELD_T field1; FIELD_T field2; } packed_struct_t; typedef struct { #if ADD_BYTE uint8 field0; #endif FIELD_T field1; FIELD_T field2; } natural_struct_t; void test_function(natural_struct_t *natural, packed_struct_t *packed) { natural->field1 = packed->field1; packed->field2 = natural->field2; } This produces test_function: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. ldrb r3, [r1, #1] @ zero_extendqisi2 @ tmp141, ldrb ip, [r1, #0] @ zero_extendqisi2 @ tmp140,* packed orr r2, ip, r3, lsl #8 @, tmp143, tmp140, tmp141, ldrh r3, [r0, #2] @, natural_3(D)->field2 strh r2, [r0, #0] @ movhi @ tmp143, natural_3(D)->field1 strh r3, [r1, #2] @ unaligned @ natural_3(D)->field2, bx lr @ .size test_function, .-test_function .ident "GCC: (Sourcery CodeBench Lite 2011.09-69) 4.6.1" The load from the packed structure is decomposed to byte accesses but note the stores are not. Also if you try full words by changing the define HALFWORD the generated code is as expected. Adding a byte to the beginning of the packed and natural structure by changing the define ADD_BYTE doesn't change the results. It appears to only be the half word load that is having the problem. Note in the above assembly output, that the @unaligned is missing from the load though present on the store. If you look at the assembly for the full word compile, the @unaligned is present on both the load and store. I claim this is a sometimes result because I have looked at cases in my more complicated source and I can see that sometimes packed half word loads do not use byte accesses.