http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56897
Bug #: 56897
Summary: unaligned memory access on alpha
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: [email protected]
ReportedBy: [email protected]
Hi,
After looking at the RTL dumps here and there, I've noticed that
GCC generates unaligned loads in the following manner:
foo = ([reg:X & -8] << (64 - (((reg:FP+reg:Y) & 0x7) << 3))) >> 56
Obviously, we're losing every eighth byte here (consider FP-0,FP-8).
Since FP is aligned, GCC optimizes this to foo = 0. The right way
to do this is:
foo = ([reg:X & -8] << (56 - (((reg:FP+reg:Y-1) & 0x7) << 3))) >> 56
To reproduce, try this out:
unsigned long foo = 0x010203040a0b0c0d;
printf("%02x", *((char *)&foo + 7));
With -O (and onwards) it will turn out to be zero; at every &X+15,
&X+23, etc. Depending on the offset from the frame pointer.
Attached the diff against trunk.
Martynas.