aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2012-02-28 09:15:49 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2012-02-28 09:15:49 +0000
commit3a5a825aaecd124c57d3b08ba349631ac8e89123 (patch)
tree9331bf1775c4098ffb8b748e6a4aa7b0856f164d /gcc
parent95510497873486319b680dfedf017415a2bb8173 (diff)
downloadgcc-3a5a825aaecd124c57d3b08ba349631ac8e89123.zip
gcc-3a5a825aaecd124c57d3b08ba349631ac8e89123.tar.gz
gcc-3a5a825aaecd124c57d3b08ba349631ac8e89123.tar.bz2
re PR tree-optimization/52402 (IPA-SRA creates aligned loads from unaligned memory)
2012-02-28 Richard Guenther <rguenther@suse.de> PR tree-optimization/52402 * ipa-prop.c (ipa_modify_call_arguments): Properly use mis-aligned types when creating the accesses at the call site. * gcc.dg/torture/pr52402.c: New testcase. From-SVN: r184619
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/ipa-prop.c24
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr52402.c28
4 files changed, 60 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a89a8ff..24df23a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2012-02-28 Richard Guenther <rguenther@suse.de>
+
+ PR tree-optimization/52402
+ * ipa-prop.c (ipa_modify_call_arguments): Properly use
+ mis-aligned types when creating the accesses at the call site.
+
2012-02-28 Georg-Johann Lay <avr@gjlay.de>
* config/avr/builtins.def: New file.
diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 6d76adb..3856793 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -2508,9 +2508,27 @@ ipa_modify_call_arguments (struct cgraph_edge *cs, gimple stmt,
}
}
- expr = fold_build2_loc (loc, MEM_REF, adj->type, base, off);
- if (adj->by_ref)
- expr = build_fold_addr_expr (expr);
+ if (!adj->by_ref)
+ {
+ tree type = adj->type;
+ unsigned int align;
+ unsigned HOST_WIDE_INT misalign;
+ align = get_pointer_alignment_1 (base, &misalign);
+ misalign += (double_int_sext (tree_to_double_int (off),
+ TYPE_PRECISION (TREE_TYPE (off))).low
+ * BITS_PER_UNIT);
+ misalign = misalign & (align - 1);
+ if (misalign != 0)
+ align = (misalign & -misalign);
+ if (align < TYPE_ALIGN (type))
+ type = build_aligned_type (type, align);
+ expr = fold_build2_loc (loc, MEM_REF, type, base, off);
+ }
+ else
+ {
+ expr = fold_build2_loc (loc, MEM_REF, adj->type, base, off);
+ expr = build_fold_addr_expr (expr);
+ }
expr = force_gimple_operand_gsi (&gsi, expr,
adj->by_ref
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ee4e5f3..7a3af58 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2012-02-28 Richard Guenther <rguenther@suse.de>
+ PR tree-optimization/52402
+ * gcc.dg/torture/pr52402.c: New testcase.
+
+2012-02-28 Richard Guenther <rguenther@suse.de>
+
PR lto/52400
* g++.dg/lto/pr52400_0.C: New testcase.
diff --git a/gcc/testsuite/gcc.dg/torture/pr52402.c b/gcc/testsuite/gcc.dg/torture/pr52402.c
new file mode 100644
index 0000000..5bd51fb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr52402.c
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+
+typedef int v4si __attribute__((vector_size(16)));
+struct T { v4si i[2]; int j; } __attribute__((packed));
+
+static v4si __attribute__((noinline))
+foo (struct T t)
+{
+ return t.i[0];
+}
+
+static struct T *__attribute__((noinline))
+init ()
+{
+ char *p = __builtin_malloc (sizeof (struct T) + 1);
+ p++;
+ __builtin_memset (p, 1, sizeof (struct T));
+ return (struct T *)p;
+}
+
+int main()
+{
+ struct T *p;
+ p = init ();
+ if (foo (*p)[0] != 0x01010101)
+ __builtin_abort ();
+ return 0;
+}