--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -fgimple -fdump-tree-forwprop1-gimple" } */
+
+struct S {
+ struct S *next;
+ int vals[5];
+};
+
+int __GIMPLE foo (struct S * s, int idx)
+{
+ int D_2968;
+ int *_1;
+
+ /* In GIMPLE '*s' does not have to be aligned according to its type
+ so we have to preserve the alignment of the access when forwarding
+ the address. */
+ _1 = &s->vals[idx];
+ D_2968 = __MEM <volatile int> ((volatile int *)_1);
+ return D_2968;
+}
+
+/* { dg-final { scan-tree-dump "__MEM <struct S, 32>" "forwprop1" { target lp64 } } } */
new_base = build_fold_addr_expr (*def_rhs_basep);
new_offset = TREE_OPERAND (rhs, 1);
}
- *def_rhs_basep = build2 (MEM_REF, TREE_TYPE (*def_rhs_basep),
- new_base, new_offset);
+ tree atype = TREE_TYPE (*def_rhs_basep);
+ if (TYPE_ALIGN (TREE_TYPE (rhs)) < TYPE_ALIGN (atype))
+ atype = build_aligned_type (atype, TYPE_ALIGN (TREE_TYPE (rhs)));
+ *def_rhs_basep = build2 (MEM_REF, atype, new_base, new_offset);
TREE_THIS_VOLATILE (*def_rhs_basep) = TREE_THIS_VOLATILE (rhs);
TREE_SIDE_EFFECTS (*def_rhs_basep) = TREE_SIDE_EFFECTS (rhs);
TREE_THIS_NOTRAP (*def_rhs_basep) = TREE_THIS_NOTRAP (rhs);