From 6f36cc2535c11b9406715836daeb87169fa79473 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 22 May 2024 19:27:01 -0400 Subject: More tweaks from gimple_outgoing_range changes. the dom_ranger used for fast vrp no longer needs a local gimple_outgoing_range object as it is now always available from the range_query parent class. The builtin_unreachable code for adjusting globals and removing the builtin calls during the final VRP pass can now function with just a range_query object rather than a specific ranger. This adjusts it to use the extra methods in the range_query API. This will now allow removal of builtin_unreachable calls even if there is no active ranger with dependency info available. * gimple-range.cc (dom_ranger::dom_ranger): Do not initialize m_out. (dom_ranger::maybe_push_edge): Use gori () rather than m_out. * gimple-range.h (dom_ranger::m_out): Remove. * tree-vrp.cc (remove_unreachable::remove_unreachable): Use a range-query ranther than a gimple_ranger. (remove_unreachable::remove): New. (remove_unreachable::m_ranger): Change to a range_query. (remove_unreachable::handle_early): If there is no dependency information, do nothing. (remove_unreachable::remove_and_update_globals): Do not update globals if there is no dependecy info to use. --- gcc/tree-vrp.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'gcc/tree-vrp.cc') diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index 7d7f9fe..1c7b451 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -85,14 +85,15 @@ along with GCC; see the file COPYING3. If not see class remove_unreachable { public: - remove_unreachable (gimple_ranger &r, bool all) : m_ranger (r), final_p (all) + remove_unreachable (range_query &r, bool all) : m_ranger (r), final_p (all) { m_list.create (30); } ~remove_unreachable () { m_list.release (); } void handle_early (gimple *s, edge e); void maybe_register (gimple *s); + bool remove (); bool remove_and_update_globals (); vec > m_list; - gimple_ranger &m_ranger; + range_query &m_ranger; bool final_p; }; @@ -195,6 +196,9 @@ fully_replaceable (tree name, basic_block bb) void remove_unreachable::handle_early (gimple *s, edge e) { + // If there is no gori_ssa, there is no early processsing. + if (!m_ranger.gori_ssa ()) + return ; bool lhs_p = TREE_CODE (gimple_cond_lhs (s)) == SSA_NAME; bool rhs_p = TREE_CODE (gimple_cond_rhs (s)) == SSA_NAME; // Do not remove __builtin_unreachable if it confers a relation, or @@ -253,6 +257,41 @@ remove_unreachable::handle_early (gimple *s, edge e) } } +// Process the edges in the list, change the conditions and removing any +// dead code feeding those conditions. This removes the unreachables, but +// makes no attempt to set globals values. + +bool +remove_unreachable::remove () +{ + if (!final_p || m_list.length () == 0) + return false; + + bool change = false; + unsigned i; + for (i = 0; i < m_list.length (); i++) + { + auto eb = m_list[i]; + basic_block src = BASIC_BLOCK_FOR_FN (cfun, eb.first); + basic_block dest = BASIC_BLOCK_FOR_FN (cfun, eb.second); + if (!src || !dest) + continue; + edge e = find_edge (src, dest); + gimple *s = gimple_outgoing_range_stmt_p (e->src); + gcc_checking_assert (gimple_code (s) == GIMPLE_COND); + + change = true; + // Rewrite the condition. + if (e->flags & EDGE_TRUE_VALUE) + gimple_cond_make_true (as_a (s)); + else + gimple_cond_make_false (as_a (s)); + update_stmt (s); + } + + return change; +} + // Process the edges in the list, change the conditions and removing any // dead code feeding those conditions. Calculate the range of any @@ -266,6 +305,10 @@ remove_unreachable::remove_and_update_globals () if (m_list.length () == 0) return false; + // If there is no import/export info, just remove unreachables if necessary. + if (!m_ranger.gori_ssa ()) + return remove (); + // Ensure the cache in SCEV has been cleared before processing // globals to be removed. scev_reset (); -- cgit v1.1