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 2A46A3858415 for ; Tue, 7 Sep 2021 08:42:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A46A3858415 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 F34C71FD3E for ; Tue, 7 Sep 2021 08:42:10 +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 E013E13C31 for ; Tue, 7 Sep 2021 08:42:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jKWgNeIlN2GNWAAAMHmgww (envelope-from ) for ; Tue, 07 Sep 2021 08:42:10 +0000 Date: Tue, 7 Sep 2021 10:42:10 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/101555 - avoid redundant alias queries in PRE Message-ID: <1s74q545-oqn0-5217-67or-65nnpnr0rs82@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.6 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 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Tue, 07 Sep 2021 08:42:13 -0000 This avoids doing redundant work during PHI translation to invalidate mems when translating their corresponding VUSE through the blocks virtual PHI node. All the invalidation work is already done by prune_clobbered_mems. This speeds up the compile of the testcase from 275s with PRE taking 91% of the compile-time down to 43s with PRE taking 16% of the compile-time. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2021-09-07 Richard Biener PR tree-optimization/101555 * tree-ssa-pre.c (translate_vuse_through_block): Do not perform an alias walk to determine the validity of the mem at the start of the block which is already guaranteed by means of prune_clobbered_mems. (phi_translate_1): Pass edge to translate_vuse_through_block. --- gcc/tree-ssa-pre.c | 97 ++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 60 deletions(-) diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index 769aadb2315..08755847f66 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -1237,21 +1237,18 @@ fully_constant_expression (pre_expr e) return e; } -/* Translate the VUSE backwards through phi nodes in PHIBLOCK, so that - it has the value it would have in BLOCK. Set *SAME_VALID to true +/* Translate the VUSE backwards through phi nodes in E->dest, so that + it has the value it would have in E->src. Set *SAME_VALID to true in case the new vuse doesn't change the value id of the OPERANDS. */ static tree translate_vuse_through_block (vec operands, alias_set_type set, alias_set_type base_set, - tree type, tree vuse, - basic_block phiblock, - basic_block block, bool *same_valid) + tree type, tree vuse, edge e, bool *same_valid) { + basic_block phiblock = e->dest; gimple *phi = SSA_NAME_DEF_STMT (vuse); ao_ref ref; - edge e = NULL; - bool use_oracle; if (same_valid) *same_valid = true; @@ -1259,59 +1256,40 @@ translate_vuse_through_block (vec operands, if (gimple_bb (phi) != phiblock) return vuse; - unsigned int cnt = param_sccvn_max_alias_queries_per_access; - use_oracle = ao_ref_init_from_vn_reference (&ref, set, base_set, - type, operands); - - /* Use the alias-oracle to find either the PHI node in this block, - the first VUSE used in this block that is equivalent to vuse or - the first VUSE which definition in this block kills the value. */ - if (gimple_code (phi) == GIMPLE_PHI) - e = find_edge (block, phiblock); - else if (use_oracle) - while (cnt > 0 - && !stmt_may_clobber_ref_p_1 (phi, &ref)) - { - --cnt; - vuse = gimple_vuse (phi); - phi = SSA_NAME_DEF_STMT (vuse); - if (gimple_bb (phi) != phiblock) - return vuse; - if (gimple_code (phi) == GIMPLE_PHI) - { - e = find_edge (block, phiblock); - break; - } - } - else - return NULL_TREE; - - if (e) + /* We have pruned expressions that are killed in PHIBLOCK via + prune_clobbered_mems but we have not rewritten the VUSE to the one + live at the start of the block. If there is no virtual PHI to translate + through return the VUSE live at entry. Otherwise the VUSE to translate + is the def of the virtual PHI node. */ + phi = get_virtual_phi (phiblock); + if (!phi) + return BB_LIVE_VOP_ON_EXIT + (get_immediate_dominator (CDI_DOMINATORS, phiblock)); + + if (same_valid + && ao_ref_init_from_vn_reference (&ref, set, base_set, type, operands)) { - if (use_oracle && same_valid) - { - bitmap visited = NULL; - /* Try to find a vuse that dominates this phi node by skipping - non-clobbering statements. */ - vuse = get_continuation_for_phi (phi, &ref, true, - cnt, &visited, false, NULL, NULL); - if (visited) - BITMAP_FREE (visited); - } - else - vuse = NULL_TREE; - /* If we didn't find any, the value ID can't stay the same. */ - if (!vuse && same_valid) - *same_valid = false; - /* ??? We would like to return vuse here as this is the canonical - upmost vdef that this reference is associated with. But during - insertion of the references into the hash tables we only ever - directly insert with their direct gimple_vuse, hence returning - something else would make us not find the other expression. */ - return PHI_ARG_DEF (phi, e->dest_idx); + bitmap visited = NULL; + /* Try to find a vuse that dominates this phi node by skipping + non-clobbering statements. */ + unsigned int cnt = param_sccvn_max_alias_queries_per_access; + vuse = get_continuation_for_phi (phi, &ref, true, + cnt, &visited, false, NULL, NULL); + if (visited) + BITMAP_FREE (visited); } - - return NULL_TREE; + else + vuse = NULL_TREE; + /* If we didn't find any, the value ID can't stay the same. */ + if (!vuse && same_valid) + *same_valid = false; + + /* ??? We would like to return vuse here as this is the canonical + upmost vdef that this reference is associated with. But during + insertion of the references into the hash tables we only ever + directly insert with their direct gimple_vuse, hence returning + something else would make us not find the other expression. */ + return PHI_ARG_DEF (phi, e->dest_idx); } /* Like bitmap_find_leader, but checks for the value existing in SET1 *or* @@ -1630,8 +1608,7 @@ phi_translate_1 (bitmap_set_t dest, newvuse = translate_vuse_through_block (newoperands.exists () ? newoperands : operands, ref->set, ref->base_set, - ref->type, - vuse, phiblock, pred, + ref->type, vuse, e, changed ? NULL : &same_valid); if (newvuse == NULL_TREE) -- 2.31.1