From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 932B03858412; Wed, 24 Nov 2021 14:34:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 932B03858412 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v3)] Add caching of BB insns. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/loop-unswitch-improvement-v3 X-Git-Oldrev: d1c5ce63cd41244bcc0c96f664952ff46e5388e0 X-Git-Newrev: 099d62f35327cbce186df2e70076826bb4ea6833 Message-Id: <20211124143402.932B03858412@sourceware.org> Date: Wed, 24 Nov 2021 14:34:02 +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: Wed, 24 Nov 2021 14:34:02 -0000 https://gcc.gnu.org/g:099d62f35327cbce186df2e70076826bb4ea6833 commit 099d62f35327cbce186df2e70076826bb4ea6833 Author: Martin Liska Date: Wed Nov 24 12:12:25 2021 +0100 Add caching of BB insns. Diff: --- gcc/tree-ssa-loop-unswitch.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index 57ddd769b31..35b8be935b2 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -106,6 +106,24 @@ static void hoist_guard (class loop *, edge); static bool check_exit_phi (class loop *); static tree get_vop_from_header (class loop *); +static void +calculate_loop_insns (class loop *loop) +{ + basic_block *bbs = get_loop_body (loop); + + for (unsigned i = 0; i < loop->num_nodes; i++) + { + unsigned insns = 0; + for (gimple_stmt_iterator gsi = gsi_start_bb (bbs[i]); !gsi_end_p (gsi); + gsi_next (&gsi)) + insns += estimate_num_insns (gsi_stmt (gsi), &eni_size_weights); + + bbs[i]->aux = (void *)(size_t)insns; + } + + free (bbs); +} + /* Main entry point. Perform loop unswitching on all suitable loops. */ unsigned int @@ -119,8 +137,11 @@ tree_ssa_unswitch_loops (void) for (auto loop : loops_list (cfun, LI_FROM_INNERMOST)) { if (!loop->inner) - /* Unswitch innermost loop. */ - changed |= tree_unswitch_single_loop (loop, 0, ranger, NULL, false); + { + /* Unswitch innermost loop. */ + calculate_loop_insns (loop); + changed |= tree_unswitch_single_loop (loop, 0, ranger, NULL, false); + } else changed |= tree_unswitch_outer_loop (loop); } @@ -418,9 +439,7 @@ evaluate_insns (class loop *loop, basic_block *bbs, for (unsigned i = 0; i < loop->num_nodes; i++) if (bbs[i]->flags & reachable_flag) - for (gimple_stmt_iterator gsi = gsi_start_bb (bbs[i]); !gsi_end_p (gsi); - gsi_next (&gsi)) - size += estimate_num_insns (gsi_stmt (gsi), &eni_size_weights); + size += (size_t)bbs[i]->aux; /* Clear the flag from basic blocks. */ for (unsigned i = 0; i < loop->num_nodes; i++) @@ -544,6 +563,13 @@ tree_unswitch_single_loop (class loop *loop, int num, gimple_ranger *ranger, goto exit; } + /* Copy BB costs. */ + basic_block *bbs2 = get_loop_body (nloop); + for (unsigned i = 0; i < nloop->num_nodes; i++) + bbs2[i]->aux = get_bb_original (bbs2[i])->aux; + + free (bbs2); + /* Update the SSA form after unswitching. */ update_ssa (TODO_update_ssa); free_original_copy_tables ();