This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR44903
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 28 Jul 2010 12:32:16 +0200 (CEST)
- Subject: [PATCH] Fix PR44903
The expansion of unaligned indirect references never worked correctly.
So we have to be careful to not generate those when expanding
memcpy inline on STRICT_ALIGNMENT targets. The following does so.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2010-07-28 Richard Guenther <rguenther@suse.de>
PR middle-end/44903
* builtins.c (fold_builtin_memory_op): On STRICT_ALIGNMENT
targets try harder to not generate unaligned accesses.
Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c (revision 162526)
--- gcc/builtins.c (working copy)
*************** fold_builtin_memory_op (location_t loc,
*** 8474,8480 ****
STRIP_NOPS (srcvar);
if (TREE_CODE (srcvar) == ADDR_EXPR
&& var_decl_component_p (TREE_OPERAND (srcvar, 0))
! && tree_int_cst_equal (TYPE_SIZE_UNIT (srctype), len))
srcvar = fold_build2 (MEM_REF, destvar ? desttype : srctype,
srcvar, off0);
else
--- 8474,8483 ----
STRIP_NOPS (srcvar);
if (TREE_CODE (srcvar) == ADDR_EXPR
&& var_decl_component_p (TREE_OPERAND (srcvar, 0))
! && tree_int_cst_equal (TYPE_SIZE_UNIT (srctype), len)
! && (!STRICT_ALIGNMENT
! || !destvar
! || src_align >= (int) TYPE_ALIGN (desttype)))
srcvar = fold_build2 (MEM_REF, destvar ? desttype : srctype,
srcvar, off0);
else
*************** fold_builtin_memory_op (location_t loc,
*** 8485,8495 ****
--- 8488,8504 ----
if (srcvar == NULL_TREE)
{
+ if (STRICT_ALIGNMENT
+ && src_align < (int) TYPE_ALIGN (desttype))
+ return NULL_TREE;
STRIP_NOPS (src);
srcvar = fold_build2 (MEM_REF, desttype, src, off0);
}
else if (destvar == NULL_TREE)
{
+ if (STRICT_ALIGNMENT
+ && dest_align < (int) TYPE_ALIGN (srctype))
+ return NULL_TREE;
STRIP_NOPS (dest);
destvar = fold_build2 (MEM_REF, srctype, dest, off0);
}