This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix target/24178
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 2 Nov 2005 10:22:08 -0800
- Subject: fix target/24178
As described in the pr audit trail, the code in get_aligned_mem
didn't match the code in aligned_memory_operand, leading to some
confusion.
r~
* config/alpha/alpha.c (get_aligned_mem): Honor alignment given
by MEM_ALIGN.
Index: testsuite/gcc.target/alpha/pr24178.c
===================================================================
--- testsuite/gcc.target/alpha/pr24178.c (revision 0)
+++ testsuite/gcc.target/alpha/pr24178.c (revision 0)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcpu=ev4" } */
+
+struct S {
+ long l;
+ unsigned char c;
+};
+unsigned long f(unsigned char *p10) {
+ struct S *p = (struct S *) (p10 + 10);
+ return p->c;
+}
+
+/* { dg-final { scan-assembler "ldl.*,18\\(" } } */
Index: config/alpha/alpha.c
===================================================================
--- config/alpha/alpha.c (revision 106387)
+++ config/alpha/alpha.c (working copy)
@@ -1487,7 +1487,7 @@
get_aligned_mem (rtx ref, rtx *paligned_mem, rtx *pbitnum)
{
rtx base;
- HOST_WIDE_INT offset = 0;
+ HOST_WIDE_INT disp, offset;
gcc_assert (GET_CODE (ref) == MEM);
@@ -1495,23 +1495,34 @@
&& ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
{
base = find_replacement (&XEXP (ref, 0));
-
gcc_assert (memory_address_p (GET_MODE (ref), base));
}
else
base = XEXP (ref, 0);
if (GET_CODE (base) == PLUS)
- offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
+ disp = INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
+ else
+ disp = 0;
- *paligned_mem
- = widen_memory_access (ref, SImode, (offset & ~3) - offset);
+ /* Find the byte offset within an aligned word. If the memory itself is
+ claimed to be aligned, believe it. Otherwise, aligned_memory_operand
+ will have examined the base register and determined it is aligned, and
+ thus displacements from it are naturally alignable. */
+ if (MEM_ALIGN (ref) >= 32)
+ offset = 0;
+ else
+ offset = disp & 3;
+ /* Access the entire aligned word. */
+ *paligned_mem = widen_memory_access (ref, SImode, -offset);
+
+ /* Convert the byte offset within the word to a bit offset. */
if (WORDS_BIG_ENDIAN)
- *pbitnum = GEN_INT (32 - (GET_MODE_BITSIZE (GET_MODE (ref))
- + (offset & 3) * 8));
+ offset = 32 - (GET_MODE_BITSIZE (GET_MODE (ref)) + offset * 8);
else
- *pbitnum = GEN_INT ((offset & 3) * 8);
+ offset *= 8;
+ *pbitnum = GEN_INT (offset);
}
/* Similar, but just get the address. Handle the two reload cases.