From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 2C8D33858D32 for ; Thu, 7 Jul 2022 08:49:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C8D33858D32 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 2F9301FD81 for ; Thu, 7 Jul 2022 08:49:08 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 2A4E82C141 for ; Thu, 7 Jul 2022 08:49:08 +0000 (UTC) Date: Thu, 7 Jul 2022 08:49:08 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Speed up LC SSA rewrite more User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jul 2022 08:49:12 -0000 Message-ID: <20220707084908.XYWXFdqUpUlwnoF7om9CcwwfQp6Sijc-6sFn5paSOcU@z> 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. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * 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. --- 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); -- 2.35.3