Skip to content

Commit e7b7188

Browse files
committed
tree-optimization/114557 - reduce ehcleanup peak memory use
The following reduces peak memory use for the PR114480 testcase at -O1 which is almost exclusively spent by the ehcleanup pass in allocating PHI nodes. The free_phinodes cache we maintain isn't very effective since it has effectively two slots, one for 4 and one for 9 argument PHIs and it is only ever used for allocations up to 9 arguments but we put all larger PHIs in the 9 argument bucket. This proves uneffective resulting in much garbage to be kept when incrementally growing PHI nodes by edge redirection. The mitigation is to rely on the GC freelist for larger sizes and thus immediately return all larger bucket sized PHIs to it via ggc_free. This reduces the peak memory use from 19.8GB to 11.3GB and compile-time from 359s to 168s. PR tree-optimization/114557 PR tree-optimization/114480 * tree-phinodes.cc (release_phi_node): Return PHIs from allocation buckets not covered by free_phinodes to GC. (remove_phi_node): Release the PHI LHS before freeing the PHI node. * tree-vect-loop.cc (vectorizable_live_operation): Get PHI lhs before releasing it.
1 parent 8677182 commit e7b7188

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

gcc/tree-phinodes.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ release_phi_node (gimple *phi)
223223
delink_imm_use (imm);
224224
}
225225

226+
/* Immediately return the memory to the allocator when we would
227+
only ever re-use it for a smaller size allocation. */
228+
if (len - 2 >= NUM_BUCKETS - 2)
229+
{
230+
ggc_free (phi);
231+
return;
232+
}
233+
226234
bucket = len > NUM_BUCKETS - 1 ? NUM_BUCKETS - 1 : len;
227235
bucket -= 2;
228236
vec_safe_push (free_phinodes[bucket], phi);
@@ -445,9 +453,9 @@ remove_phi_node (gimple_stmt_iterator *gsi, bool release_lhs_p)
445453

446454
/* If we are deleting the PHI node, then we should release the
447455
SSA_NAME node so that it can be reused. */
448-
release_phi_node (phi);
449456
if (release_lhs_p)
450457
release_ssa_name (gimple_phi_result (phi));
458+
release_phi_node (phi);
451459
}
452460

453461
/* Remove all the phi nodes from BB. */

gcc/tree-vect-loop.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10962,8 +10962,8 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
1096210962
lhs_type, &exit_gsi);
1096310963

1096410964
auto gsi = gsi_for_stmt (use_stmt);
10965-
remove_phi_node (&gsi, false);
1096610965
tree lhs_phi = gimple_phi_result (use_stmt);
10966+
remove_phi_node (&gsi, false);
1096710967
gimple *copy = gimple_build_assign (lhs_phi, new_tree);
1096810968
gsi_insert_before (&exit_gsi, copy, GSI_SAME_STMT);
1096910969
break;

0 commit comments

Comments
 (0)