From patchwork Mon Jul 4 08:36:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1651871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=bX3WdCUB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lbzgk4G3Sz9sFs for ; Mon, 4 Jul 2022 18:37:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44CB83856DE0 for ; Mon, 4 Jul 2022 08:37:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44CB83856DE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656923821; bh=JHDsTiU/bSQGH93PBoEXNZkLU500OryF/TAKxkEeLqE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bX3WdCUBouhr0XEcXv6EcK+qe/nPlZ6yW4FUDME3afKFN1DnUrj0O+ZnXDpVkEQCS qI0MMmIv2e0H71cBYFwX0tg5C7rqWqQeI2OegyszPr695GHzXiwmlsZcLyZ0Ci3Aav aqoKV9DvogDccCKOUXpMf59ZbYD7HvhzQRGcUMZc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 263193858C52 for ; Mon, 4 Jul 2022 08:36:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 263193858C52 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DB3C3204EF for ; Mon, 4 Jul 2022 08:36:36 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C7DFC1342C for ; Mon, 4 Jul 2022 08:36:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YG2UL5SmwmKwRAAAMHmgww (envelope-from ) for ; Mon, 04 Jul 2022 08:36:36 +0000 Date: Mon, 4 Jul 2022 10:36:36 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Put virtual operands into loop-closed SSA MIME-Version: 1.0 Message-Id: <20220704083636.C7DFC1342C@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When attempting to manually update SSA form after high-level loop transforms such as loop versioning it is helpful when the loop-closed SSA form includes virtual operands. While we have the special rewrite_virtuals_into_loop_closed_ssa function that doesn't presently scale, invoking update_ssa by itself. So the following makes the regular loop-closed SSA form also cover virtual operands. For users of loop_version this allows to use cheaper TODO_update_ssa_no_phi, skipping dominance frontier compute (for the whole function) and iterated dominance frontiers for each copied def. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * tree-ssa-loop-manip.h (rewrite_virtuals_into_loop_closed_ssa): Remove. (rewrite_into_loop_closed_ssa_1): Likewise. * tree-ssa-loop-manip.cc (rewrite_into_loop_closed_ssa_1): Make static. (rewrite_into_loop_closed_ssa): Remove loop overload, always rewrite virtuals into LC SSA. (check_loop_closed_ssa_bb): Also check virtuals. * tree-ssa-dce.cc (remove_dead_phis): Preserve virtual LC PHIs when in LC SSA. * gimple-loop-jam.cc (fuse_loops): Do not rewrite into loop-closed SSA here, but ... (tree_loop_unroll_and_jam): ... here once. * tree-if-conv.cc (version_loop_for_if_conversion): Use the cheaper TODO_update_ssa_no_phi. * tree-loop-distribution.cc (version_loop_by_alias_check): Likewise. * tree-ssa-loop-unswitch.cc (tree_unswitch_single_loop): Likewise. * tree-vect-loop-manip.cc (vect_loop_versioning): Likewise. (tree_unswitch_outer_loop): Do not rewrite virtuals into LC ssa. * tree-parloops.cc (transform_to_exit_first_loop_alt): Likewise. (pass_parallelize_loops::execute): After finishing rewrite into LC SSA again because we do not maintain it properly. --- gcc/gimple-loop-jam.cc | 2 +- gcc/tree-if-conv.cc | 2 +- gcc/tree-loop-distribution.cc | 2 +- gcc/tree-parloops.cc | 10 +++------- gcc/tree-ssa-dce.cc | 3 ++- gcc/tree-ssa-loop-manip.cc | 23 +++++++---------------- gcc/tree-ssa-loop-manip.h | 3 --- gcc/tree-ssa-loop-unswitch.cc | 4 +--- gcc/tree-vect-loop-manip.cc | 2 +- 9 files changed, 17 insertions(+), 34 deletions(-) diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc index 9b18b52a54c..8cde6c7c5ce 100644 --- a/gcc/gimple-loop-jam.cc +++ b/gcc/gimple-loop-jam.cc @@ -363,7 +363,6 @@ fuse_loops (class loop *loop) delete_loop (next); next = ln; } - rewrite_into_loop_closed_ssa_1 (NULL, 0, SSA_OP_USE, loop); } /* Return true if any of the access functions for dataref A @@ -610,6 +609,7 @@ tree_loop_unroll_and_jam (void) if (todo) { + rewrite_into_loop_closed_ssa (NULL, 0); scev_reset (); free_dominance_info (CDI_DOMINATORS); } diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 3c659f6b5a7..1c8e1a45234 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -2934,7 +2934,7 @@ version_loop_for_if_conversion (class loop *loop, vec *preds) if (preds) preds->safe_push (g); gsi_insert_before (&gsi, g, GSI_SAME_STMT); - update_ssa (TODO_update_ssa); + update_ssa (TODO_update_ssa_no_phi); return new_loop; } diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc index 18b97fc3801..ed7f432f322 100644 --- a/gcc/tree-loop-distribution.cc +++ b/gcc/tree-loop-distribution.cc @@ -2751,7 +2751,7 @@ version_loop_by_alias_check (vec *partitions, gimple_stmt_iterator cond_gsi = gsi_last_bb (cond_bb); gsi_insert_seq_before (&cond_gsi, cond_stmts, GSI_SAME_STMT); } - update_ssa (TODO_update_ssa); + update_ssa (TODO_update_ssa_no_phi); } /* Return true if loop versioning is needed to distrubute PARTITIONS. diff --git a/gcc/tree-parloops.cc b/gcc/tree-parloops.cc index 2c3ef436ab7..2d3aa78cd24 100644 --- a/gcc/tree-parloops.cc +++ b/gcc/tree-parloops.cc @@ -2355,12 +2355,6 @@ transform_to_exit_first_loop_alt (class loop *loop, tree control = gimple_cond_lhs (cond_stmt); edge e; - /* Rewriting virtuals into loop-closed ssa normal form makes this - transformation simpler. It also ensures that the virtuals are in - loop-closed ssa normal from after the transformation, which is required by - create_parallel_loop. */ - rewrite_virtuals_into_loop_closed_ssa (loop); - /* Create the new_header block. */ basic_block new_header = split_block_before_cond_jump (exit->src); edge edge_at_split = single_pred_edge (new_header); @@ -4223,7 +4217,9 @@ pass_parallelize_loops::execute (function *fun) checking_verify_loop_structure (); - todo |= TODO_update_ssa; + update_ssa (TODO_update_ssa); + if (in_loop_pipeline) + rewrite_into_loop_closed_ssa (NULL, 0); } if (!in_loop_pipeline) diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index 5df64922594..bc533582673 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -1026,7 +1026,8 @@ remove_dead_phis (basic_block bb) { /* Virtual PHI nodes with one or identical arguments can be removed. */ - if (degenerate_phi_p (phi)) + if (!loops_state_satisfies_p (LOOP_CLOSED_SSA) + && degenerate_phi_p (phi)) { tree vdef = gimple_phi_result (phi); tree vuse = gimple_phi_arg_def (phi, 0); diff --git a/gcc/tree-ssa-loop-manip.cc b/gcc/tree-ssa-loop-manip.cc index 5d435637e98..623d03b9d86 100644 --- a/gcc/tree-ssa-loop-manip.cc +++ b/gcc/tree-ssa-loop-manip.cc @@ -625,7 +625,7 @@ find_uses_to_rename_in_loop (class loop *loop, bitmap *use_blocks, UPDATE_FLAG is used in the call to update_ssa. See TODO_update_ssa* for documentation. */ -void +static void rewrite_into_loop_closed_ssa_1 (bitmap changed_bbs, unsigned update_flag, int use_flags, class loop *loop) { @@ -686,24 +686,16 @@ rewrite_into_loop_closed_ssa_1 (bitmap changed_bbs, unsigned update_flag, free (use_blocks); } -/* Rewrites the non-virtual defs and uses into a loop closed ssa form. If - CHANGED_BBS is not NULL, we look for uses outside loops only in the basic +/* Rewrites the defs and uses into a loop closed ssa form. + If CHANGED_BBS is not NULL, we look for uses outside loops only in the basic blocks in this set. UPDATE_FLAG is used in the call to update_ssa. See TODO_update_ssa* for documentation. */ void rewrite_into_loop_closed_ssa (bitmap changed_bbs, unsigned update_flag) { - rewrite_into_loop_closed_ssa_1 (changed_bbs, update_flag, SSA_OP_USE, NULL); -} - -/* Rewrites virtual defs and uses with def in LOOP into loop closed ssa - form. */ - -void -rewrite_virtuals_into_loop_closed_ssa (class loop *loop) -{ - rewrite_into_loop_closed_ssa_1 (NULL, 0, SSA_OP_VIRTUAL_USES, loop); + rewrite_into_loop_closed_ssa_1 (changed_bbs, update_flag, + SSA_OP_ALL_USES, NULL); } /* Check invariants of the loop closed ssa form for the def in DEF_BB. */ @@ -736,8 +728,7 @@ check_loop_closed_ssa_bb (basic_block bb) { gphi *phi = bsi.phi (); - if (!virtual_operand_p (PHI_RESULT (phi))) - check_loop_closed_ssa_def (bb, PHI_RESULT (phi)); + check_loop_closed_ssa_def (bb, PHI_RESULT (phi)); } for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb); !gsi_end_p (bsi); @@ -747,7 +738,7 @@ check_loop_closed_ssa_bb (basic_block bb) tree var; gimple *stmt = gsi_stmt (bsi); - FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF) + FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_ALL_DEFS) check_loop_closed_ssa_def (bb, var); } } diff --git a/gcc/tree-ssa-loop-manip.h b/gcc/tree-ssa-loop-manip.h index 00293195e80..924cac0edff 100644 --- a/gcc/tree-ssa-loop-manip.h +++ b/gcc/tree-ssa-loop-manip.h @@ -24,10 +24,7 @@ typedef void (*transform_callback)(class loop *, void *); extern void create_iv (tree, tree, tree, class loop *, gimple_stmt_iterator *, bool, tree *, tree *); -extern void rewrite_into_loop_closed_ssa_1 (bitmap, unsigned, int, - class loop *); extern void rewrite_into_loop_closed_ssa (bitmap, unsigned); -extern void rewrite_virtuals_into_loop_closed_ssa (class loop *); extern void verify_loop_closed_ssa (bool, class loop * = NULL); static inline void diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc index 3a827f2f904..7d6781d1505 100644 --- a/gcc/tree-ssa-loop-unswitch.cc +++ b/gcc/tree-ssa-loop-unswitch.cc @@ -980,7 +980,7 @@ tree_unswitch_single_loop (class loop *loop, dump_user_location_t loc, free_original_copy_tables (); /* Update the SSA form after unswitching. */ - update_ssa (TODO_update_ssa); + update_ssa (TODO_update_ssa_no_phi); /* Invoke itself on modified loops. */ bitmap handled_copy = BITMAP_ALLOC (NULL); @@ -1068,8 +1068,6 @@ tree_unswitch_outer_loop (class loop *loop) auto_vec dbg_to_reset; while ((guard = find_loop_guard (loop, dbg_to_reset))) { - if (! changed) - rewrite_virtuals_into_loop_closed_ssa (loop); hoist_guard (loop, guard); for (gimple *debug_stmt : dbg_to_reset) { diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index e81de45e07e..47c4fe8de86 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -3696,7 +3696,7 @@ vect_loop_versioning (loop_vec_info loop_vinfo, } } - update_ssa (TODO_update_ssa); + update_ssa (TODO_update_ssa_no_phi); } /* Split the cost model check off to a separate BB. Costing assumes