diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2021-09-21 10:27:53 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2021-09-27 17:39:51 +0200 |
commit | 0288527f47cec6698b31ccb3210816415506009e (patch) | |
tree | f0e5b4465af7816e61befbf1b6fe5b3138c4ab4e /gcc/tree-vrp.c | |
parent | dd11aab6463880c35d942c4a4fd346fdaeeb8e72 (diff) | |
download | gcc-0288527f47cec6698b31ccb3210816415506009e.zip gcc-0288527f47cec6698b31ccb3210816415506009e.tar.gz gcc-0288527f47cec6698b31ccb3210816415506009e.tar.bz2 |
Replace VRP threader with a hybrid forward threader.
This patch implements the new hybrid forward threader and replaces the
embedded VRP threader with it.
With all the pieces that have gone in, the implementation of the hybrid
threader is straightforward: convert the current state into
SSA imports that the solver will understand, and let the path solver
precompute ranges and relations for the path. After this setup is done,
we can use the range_query API to solve gimple statements in the threader.
The forward threader is now engine agnostic so there are no changes to
the threader per se.
I have put the hybrid bits in tree-ssa-threadedge.*, instead of VRP,
because they will also be used in the evrp removal of the DOM/threader,
which is my next task.
Most of the patch, is actually test changes. I have gone through every
single one and verified that we're correct. Most were trivial dump
file name changes, but others required going through the IL an
certifying that the different IL was expected.
For example, in pr59597.c, we have one less thread because the
ASSERT_EXPR was getting in the way, and making it seem like things were
not crossing loops. The hybrid threader sees the correct representation
of the IL, and avoids threading this one case.
The final numbers are a 12.16% improvement in jump threads immediately
after VRP, and a 0.82% improvement in overall jump threads. The
performance drop is 0.6% (plus the 1.43% hit from moving the embedded
threader into its own pass). As I've said, I'd prefer to keep the
threader in its own pass, but if this is an issue, we can address this
with a shared ranger when VRP is replaced with an evrp instance
(upcoming).
Note, that these numbers are slightly different than what I originally
posted. A few correctness tweaks, plus restricting loop threads, made
the difference. That being said, I was aiming for par. A 12% gain is
just gravy ;-). When we merge the threaders, we should see even better
numbers-- and we'll have the benefit of an entire release stress testing
the solver.
As I mentioned in my introductory note, paths ending in MEM_REF
conditional are missing. In reality, this didn't make a difference, as
it was so rare. However, as a follow-up, I will distill a test and add
a suitable PR to keep us honest.
There is a one-line change to libgomp/team.c silencing a new used
uninitialized warning. As my previous work with the threaders has
shown, warnings flare up after each improvement to jump threading. I
expect this to be no different. I've promised Jakub to investigate
fully, so I will analyze and add the appropriate PR for the warning
experts.
Oh yeah, the new pass dump is called vrp-threader[12] to match each
VRP[12] pass. However, there's no reason for it to either be named
vrp-threader, or for it to live in tree-vrp.c.
Tested on x86-64 Linux.
OK?
p.s. "Did I say 5 weeks? My bad, I meant 5 months."
gcc/ChangeLog:
* passes.def (pass_vrp_threader): New.
* tree-pass.h (make_pass_vrp_threader): Add make_pass_vrp_threader.
* tree-ssa-threadedge.c (hybrid_jt_state::register_equivs_stmt): New.
(hybrid_jt_simplifier::hybrid_jt_simplifier): New.
(hybrid_jt_simplifier::simplify): New.
(hybrid_jt_simplifier::compute_ranges_from_state): New.
* tree-ssa-threadedge.h (class hybrid_jt_state): New.
(class hybrid_jt_simplifier): New.
* tree-vrp.c (execute_vrp): Remove ASSERT_EXPR based jump
threader.
(class hybrid_threader): New.
(hybrid_threader::hybrid_threader): New.
(hybrid_threader::~hybrid_threader): New.
(hybrid_threader::before_dom_children): New.
(hybrid_threader::after_dom_children): New.
(execute_vrp_threader): New.
(class pass_vrp_threader): New.
(make_pass_vrp_threader): New.
libgomp/ChangeLog:
* team.c: Initialize start_data.
* testsuite/libgomp.graphite/force-parallel-4.c: Adjust.
* testsuite/libgomp.graphite/force-parallel-8.c: Adjust.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr55107.c: Adjust.
* gcc.dg/tree-ssa/phi_on_compare-1.c: Adjust.
* gcc.dg/tree-ssa/phi_on_compare-2.c: Adjust.
* gcc.dg/tree-ssa/phi_on_compare-3.c: Adjust.
* gcc.dg/tree-ssa/phi_on_compare-4.c: Adjust.
* gcc.dg/tree-ssa/pr21559.c: Adjust.
* gcc.dg/tree-ssa/pr59597.c: Adjust.
* gcc.dg/tree-ssa/pr61839_1.c: Adjust.
* gcc.dg/tree-ssa/pr61839_3.c: Adjust.
* gcc.dg/tree-ssa/pr71437.c: Adjust.
* gcc.dg/tree-ssa/ssa-dom-thread-11.c: Adjust.
* gcc.dg/tree-ssa/ssa-dom-thread-16.c: Adjust.
* gcc.dg/tree-ssa/ssa-dom-thread-18.c: Adjust.
* gcc.dg/tree-ssa/ssa-dom-thread-2a.c: Adjust.
* gcc.dg/tree-ssa/ssa-dom-thread-4.c: Adjust.
* gcc.dg/tree-ssa/ssa-thread-14.c: Adjust.
* gcc.dg/tree-ssa/ssa-vrp-thread-1.c: Adjust.
* gcc.dg/tree-ssa/vrp106.c: Adjust.
* gcc.dg/tree-ssa/vrp55.c: Adjust.
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r-- | gcc/tree-vrp.c | 143 |
1 files changed, 123 insertions, 20 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index a5079ee..c55a749 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -66,6 +66,8 @@ along with GCC; see the file COPYING3. If not see #include "range-op.h" #include "value-range-equiv.h" #include "gimple-array-bounds.h" +#include "gimple-range.h" +#include "gimple-range-path.h" #include "tree-ssa-dom.h" /* Set of SSA names found live during the RPO traversal of the function @@ -4591,11 +4593,6 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p) array_checker.check (); } - /* We must identify jump threading opportunities before we release - the datastructures built by VRP. */ - vrp_jump_threader threader (fun, &vrp_vr_values); - threader.thread_jumps (); - simplify_casted_conds (fun, &vrp_vr_values); free_numbers_of_iterations_estimates (fun); @@ -4605,21 +4602,6 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p) does not properly handle ASSERT_EXPRs. */ assert_engine.remove_range_assertions (); - /* If we exposed any new variables, go ahead and put them into - SSA form now, before we handle jump threading. This simplifies - interactions between rewriting of _DECL nodes into SSA form - and rewriting SSA_NAME nodes into SSA form after block - duplication and CFG manipulation. */ - update_ssa (TODO_update_ssa); - - /* We identified all the jump threading opportunities earlier, but could - not transform the CFG at that time. This routine transforms the - CFG and arranges for the dominator tree to be rebuilt if necessary. - - Note the SSA graph update will occur during the normal TODO - processing by the pass manager. */ - threader.thread_through_all_blocks (); - scev_finalize (); loop_optimizer_finalize (); return 0; @@ -4669,3 +4651,124 @@ make_pass_vrp (gcc::context *ctxt) { return new pass_vrp (ctxt); } + +// This is the dom walker for the hybrid threader. The reason this is +// here, as opposed to the generic threading files, is because the +// other client would be DOM, and they have their own custom walker. + +class hybrid_threader : public dom_walker +{ +public: + hybrid_threader (); + ~hybrid_threader (); + + void thread_jumps (function *fun) + { + walk (fun->cfg->x_entry_block_ptr); + } + void thread_through_all_blocks () + { + m_threader->thread_through_all_blocks (false); + } + +private: + edge before_dom_children (basic_block) override; + void after_dom_children (basic_block bb) override; + + hybrid_jt_simplifier *m_simplifier; + jump_threader *m_threader; + jt_state *m_state; + gimple_ranger *m_ranger; + path_range_query *m_query; +}; + +hybrid_threader::hybrid_threader () : dom_walker (CDI_DOMINATORS, REACHABLE_BLOCKS) +{ + loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS); + scev_initialize (); + calculate_dominance_info (CDI_DOMINATORS); + mark_dfs_back_edges (); + + m_ranger = new gimple_ranger; + m_query = new path_range_query (*m_ranger, /*resolve=*/true); + m_simplifier = new hybrid_jt_simplifier (m_ranger, m_query); + m_state = new hybrid_jt_state; + m_threader = new jump_threader (m_simplifier, m_state); +} + +hybrid_threader::~hybrid_threader () +{ + delete m_simplifier; + delete m_threader; + delete m_state; + delete m_ranger; + + scev_finalize (); + loop_optimizer_finalize (); +} + +edge +hybrid_threader::before_dom_children (basic_block bb) +{ + gimple_stmt_iterator gsi; + int_range<2> r; + + for (gsi = gsi_start_nondebug_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + m_ranger->range_of_stmt (r, stmt); + } + return NULL; +} + +void +hybrid_threader::after_dom_children (basic_block bb) +{ + m_threader->thread_outgoing_edges (bb); +} + +static unsigned int +execute_vrp_threader (function *fun) +{ + hybrid_threader threader; + threader.thread_jumps (fun); + threader.thread_through_all_blocks (); + return 0; +} + +namespace { + +const pass_data pass_data_vrp_threader = +{ + GIMPLE_PASS, /* type */ + "vrp-thread", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_TREE_VRP, /* tv_id */ + PROP_ssa, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + ( TODO_cleanup_cfg | TODO_update_ssa ), /* todo_flags_finish */ +}; + +class pass_vrp_threader : public gimple_opt_pass +{ +public: + pass_vrp_threader (gcc::context *ctxt) + : gimple_opt_pass (pass_data_vrp_threader, ctxt) + {} + + /* opt_pass methods: */ + opt_pass * clone () { return new pass_vrp_threader (m_ctxt); } + virtual bool gate (function *) { return flag_tree_vrp != 0; } + virtual unsigned int execute (function *fun) + { return execute_vrp_threader (fun); } +}; + +} // namespace { + +gimple_opt_pass * +make_pass_vrp_threader (gcc::context *ctxt) +{ + return new pass_vrp_threader (ctxt); +} |