https://gcc.gnu.org/g:345d121a56a34e59e189a687b27953266fcd7613
commit r17-5249-g345d121a56a34e59e189a687b27953266fcd7613 Author: Aldy Hernandez <[email protected]> Date: Fri Oct 16 08:58:52 2026 +0000 path solver: factor the closure of the exit dependencies compute_exit_dependencies closes the imports of the exit block over the operands defining them. Split the loop out into into a separate method, so a later patch can close a set of names of its own. No functional change. Tested on ppc64le Linux. gcc/ChangeLog: * gimple-range-path.h (path_range_query::close_dependencies): New. (path_range_query::add_dependencies_of): New. * gimple-range-path.cc (path_range_query::add_dependencies_of): New, split out of... (path_range_query::compute_exit_dependencies): ...here. (path_range_query::close_dependencies): New, likewise. Diff: --- gcc/gimple-range-path.cc | 89 +++++++++++++++++++++++++++++------------------- gcc/gimple-range-path.h | 5 +++ 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 167d57397a8b..784f8dc585cd 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -496,16 +496,49 @@ path_range_query::add_to_exit_dependencies (tree name, bitmap dependencies) return false; } -// Compute the exit dependencies to PATH. These are essentially the -// SSA names used to calculate the final conditional along the path. +// Add to DEPENDENCIES the operands used to define NAME along PATH, +// and push the new ones onto WORKLIST. void -path_range_query::compute_exit_dependencies (bitmap dependencies) +path_range_query::add_dependencies_of (tree name, + const vec<basic_block> &path, + bitmap dependencies, + vec<tree> &worklist) { - // Start with the imports from the exit block... - basic_block exit = m_path[0]; - bitmap_copy (dependencies, gori_ssa ()->imports (exit)); + gimple *def_stmt = SSA_NAME_DEF_STMT (name); + if (SSA_NAME_IS_DEFAULT_DEF (name) + || !path.contains (gimple_bb (def_stmt))) + return; + + if (gphi *phi = dyn_cast <gphi *> (def_stmt)) + { + for (size_t i = 0; i < gimple_phi_num_args (phi); ++i) + { + edge e = gimple_phi_arg_edge (phi, i); + tree arg = gimple_phi_arg (phi, i)->def; + if (TREE_CODE (arg) == SSA_NAME + && path.contains (e->src) + && bitmap_set_bit (dependencies, SSA_NAME_VERSION (arg))) + worklist.safe_push (arg); + } + } + else if (gassign *ass = dyn_cast <gassign *> (def_stmt)) + { + tree ssa[3]; + unsigned count = gimple_range_ssa_names (ssa, 3, ass); + for (unsigned j = 0; j < count; ++j) + if (add_to_exit_dependencies (ssa[j], dependencies)) + worklist.safe_push (ssa[j]); + } +} + +// Close DEPENDENCIES along PATH over add_dependencies_of. + +void +path_range_query::close_dependencies (const vec<basic_block> &path, + bitmap dependencies) +{ auto_vec<tree> worklist (bitmap_count_bits (dependencies)); bitmap_iterator bi; unsigned i; @@ -515,40 +548,26 @@ path_range_query::compute_exit_dependencies (bitmap dependencies) worklist.quick_push (name); } - // ...and add any operands used to define these imports. while (!worklist.is_empty ()) - { - tree name = worklist.pop (); - gimple *def_stmt = SSA_NAME_DEF_STMT (name); - if (SSA_NAME_IS_DEFAULT_DEF (name) - || !m_path.contains (gimple_bb (def_stmt))) - continue; + add_dependencies_of (worklist.pop (), path, dependencies, worklist); +} - if (gphi *phi = dyn_cast <gphi *> (def_stmt)) - { - for (size_t i = 0; i < gimple_phi_num_args (phi); ++i) - { - edge e = gimple_phi_arg_edge (phi, i); - tree arg = gimple_phi_arg (phi, i)->def; +// Compute the exit dependencies to PATH. These are essentially the +// SSA names used to calculate the final conditional along the path. + +void +path_range_query::compute_exit_dependencies (bitmap dependencies) +{ + // Start with the imports from the exit block... + basic_block exit = m_path[0]; + bitmap_copy (dependencies, gori_ssa ()->imports (exit)); + + // ...and add any operands used to define these imports. + close_dependencies (m_path, dependencies); - if (TREE_CODE (arg) == SSA_NAME - && m_path.contains (e->src) - && bitmap_set_bit (dependencies, SSA_NAME_VERSION (arg))) - worklist.safe_push (arg); - } - } - else if (gassign *ass = dyn_cast <gassign *> (def_stmt)) - { - tree ssa[3]; - unsigned count = gimple_range_ssa_names (ssa, 3, ass); - for (unsigned j = 0; j < count; ++j) - if (add_to_exit_dependencies (ssa[j], dependencies)) - worklist.safe_push (ssa[j]); - } - } // Exported booleans along the path, may help conditionals. if (m_resolve) - for (i = 0; i < m_path.length (); ++i) + for (unsigned i = 0; i < m_path.length (); ++i) { basic_block bb = m_path[i]; tree name; diff --git a/gcc/gimple-range-path.h b/gcc/gimple-range-path.h index 3e37eeb7175e..320bbb2b9755 100644 --- a/gcc/gimple-range-path.h +++ b/gcc/gimple-range-path.h @@ -51,6 +51,11 @@ public: void dump (FILE *) override; void debug (); +protected: + void close_dependencies (const vec<basic_block> &, bitmap dependencies); + void add_dependencies_of (tree name, const vec<basic_block> &, + bitmap dependencies, vec<tree> &worklist); + private: bool internal_range_of_expr (vrange &r, tree name, gimple *); void compute_ranges (const bitmap_head *dependencies);
