This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
- From: "johnvb at broadcom dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 30 Dec 2011 02:14:21 +0000
- Subject: [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
- Auto-submitted: auto-generated
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.