From 011d0a033ab370ea38b06b813ac62be8dde0801b Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Wed, 17 Aug 2022 13:18:01 +0200 Subject: Make path_range_query standalone and add reset_path. These are a bunch of cleanups inspired by Richi's suggestion of making path_range_query standalone, instead of having to call compute_ranges() for each path. I've made the ranger need explicit, and moved the responsibility for its creation to the caller. I've also investigated and documented why the forward threader needs its own compute exit dependencies variant. I can't wait for it to go away :-/. I've also added constructors that take a path and dependencies, and made compute_ranges() private. Unfortunately, reinstantiating path_range_query in the forward threader caused a 14% performance regression in DOM, because the old threader calls it over and over on the same path to simplify statements (some of which not even in the IL, but that's old news). In the meantime, I've left the ability to reset a path, but this time appropriately called reset_path(). Tested, benchmarked, and thread counted on x86-64 Linux. gcc/ChangeLog: * gimple-range-path.cc (path_range_query::path_range_query): Add various constructors to take a path. (path_range_query::~path_range_query): Remove m_alloced_ranger. (path_range_query::range_on_path_entry): Adjust for m_ranger being a reference. (path_range_query::set_path): Rename to... (path_range_query::reset_path): ...this and call compute_ranges. (path_range_query::ssa_range_in_phi): Adjust for m_ranger reference. (path_range_query::range_defined_in_block): Same. (path_range_query::compute_ranges_in_block): Same. (path_range_query::adjust_for_non_null_uses): Same. (path_range_query::compute_exit_dependencies): Use m_path instead of argument. (path_range_query::compute_ranges): Remove path argument. (path_range_query::range_of_stmt): Adjust for m_ranger reference. (path_range_query::compute_outgoing_relations): Same. * gimple-range-path.h (class path_range_query): Add various constructors. Make compute_ranges and compute_exit_dependencies private. Rename set_path to reset_path. Make m_ranger a reference. Remove m_alloced_ranger. * tree-ssa-dom.cc (pass_dominator::execute): Adjust constructor to path_range_query. * tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Take a ranger and instantiate a new path_range_query every time. (ch_base::copy_headers): Pass ranger instead of path_range_query. * tree-ssa-threadbackward.cc (class back_threader): Remove m_solver. (back_threader::~back_threader): Remove m_solver. (back_threader::find_taken_edge_switch): Adjust for m_ranger reference. (back_threader::find_taken_edge_cond): Same. (back_threader::dump): Remove m_solver. (back_threader::back_threader): Move verify_marked_backedges here from the path_range_query constructor. * tree-ssa-threadedge.cc (hybrid_jt_simplifier::simplify): Move some code from compute_ranges_from_state here. (hybrid_jt_simplifier::compute_ranges_from_state): Rename... (hybrid_jt_simplifier::compute_exit_dependencies): ...to this. * tree-ssa-threadedge.h (class hybrid_jt_simplifier): Rename compute_ranges_from_state to compute_exit_dependencies. Remove m_path. --- gcc/tree-ssa-loop-ch.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 3b91a89..96816b8 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -49,7 +49,7 @@ along with GCC; see the file COPYING3. If not see be statically determined. */ static bool -entry_loop_condition_is_static (class loop *l, path_range_query *query) +entry_loop_condition_is_static (class loop *l, gimple_ranger *ranger) { edge e = loop_preheader_edge (l); gcond *last = safe_dyn_cast (last_stmt (e->dest)); @@ -72,8 +72,8 @@ entry_loop_condition_is_static (class loop *l, path_range_query *query) desired_static_value = boolean_true_node; int_range<2> r; - query->compute_ranges (e); - query->range_of_stmt (r, last); + path_range_query query (*ranger, e); + query.range_of_stmt (r, last); return r == int_range<2> (desired_static_value, desired_static_value); } @@ -385,7 +385,7 @@ ch_base::copy_headers (function *fun) auto_vec > copied; mark_dfs_back_edges (); - path_range_query *query = new path_range_query; + gimple_ranger *ranger = new gimple_ranger; for (auto loop : loops_list (cfun, 0)) { int initial_limit = param_max_loop_header_insns; @@ -409,7 +409,7 @@ ch_base::copy_headers (function *fun) iteration. */ if (optimize_loop_for_size_p (loop) && !loop->force_vectorize - && !entry_loop_condition_is_static (loop, query)) + && !entry_loop_condition_is_static (loop, ranger)) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, @@ -422,7 +422,7 @@ ch_base::copy_headers (function *fun) candidates.safe_push (loop); } /* Do not use ranger after we change the IL and not have updated SSA. */ - delete query; + delete ranger; for (auto loop : candidates) { -- cgit v1.1 From 338a296dd76bf3d253a990ddb65e1bbef0c680a7 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Thu, 18 Aug 2022 17:55:19 +0200 Subject: Remove path_range_query constructor that takes an edge. The path_range_query constructor that takes an edge is really a convenience function for the loop-ch pass. It feels wrong to pollute the API with such a specialized function that could be done with a small inline function closer to its user. As an added benefit, we remove one use of reset_path. The last remaining one is the forward threader one. Tested, thread-counted, and benchmarked on x86-64 Linux. gcc/ChangeLog: * gimple-range-path.cc (path_range_query::path_range_query): Remove constructor that takes edge. * gimple-range-path.h (class path_range_query): Same. * tree-ssa-loop-ch.cc (edge_range_query): New. (entry_loop_condition_is_static): Call edge_range_query. --- gcc/tree-ssa-loop-ch.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 96816b8..9c31688 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -45,6 +45,20 @@ along with GCC; see the file COPYING3. If not see increases effectiveness of code motion optimizations, and reduces the need for loop preconditioning. */ +/* Given a path through edge E, whose last statement is COND, return + the range of the solved conditional in R. */ + +static void +edge_range_query (irange &r, edge e, gcond *cond, gimple_ranger &ranger) +{ + auto_vec path (2); + path.safe_push (e->dest); + path.safe_push (e->src); + path_range_query query (ranger, path); + if (!query.range_of_stmt (r, cond)) + r.set_varying (boolean_type_node); +} + /* Return true if the condition on the first iteration of the loop can be statically determined. */ @@ -72,8 +86,7 @@ entry_loop_condition_is_static (class loop *l, gimple_ranger *ranger) desired_static_value = boolean_true_node; int_range<2> r; - path_range_query query (*ranger, e); - query.range_of_stmt (r, last); + edge_range_query (r, e, last, *ranger); return r == int_range<2> (desired_static_value, desired_static_value); } -- cgit v1.1