summaryrefslogtreecommitdiff
path: root/gcc/tree-sra.c
diff options
context:
space:
mode:
authorMartin Jambor <mjambor@suse.cz>2020-03-21 00:21:02 +0100
committerMartin Jambor <mjambor@suse.cz>2020-03-21 00:21:02 +0100
commit29f23ed79b60949fc60f6fdbbd931bd58090b241 (patch)
tree2d50bd30c920febc2b540dfca18e3dbce4189055 /gcc/tree-sra.c
parentcc3afc9db0710fe40e3d9a5e941e5e4efe7227f2 (diff)
sra: Cap number of sub-access propagations with a param (PR 93435)
PR 93435 is a perfect SRA bomb. It initializes an array of 16 chars element-wise, then uses that to initialize an aggregate that consists of four such arrays, that one to initialize one four times as big as the previous one all the way to an aggregate that has 64kb. This causes the sub-access propagation across assignments to create thousands of byte-sized artificial accesses which are then eligible to be replaced - they do facilitate forward propagation but there is enough of them for DSE to never finish. This patch avoids that situation by accounting how many of such replacements can be created per SRA candidate. The default value of 32 was just the largest power of two that did not slow down compilation of the testcase, but it should also hopefully be big enough for any reasonable input that might rely on the optimization. 2020-03-20 Martin Jambor <mjambor@suse.cz> PR tree-optimization/93435 * params.opt (sra-max-propagations): New parameter. * tree-sra.c (propagation_budget): New variable. (budget_for_propagation_access): New function. (propagate_subaccesses_from_rhs): Use it. (propagate_subaccesses_from_lhs): Likewise. (propagate_all_subaccesses): Set up and destroy propagation_budget. gcc/testsuite/ * gcc.dg/tree-ssa/pr93435.c: New test.
Diffstat (limited to 'gcc/tree-sra.c')
-rw-r--r--gcc/tree-sra.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index afff0ecd2e1..b2056b58750 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -285,6 +285,9 @@ static object_allocator<assign_link> assign_link_pool ("SRA links");
/* Base (tree) -> Vector (vec<access_p> *) map. */
static hash_map<tree, auto_vec<access_p> > *base_access_vec;
+/* Hash to limit creation of artificial accesses */
+static hash_map<tree, unsigned> *propagation_budget;
+
/* Candidate hash table helpers. */
struct uid_decl_hasher : nofree_ptr_hash <tree_node>
@@ -2687,6 +2690,32 @@ subtree_mark_written_and_rhs_enqueue (struct access *access)
subtree_mark_written_and_rhs_enqueue (child);
}
+/* If there is still budget to create a propagation access for DECL, return
+ true and decrement the budget. Otherwise return false. */
+
+static bool
+budget_for_propagation_access (tree decl)
+{
+ unsigned b, *p = propagation_budget->get (decl);
+ if (p)
+ b = *p;
+ else
+ b = param_sra_max_propagations;
+
+ if (b == 0)
+ return false;
+ b--;
+
+ if (b == 0 && dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "The propagation budget of ");
+ print_generic_expr (dump_file, decl);
+ fprintf (dump_file, " (UID: %u) has been exhausted.\n", DECL_UID (decl));
+ }
+ propagation_budget->put (decl, b);
+ return true;
+}
+
/* Propagate subaccesses and grp_write flags of RACC across an assignment link
to LACC. Enqueue sub-accesses as necessary so that the write flag is
propagated transitively. Return true if anything changed. Additionally, if
@@ -2791,7 +2820,8 @@ propagate_subaccesses_from_rhs (struct access *lacc, struct access *racc)
continue;
}
- if (rchild->grp_unscalarizable_region)
+ if (rchild->grp_unscalarizable_region
+ || !budget_for_propagation_access (lacc->base))
{
if (rchild->grp_write && !lacc->grp_write)
{
@@ -2851,7 +2881,8 @@ propagate_subaccesses_from_lhs (struct access *lacc, struct access *racc)
if (lchild->grp_unscalarizable_region
|| child_would_conflict_in_acc (racc, norm_offset, lchild->size,
- &matching_acc))
+ &matching_acc)
+ || !budget_for_propagation_access (racc->base))
{
if (matching_acc
&& propagate_subaccesses_from_lhs (lchild, matching_acc))
@@ -2882,6 +2913,7 @@ propagate_subaccesses_from_lhs (struct access *lacc, struct access *racc)
static void
propagate_all_subaccesses (void)
{
+ propagation_budget = new hash_map<tree, unsigned>;
while (rhs_work_queue_head)
{
struct access *racc = pop_access_from_rhs_work_queue ();
@@ -2945,6 +2977,7 @@ propagate_all_subaccesses (void)
add_access_to_lhs_work_queue (racc);
}
}
+ delete propagation_budget;
}
/* Return true if the forest beginning with ROOT does not contain