From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 08D2F3857360; Thu, 7 Jul 2022 08:50:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08D2F3857360 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1551] Speed up LC SSA rewrite more X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: e5a9d60317852a7323e46109fa366e630b8b5bae X-Git-Newrev: 1e1fdb729d99647bb90d8a18afa1a5fc3c2d3a22 Message-Id: <20220707085012.08D2F3857360@sourceware.org> Date: Thu, 7 Jul 2022 08:50:12 +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 Jul 2022 08:50:12 -0000 https://gcc.gnu.org/g:1e1fdb729d99647bb90d8a18afa1a5fc3c2d3a22 commit r13-1551-g1e1fdb729d99647bb90d8a18afa1a5fc3c2d3a22 Author: Richard Biener Date: Thu Jul 7 09:29:55 2022 +0200 Speed up LC SSA rewrite more In many cases loops have only one exit or a variable is only live across one of the exits. In this case we know that all uses outside of the loop will be dominated by the single LC PHI node we insert. If that holds for all variables requiring LC SSA PHIs then we can simplify the update_ssa process, avoiding the (iterated) dominance frontier computations. * tree-ssa-loop-manip.cc (add_exit_phis_var): Return the number of LC PHIs inserted. (add_exit_phis): Return whether any variable required multiple LC PHI nodes. (rewrite_into_loop_closed_ssa_1): Use TODO_update_ssa_no_phi when possible. Diff: --- gcc/tree-ssa-loop-manip.cc | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/gcc/tree-ssa-loop-manip.cc b/gcc/tree-ssa-loop-manip.cc index 0324ff60a0f..c531f1f12fd 100644 --- a/gcc/tree-ssa-loop-manip.cc +++ b/gcc/tree-ssa-loop-manip.cc @@ -314,9 +314,10 @@ add_exit_phi (basic_block exit, tree var) } /* Add exit phis for VAR that is used in LIVEIN. - Exits of the loops are stored in LOOP_EXITS. */ + Exits of the loops are stored in LOOP_EXITS. Returns the number + of PHIs added for VAR. */ -static void +static unsigned add_exit_phis_var (tree var, bitmap use_blocks, bitmap def_loop_exits) { unsigned index; @@ -328,10 +329,13 @@ add_exit_phis_var (tree var, bitmap use_blocks, bitmap def_loop_exits) auto_bitmap live_exits (&loop_renamer_obstack); compute_live_loop_exits (live_exits, use_blocks, def_bb, def_loop_exits); + unsigned cnt = 0; EXECUTE_IF_SET_IN_BITMAP (live_exits, 0, index, bi) { add_exit_phi (BASIC_BLOCK_FOR_FN (cfun, index), var); + cnt++; } + return cnt; } static int @@ -348,13 +352,15 @@ loop_name_cmp (const void *p1, const void *p2) /* Add exit phis for the names marked in NAMES_TO_RENAME. Exits of the loops are stored in EXITS. Sets of blocks where the ssa - names are used are stored in USE_BLOCKS. */ + names are used are stored in USE_BLOCKS. Returns whether any name + required multiple LC PHI nodes. */ -static void +static bool add_exit_phis (bitmap names_to_rename, bitmap *use_blocks) { unsigned i; bitmap_iterator bi; + bool multiple_p = false; /* Sort names_to_rename after definition loop so we can avoid re-computing def_loop_exits. */ @@ -381,9 +387,12 @@ add_exit_phis (bitmap names_to_rename, bitmap *use_blocks) for (auto exit = loop->exits->next; exit->e; exit = exit->next) bitmap_set_bit (def_loop_exits, exit->e->dest->index); } - add_exit_phis_var (ssa_name (p.second), use_blocks[p.second], - def_loop_exits); + if (add_exit_phis_var (ssa_name (p.second), use_blocks[p.second], + def_loop_exits) > 1) + multiple_p = true; } + + return multiple_p; } /* For USE in BB, if it is used outside of the loop it is defined in, @@ -588,15 +597,18 @@ rewrite_into_loop_closed_ssa_1 (bitmap changed_bbs, unsigned update_flag, } /* Add the PHI nodes on exits of the loops for the names we need to - rewrite. */ - add_exit_phis (names_to_rename, use_blocks); + rewrite. When no variable required multiple LC PHI nodes to be + inserted then we know that all uses outside of the loop are + dominated by the single LC SSA definition and no further PHI + node insertions are required. */ + bool need_phis_p = add_exit_phis (names_to_rename, use_blocks); if (release_recorded_exits_p) release_recorded_exits (cfun); /* Fix up all the names found to be used outside their original loops. */ - update_ssa (TODO_update_ssa); + update_ssa (need_phis_p ? TODO_update_ssa : TODO_update_ssa_no_phi); } bitmap_obstack_release (&loop_renamer_obstack);