mirror of git://gcc.gnu.org/git/gcc.git
completely_scalarize arrays as well as records
gcc/: PR tree-optimization/67283 * tree-sra.c (type_consists_of_records_p): Rename to... (scalarizable_type_p): ...this, add case for ARRAY_TYPE. (completely_scalarize_record): Rename to... (completely_scalarize): ...this, add ARRAY_TYPE case, move some code to: (scalarize_elem): New. gcc/testsuite/: * gcc.dg/tree-ssa/sra-15.c: New. From-SVN: r227265
This commit is contained in:
parent
f2511224db
commit
07ad3ec6b1
|
|
@ -1,3 +1,13 @@
|
||||||
|
2015-08-27 Alan Lawrence <alan.lawrence@arm.com>
|
||||||
|
|
||||||
|
PR tree-optimization/67283
|
||||||
|
* tree-sra.c (type_consists_of_records_p): Rename to...
|
||||||
|
(scalarizable_type_p): ...this, add case for ARRAY_TYPE.
|
||||||
|
|
||||||
|
(completely_scalarize_record): Rename to...
|
||||||
|
(completely_scalarize): ...this, add ARRAY_TYPE case, move some code to:
|
||||||
|
(scalarize_elem): New.
|
||||||
|
|
||||||
2015-08-27 Alan Lawrence <alan.lawrence@arm.com>
|
2015-08-27 Alan Lawrence <alan.lawrence@arm.com>
|
||||||
|
|
||||||
* tree-sra.c (completely_scalarize_var): Rename to...
|
* tree-sra.c (completely_scalarize_var): Rename to...
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
2015-08-27 Alan Lawrence <alan.lawrence@arm.com>
|
||||||
|
|
||||||
|
* gcc.dg/tree-ssa/sra-15.c: New.
|
||||||
|
|
||||||
2015-08-27 Andre Vieira <andre.simoesdiasvieira@arm.com>
|
2015-08-27 Andre Vieira <andre.simoesdiasvieira@arm.com>
|
||||||
|
|
||||||
* gcc.target/aarch64/long_branch_1.c: New test.
|
* gcc.target/aarch64/long_branch_1.c: New test.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* Verify that SRA total scalarization works on records containing arrays. */
|
||||||
|
/* { dg-do run } */
|
||||||
|
/* { dg-options "-O1 -fdump-tree-release_ssa --param sra-max-scalarization-size-Ospeed=32" } */
|
||||||
|
|
||||||
|
extern void abort (void);
|
||||||
|
|
||||||
|
struct S
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
unsigned short f[2][2];
|
||||||
|
int i;
|
||||||
|
unsigned short f3, f4;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int __attribute__ ((noinline))
|
||||||
|
foo (struct S *p)
|
||||||
|
{
|
||||||
|
struct S l;
|
||||||
|
|
||||||
|
l = *p;
|
||||||
|
l.i++;
|
||||||
|
l.f[1][0] += 3;
|
||||||
|
*p = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct S a = {0, { {5, 7}, {9, 11} }, 4, 0, 0};
|
||||||
|
foo (&a);
|
||||||
|
if (a.i != 5 || a.f[1][0] != 12)
|
||||||
|
abort ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* { dg-final { scan-tree-dump-times "l;" 0 "release_ssa" } } */
|
||||||
121
gcc/tree-sra.c
121
gcc/tree-sra.c
|
|
@ -915,19 +915,19 @@ create_access (tree expr, gimple stmt, bool write)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return true iff TYPE is a RECORD_TYPE with fields that are either of gimple
|
/* Return true iff TYPE is scalarizable - i.e. a RECORD_TYPE or ARRAY_TYPE with
|
||||||
register types or (recursively) records with only these two kinds of fields.
|
fields that are either of gimple register types (excluding bit-fields)
|
||||||
It also returns false if any of these records contains a bit-field. */
|
or (recursively) scalarizable types. */
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
type_consists_of_records_p (tree type)
|
scalarizable_type_p (tree type)
|
||||||
{
|
{
|
||||||
tree fld;
|
gcc_assert (!is_gimple_reg_type (type));
|
||||||
|
|
||||||
if (TREE_CODE (type) != RECORD_TYPE)
|
switch (TREE_CODE (type))
|
||||||
return false;
|
{
|
||||||
|
case RECORD_TYPE:
|
||||||
for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
|
for (tree fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
|
||||||
if (TREE_CODE (fld) == FIELD_DECL)
|
if (TREE_CODE (fld) == FIELD_DECL)
|
||||||
{
|
{
|
||||||
tree ft = TREE_TYPE (fld);
|
tree ft = TREE_TYPE (fld);
|
||||||
|
|
@ -936,52 +936,105 @@ type_consists_of_records_p (tree type)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!is_gimple_reg_type (ft)
|
if (!is_gimple_reg_type (ft)
|
||||||
&& !type_consists_of_records_p (ft))
|
&& !scalarizable_type_p (ft))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case ARRAY_TYPE:
|
||||||
|
{
|
||||||
|
tree elem = TREE_TYPE (type);
|
||||||
|
if (DECL_P (elem) && DECL_BIT_FIELD (elem))
|
||||||
|
return false;
|
||||||
|
if (!is_gimple_reg_type (elem)
|
||||||
|
&& !scalarizable_type_p (elem))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create total_scalarization accesses for all scalar type fields in DECL that
|
static void scalarize_elem (tree, HOST_WIDE_INT, HOST_WIDE_INT, tree, tree);
|
||||||
must be of a RECORD_TYPE conforming to type_consists_of_records_p. BASE
|
|
||||||
must be the top-most VAR_DECL representing the variable, OFFSET must be the
|
/* Create total_scalarization accesses for all scalar fields of a member
|
||||||
offset of DECL within BASE. REF must be the memory reference expression for
|
of type DECL_TYPE conforming to scalarizable_type_p. BASE
|
||||||
the given decl. */
|
must be the top-most VAR_DECL representing the variable; within that,
|
||||||
|
OFFSET locates the member and REF must be the memory reference expression for
|
||||||
|
the member. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
completely_scalarize_record (tree base, tree decl, HOST_WIDE_INT offset,
|
completely_scalarize (tree base, tree decl_type, HOST_WIDE_INT offset, tree ref)
|
||||||
tree ref)
|
|
||||||
{
|
{
|
||||||
tree fld, decl_type = TREE_TYPE (decl);
|
switch (TREE_CODE (decl_type))
|
||||||
|
{
|
||||||
for (fld = TYPE_FIELDS (decl_type); fld; fld = DECL_CHAIN (fld))
|
case RECORD_TYPE:
|
||||||
|
for (tree fld = TYPE_FIELDS (decl_type); fld; fld = DECL_CHAIN (fld))
|
||||||
if (TREE_CODE (fld) == FIELD_DECL)
|
if (TREE_CODE (fld) == FIELD_DECL)
|
||||||
{
|
{
|
||||||
HOST_WIDE_INT pos = offset + int_bit_position (fld);
|
HOST_WIDE_INT pos = offset + int_bit_position (fld);
|
||||||
tree ft = TREE_TYPE (fld);
|
tree ft = TREE_TYPE (fld);
|
||||||
tree nref = build3 (COMPONENT_REF, TREE_TYPE (fld), ref, fld,
|
tree nref = build3 (COMPONENT_REF, ft, ref, fld, NULL_TREE);
|
||||||
NULL_TREE);
|
|
||||||
|
|
||||||
if (is_gimple_reg_type (ft))
|
scalarize_elem (base, pos, tree_to_uhwi (DECL_SIZE (fld)), nref,
|
||||||
|
ft);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ARRAY_TYPE:
|
||||||
{
|
{
|
||||||
struct access *access;
|
tree elemtype = TREE_TYPE (decl_type);
|
||||||
HOST_WIDE_INT size;
|
tree elem_size = TYPE_SIZE (elemtype);
|
||||||
|
gcc_assert (elem_size && tree_fits_uhwi_p (elem_size));
|
||||||
|
int el_size = tree_to_uhwi (elem_size);
|
||||||
|
gcc_assert (el_size);
|
||||||
|
|
||||||
size = tree_to_uhwi (DECL_SIZE (fld));
|
tree minidx = TYPE_MIN_VALUE (TYPE_DOMAIN (decl_type));
|
||||||
access = create_access_1 (base, pos, size);
|
tree maxidx = TYPE_MAX_VALUE (TYPE_DOMAIN (decl_type));
|
||||||
access->expr = nref;
|
gcc_assert (TREE_CODE (minidx) == INTEGER_CST
|
||||||
access->type = ft;
|
&& TREE_CODE (maxidx) == INTEGER_CST);
|
||||||
|
unsigned HOST_WIDE_INT len = tree_to_uhwi (maxidx)
|
||||||
|
+ 1 - tree_to_uhwi (minidx);
|
||||||
|
/* 4th operand to ARRAY_REF is size in units of the type alignment. */
|
||||||
|
for (unsigned HOST_WIDE_INT idx = 0; idx < len; idx++)
|
||||||
|
{
|
||||||
|
tree t_idx = build_int_cst (TYPE_DOMAIN (decl_type), idx);
|
||||||
|
tree nref = build4 (ARRAY_REF, elemtype, ref, t_idx, NULL_TREE,
|
||||||
|
NULL_TREE);
|
||||||
|
int el_off = offset + idx * el_size;
|
||||||
|
scalarize_elem (base, el_off, el_size, nref, elemtype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gcc_unreachable ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create total_scalarization accesses for a member of type TYPE, which must
|
||||||
|
satisfy either is_gimple_reg_type or scalarizable_type_p. BASE must be the
|
||||||
|
top-most VAR_DECL representing the variable; within that, POS and SIZE locate
|
||||||
|
the member and REF must be the reference expression for it. */
|
||||||
|
|
||||||
|
static void
|
||||||
|
scalarize_elem (tree base, HOST_WIDE_INT pos, HOST_WIDE_INT size,
|
||||||
|
tree ref, tree type)
|
||||||
|
{
|
||||||
|
if (is_gimple_reg_type (type))
|
||||||
|
{
|
||||||
|
struct access *access = create_access_1 (base, pos, size);
|
||||||
|
access->expr = ref;
|
||||||
|
access->type = type;
|
||||||
access->grp_total_scalarization = 1;
|
access->grp_total_scalarization = 1;
|
||||||
/* Accesses for intraprocedural SRA can have their stmt NULL. */
|
/* Accesses for intraprocedural SRA can have their stmt NULL. */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
completely_scalarize_record (base, fld, pos, nref);
|
completely_scalarize (base, type, pos, ref);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a total_scalarization access for VAR as a whole. VAR must be of a
|
/* Create a total_scalarization access for VAR as a whole. VAR must be of a
|
||||||
RECORD_TYPE conforming to type_consists_of_records_p. */
|
RECORD_TYPE or ARRAY_TYPE conforming to scalarizable_type_p. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
create_total_scalarization_access (tree var)
|
create_total_scalarization_access (tree var)
|
||||||
|
|
@ -2521,13 +2574,13 @@ analyze_all_variable_accesses (void)
|
||||||
tree var = candidate (i);
|
tree var = candidate (i);
|
||||||
|
|
||||||
if (TREE_CODE (var) == VAR_DECL
|
if (TREE_CODE (var) == VAR_DECL
|
||||||
&& type_consists_of_records_p (TREE_TYPE (var)))
|
&& scalarizable_type_p (TREE_TYPE (var)))
|
||||||
{
|
{
|
||||||
if (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var)))
|
if (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var)))
|
||||||
<= max_scalarization_size)
|
<= max_scalarization_size)
|
||||||
{
|
{
|
||||||
create_total_scalarization_access (var);
|
create_total_scalarization_access (var);
|
||||||
completely_scalarize_record (var, var, 0, var);
|
completely_scalarize (var, TREE_TYPE (var), 0, var);
|
||||||
if (dump_file && (dump_flags & TDF_DETAILS))
|
if (dump_file && (dump_flags & TDF_DETAILS))
|
||||||
{
|
{
|
||||||
fprintf (dump_file, "Will attempt to totally scalarize ");
|
fprintf (dump_file, "Will attempt to totally scalarize ");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue