From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1075) id DA9433858C39; Thu, 7 Oct 2021 10:11:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA9433858C39 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jan Hubicka To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/hubicka/heads/honza-gcc-benchmark-branch-v2)] Add early loop unrolling. X-Act-Checkin: gcc X-Git-Author: Jan Hubicka X-Git-Refname: refs/users/hubicka/heads/honza-gcc-benchmark-branch-v2 X-Git-Oldrev: caa80f2f10e6e67b43fba3bcafa8c07e13c8c407 X-Git-Newrev: 6edc7d3ba0654401089a627b9272952f66cd659f Message-Id: <20211007101118.DA9433858C39@sourceware.org> Date: Thu, 7 Oct 2021 10:11:18 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 10:11:19 -0000 https://gcc.gnu.org/g:6edc7d3ba0654401089a627b9272952f66cd659f commit 6edc7d3ba0654401089a627b9272952f66cd659f Author: Jan Hubicka Date: Thu Oct 7 12:10:56 2021 +0200 Add early loop unrolling. Diff: --- gcc/ipa-modref-tree.h | 7 +++++- gcc/opts.c | 1 + gcc/passes.def | 1 + gcc/tree-pass.h | 1 + gcc/tree-ssa-loop-ivcanon.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h index 6a9ed5ce54b..f3f6e123d67 100644 --- a/gcc/ipa-modref-tree.h +++ b/gcc/ipa-modref-tree.h @@ -616,7 +616,12 @@ private: if (n->contains (*a)) found = true; - if (!found && n->merge (*a, false)) + else if (a->contains (n)) + { + *n = a; + found = true; + } + else if (n->merge (*a, false)) found = restart = true; if (found) { diff --git a/gcc/opts.c b/gcc/opts.c index fae3a121146..1d2d22d7a3f 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -561,6 +561,7 @@ static const struct default_options default_options_table[] = { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 }, + { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fipa_reference_addressable, NULL, 1 }, { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 }, diff --git a/gcc/passes.def b/gcc/passes.def index d7a1f8c97a6..64b4b7ec45f 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -83,6 +83,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_forwprop); NEXT_PASS (pass_early_thread_jumps); NEXT_PASS (pass_sra_early); + NEXT_PASS (pass_early_complete_unrolli); /* pass_build_ealias is a dummy pass that ensures that we execute TODO_rebuild_alias at this point. */ NEXT_PASS (pass_build_ealias); diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index eb75eb17951..a3959322b29 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -389,6 +389,7 @@ extern gimple_opt_pass *make_pass_simduid_cleanup (gcc::context *ctxt); extern gimple_opt_pass *make_pass_slp_vectorize (gcc::context *ctxt); extern gimple_opt_pass *make_pass_complete_unroll (gcc::context *ctxt); extern gimple_opt_pass *make_pass_complete_unrolli (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_early_complete_unrolli (gcc::context *ctxt); extern gimple_opt_pass *make_pass_pre_slp_scalar_cleanup (gcc::context *ctxt); extern gimple_opt_pass *make_pass_parallelize_loops (gcc::context *ctxt); extern gimple_opt_pass *make_pass_loop_prefetch (gcc::context *ctxt); diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c index 8d8791f837e..84c79e84ad8 100644 --- a/gcc/tree-ssa-loop-ivcanon.c +++ b/gcc/tree-ssa-loop-ivcanon.c @@ -1673,3 +1673,60 @@ make_pass_complete_unrolli (gcc::context *ctxt) } + +/* Complete unrolling of inner loops. */ + +namespace { + +const pass_data pass_data_early_complete_unrolli = +{ + GIMPLE_PASS, /* type */ + "early-cunrolli", /* name */ + OPTGROUP_LOOP, /* optinfo_flags */ + TV_COMPLETE_UNROLL, /* tv_id */ + ( PROP_cfg | PROP_ssa ), /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_early_complete_unrolli : public gimple_opt_pass +{ +public: + pass_early_complete_unrolli (gcc::context *ctxt) + : gimple_opt_pass (pass_data_early_complete_unrolli, ctxt) + {} + + /* opt_pass methods: */ + virtual bool gate (function *) { return optimize >= 2; } + virtual unsigned int execute (function *); + +}; // class pass_early_complete_unrolli + +unsigned int +pass_early_complete_unrolli::execute (function *fun) +{ + unsigned ret = 0; + + loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS); + if (number_of_loops (fun) > 1) + { + scev_initialize (); + ret = tree_unroll_loops_completely (false, false); + scev_finalize (); + } + loop_optimizer_finalize (); + + return ret; +} + +} // anon namespace + +gimple_opt_pass * +make_pass_early_complete_unrolli (gcc::context *ctxt) +{ + return new pass_early_complete_unrolli (ctxt); +} + +