aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2011-12-08 09:05:38 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2011-12-08 09:05:38 +0000
commit908b951938511131cf3858c75924db323de415ea (patch)
treef9866f9a7ab239814de604e3414349d48cdece0b /gcc/builtins.c
parentc37257a1f686bdd260a2edc445f8b3f24dceec2e (diff)
downloadgcc-908b951938511131cf3858c75924db323de415ea.zip
gcc-908b951938511131cf3858c75924db323de415ea.tar.gz
gcc-908b951938511131cf3858c75924db323de415ea.tar.bz2
re PR tree-optimization/51315 (unaligned memory accesses generated with -ftree-sra)
PR tree-optimization/51315 * tree.h (get_object_or_type_alignment): Declare. * expr.c (get_object_or_type_alignment): Move to... * builtins.c (get_object_or_type_alignment): ...here. Add assertion. * tree-sra.c (tree_non_mode_aligned_mem_p): Rename to... (tree_non_aligned_mem_p): ...this. Add ALIGN parameter. Look into MEM_REFs and use get_object_or_type_alignment for them. (build_accesses_from_assign): Adjust for above change. (access_precludes_ipa_sra_p): Likewise. From-SVN: r182102
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 019da15..b007498 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -452,6 +452,31 @@ get_object_alignment (tree exp)
return align;
}
+/* Return the alignment of object EXP, also considering its type when we do
+ not know of explicit misalignment. Only handle MEM_REF and TARGET_MEM_REF.
+
+ ??? Note that, in the general case, the type of an expression is not kept
+ consistent with misalignment information by the front-end, for example when
+ taking the address of a member of a packed structure. However, in most of
+ the cases, expressions have the alignment of their type so we optimistically
+ fall back to this alignment when we cannot compute a misalignment. */
+
+unsigned int
+get_object_or_type_alignment (tree exp)
+{
+ unsigned HOST_WIDE_INT misalign;
+ unsigned int align = get_object_alignment_1 (exp, &misalign);
+
+ gcc_assert (TREE_CODE (exp) == MEM_REF || TREE_CODE (exp) == TARGET_MEM_REF);
+
+ if (misalign != 0)
+ align = (misalign & -misalign);
+ else
+ align = MAX (TYPE_ALIGN (TREE_TYPE (exp)), align);
+
+ return align;
+}
+
/* Return the alignment in bits of EXP, a pointer valued expression.
The alignment returned is, by default, the alignment of the thing that
EXP points to. If it is not a POINTER_TYPE, 0 is returned.