diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2902cdc7344d..1b246171d468 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-12-03 Richard Sandiford + + * cfgexpand.c (discover_nonconstant_array_refs_r): If an access + with POLY_INT_CST size is made to a fixed-size object, force the + object to live in memory. + 2019-12-03 Andrew Stubbs * config/gcn/gcn-valu.md: Change "vcondu" patterns to use VEC_1REG_MODE diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index e8bed2504bf1..bb31fef70143 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -6133,6 +6133,21 @@ discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees, *walk_subtrees = 0; } + /* References of size POLY_INT_CST to a fixed-size object must go + through memory. It's more efficient to force that here than + to create temporary slots on the fly. */ + else if ((TREE_CODE (t) == MEM_REF || TREE_CODE (t) == TARGET_MEM_REF) + && TYPE_SIZE (TREE_TYPE (t)) + && POLY_INT_CST_P (TYPE_SIZE (TREE_TYPE (t)))) + { + tree base = get_base_address (t); + if (base + && DECL_P (base) + && DECL_MODE (base) != BLKmode + && GET_MODE_SIZE (DECL_MODE (base)).is_constant ()) + TREE_ADDRESSABLE (base) = 1; + *walk_subtrees = 0; + } return NULL_TREE; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc8ff79cbc25..028755bb51a8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-12-03 Richard Sandiford + + * gcc.target/aarch64/sve/acle/general/deref_1.c: New test. + 2019-12-03 Marek Polacek PR c++/91363 - P0960R3: Parenthesized initialization of aggregates. diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/deref_1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/deref_1.c new file mode 100644 index 000000000000..99d831936a54 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/deref_1.c @@ -0,0 +1,25 @@ +/* { dg-options "-O2" } */ + +#include + +uint64_t +f1 (int32_t *x, int32_t *y) +{ + union { uint64_t x; char c[8]; } u; + svbool_t pg = svptrue_b32 (); + *(svbool_t *)&u.c[0] = svcmpeq (pg, svld1 (pg, x), 0); + *(svbool_t *)&u.c[4] = svcmpeq (pg, svld1 (pg, y), 1); + return u.x; +} + +typedef unsigned int v4si __attribute__((vector_size(16))); + +/* The aliasing is somewhat dubious here, but it must compile. */ + +v4si +f2 (void) +{ + v4si res; + *(svuint32_t *) &res = svindex_u32 (0, 1); + return res; +}