From patchwork Wed Dec 13 08:42:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 82031 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 466B8385E005 for ; Wed, 13 Dec 2023 08:43:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id C0F3F3858D39 for ; Wed, 13 Dec 2023 08:43:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0F3F3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C0F3F3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702456995; cv=none; b=oWB/WtUQLRqc7kcTHGG6EmJiqxR0i1ZEweodud9kHIQgjqsCitej2BJQX2tfVK3PKw13MPP24LGcJgGfWui87HDc5K7HnbyC8R4d3H97FfcvaCnXDPkwFDfdg41GH+6cFOxwk1JzApF+meu8koz1gVm8hEYU5qXCbJ0PUJtzWvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702456995; c=relaxed/simple; bh=3Uh482XQLDMAaX4aPwFwfZ+cmtal13SqvcI9+5ieXMY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=cstEAQ+SJbPpbgzVTvHwf3kQFJ4i+1gZuuajrfT82ZhGGdlQThqpIPT0di39RtmkjEAhYD0KZKet8Td95KizahiCzCqKD00InBfq2MeeAJxmgy/FFOmLpecz33upuawDE1LSEoa4ezRctLzFmBCZ6/dMgJ57WF7xzLT3cFdwW5s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5E02021E54 for ; Wed, 13 Dec 2023 08:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702456992; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=kdclR+HFIFDeNtIBK+QtEev1z7w5Fj4mIUgG3t0ewYk=; b=O/W8F2premrXmsLHHbV3pIp+R0nCnnZZlVyq790/y9s/lpvzQAZbY6LlEG/T1+blHKawUv MA9TKx2j1G+WBfZAca1mZ19EPYyq4v7FbAM+ALksn5XZohuurlWP5dF841bcRkJ7Qv8+94 /wGNVyPfMLd4Yt2D7fiRFGeWzD0pgHk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702456992; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=kdclR+HFIFDeNtIBK+QtEev1z7w5Fj4mIUgG3t0ewYk=; b=Y6QEhvFhm2MNZ9MCBHYV480LyJkd7U3EpHKANqXO03KYdraaiU3d+G9M1QHihg7Hnuh1Ag i+eJC831jyeCPCCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702456992; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=kdclR+HFIFDeNtIBK+QtEev1z7w5Fj4mIUgG3t0ewYk=; b=O/W8F2premrXmsLHHbV3pIp+R0nCnnZZlVyq790/y9s/lpvzQAZbY6LlEG/T1+blHKawUv MA9TKx2j1G+WBfZAca1mZ19EPYyq4v7FbAM+ALksn5XZohuurlWP5dF841bcRkJ7Qv8+94 /wGNVyPfMLd4Yt2D7fiRFGeWzD0pgHk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702456992; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=kdclR+HFIFDeNtIBK+QtEev1z7w5Fj4mIUgG3t0ewYk=; b=Y6QEhvFhm2MNZ9MCBHYV480LyJkd7U3EpHKANqXO03KYdraaiU3d+G9M1QHihg7Hnuh1Ag i+eJC831jyeCPCCQ== Date: Wed, 13 Dec 2023 09:42:09 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/112991 - re-do PR112961 fix MIME-Version: 1.0 X-Spam-Score: 1.41 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 1.38 X-Spamd-Result: default: False [1.38 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.42)[-0.418]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_SPAM_SHORT(2.40)[0.800]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-Spam-Status: No, score=-10.8 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Message-Id: <20231213084330.466B8385E005@sourceware.org> The following does away with the fake edge adding as in the original PR112961 fix and instead exposes handling of entry PHIs as additional parameter of the region VN run. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/112991 PR tree-optimization/112961 * tree-ssa-sccvn.h (do_rpo_vn): Add skip_entry_phis argument. * tree-ssa-sccvn.cc (do_rpo_vn): Likewise. (do_rpo_vn_1): Likewise, merge with auto-processing. (run_rpo_vn): Adjust. (pass_fre::execute): Likewise. * tree-if-conv.cc (tree_if_conversion): Revert last change. Value-number latch block but disable value-numbering of entry PHIs. * tree-ssa-uninit.cc (execute_early_warn_uninitialized): Adjust. * gcc.dg/torture/pr112991.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr112991.c | 21 +++++++++++++++++++++ gcc/tree-if-conv.cc | 24 +++++++++--------------- gcc/tree-ssa-sccvn.cc | 24 +++++++++++++++--------- gcc/tree-ssa-sccvn.h | 1 + gcc/tree-ssa-uninit.cc | 2 +- 5 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr112991.c diff --git a/gcc/testsuite/gcc.dg/torture/pr112991.c b/gcc/testsuite/gcc.dg/torture/pr112991.c new file mode 100644 index 00000000000..aace9854599 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112991.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +typedef struct { + unsigned links[2]; +} RMF_unit; +long RMF_recurseListsBound_count; +int RMF_recurseListsBound_tbl, RMF_recurseListsBound_list_head_1; +unsigned RMF_recurseListsBound_list_head_0; +void RMF_recurseListsBound() { + int list_count = RMF_recurseListsBound_list_head_1; + long link = RMF_recurseListsBound_list_head_0; + for (; RMF_recurseListsBound_count;) { + long next_link = + ((RMF_unit *)&RMF_recurseListsBound_tbl)[link >> 2].links[0]; + if (link) + --RMF_recurseListsBound_count; + link = next_link; + } + while (list_count) + ; +} diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index f9fd0149937..e169413bb44 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -3734,7 +3734,7 @@ tree_if_conversion (class loop *loop, vec *preds) auto_vec reads_to_lower; auto_vec writes_to_lower; bitmap exit_bbs; - edge pe, e; + edge pe; auto_vec refs; bool loop_versioned; @@ -3891,27 +3891,21 @@ tree_if_conversion (class loop *loop, vec *preds) combine_blocks (loop, loop_versioned); } + std::pair *name_pair; + unsigned ssa_names_idx; + FOR_EACH_VEC_ELT (redundant_ssa_names, ssa_names_idx, name_pair) + replace_uses_by (name_pair->first, name_pair->second); + redundant_ssa_names.release (); + /* Perform local CSE, this esp. helps the vectorizer analysis if loads and stores are involved. CSE only the loop body, not the entry PHIs, those are to be kept in sync with the non-if-converted copy. - Do this by adding a fake entry edge - we do want to include the - latch as otherwise copies on a reduction path cannot be propagated out. ??? We'll still keep dead stores though. */ - e = make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), loop->header, EDGE_FAKE); exit_bbs = BITMAP_ALLOC (NULL); for (edge exit : get_loop_exit_edges (loop)) bitmap_set_bit (exit_bbs, exit->dest->index); - - std::pair *name_pair; - unsigned ssa_names_idx; - FOR_EACH_VEC_ELT (redundant_ssa_names, ssa_names_idx, name_pair) - replace_uses_by (name_pair->first, name_pair->second); - redundant_ssa_names.release (); - - todo |= do_rpo_vn (cfun, loop_preheader_edge (loop), exit_bbs); - - /* Remove the fake edge again. */ - remove_edge (e); + todo |= do_rpo_vn (cfun, loop_preheader_edge (loop), exit_bbs, + false, true, true); /* Delete dead predicate computations. */ ifcvt_local_dce (loop); diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index a178b768459..4d3088643c4 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -7584,12 +7584,13 @@ eliminate_with_rpo_vn (bitmap inserted_exprs) static unsigned do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs, - bool iterate, bool eliminate, vn_lookup_kind kind); + bool iterate, bool eliminate, bool skip_entry_phis, + vn_lookup_kind kind); void run_rpo_vn (vn_lookup_kind kind) { - do_rpo_vn_1 (cfun, NULL, NULL, true, false, kind); + do_rpo_vn_1 (cfun, NULL, NULL, true, false, false, kind); /* ??? Prune requirement of these. */ constant_to_value_id = new hash_table (23); @@ -8290,11 +8291,13 @@ do_unwind (unwind_state *to, rpo_elim &avail) /* Do VN on a SEME region specified by ENTRY and EXIT_BBS in FN. If ITERATE is true then treat backedges optimistically as not executed and iterate. If ELIMINATE is true then perform - elimination, otherwise leave that to the caller. */ + elimination, otherwise leave that to the caller. If SKIP_ENTRY_PHIS + is true then force PHI nodes in ENTRY->dest to VARYING. */ static unsigned do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs, - bool iterate, bool eliminate, vn_lookup_kind kind) + bool iterate, bool eliminate, bool skip_entry_phis, + vn_lookup_kind kind) { unsigned todo = 0; default_vn_walk_kind = kind; @@ -8335,10 +8338,10 @@ do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs, if (e != entry && !(e->flags & EDGE_DFS_BACK)) break; - bool skip_entry_phis = e != NULL; - if (skip_entry_phis && dump_file && (dump_flags & TDF_DETAILS)) + if (e != NULL && dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Region does not contain all edges into " "the entry block, skipping its PHIs.\n"); + skip_entry_phis |= e != NULL; int *bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (fn)); for (int i = 0; i < n; ++i) @@ -8715,14 +8718,17 @@ do_rpo_vn_1 (function *fn, edge entry, bitmap exit_bbs, If ITERATE is true then treat backedges optimistically as not executed and iterate. If ELIMINATE is true then perform elimination, otherwise leave that to the caller. + If SKIP_ENTRY_PHIS is true then force PHI nodes in ENTRY->dest to VARYING. KIND specifies the amount of work done for handling memory operations. */ unsigned do_rpo_vn (function *fn, edge entry, bitmap exit_bbs, - bool iterate, bool eliminate, vn_lookup_kind kind) + bool iterate, bool eliminate, bool skip_entry_phis, + vn_lookup_kind kind) { auto_timevar tv (TV_TREE_RPO_VN); - unsigned todo = do_rpo_vn_1 (fn, entry, exit_bbs, iterate, eliminate, kind); + unsigned todo = do_rpo_vn_1 (fn, entry, exit_bbs, iterate, eliminate, + skip_entry_phis, kind); free_rpo_vn (); return todo; } @@ -8778,7 +8784,7 @@ pass_fre::execute (function *fun) if (iterate_p) loop_optimizer_init (AVOID_CFG_MODIFICATIONS); - todo = do_rpo_vn_1 (fun, NULL, NULL, iterate_p, true, VN_WALKREWRITE); + todo = do_rpo_vn_1 (fun, NULL, NULL, iterate_p, true, false, VN_WALKREWRITE); free_rpo_vn (); if (iterate_p) diff --git a/gcc/tree-ssa-sccvn.h b/gcc/tree-ssa-sccvn.h index 98d70e0ffe0..5e370b85213 100644 --- a/gcc/tree-ssa-sccvn.h +++ b/gcc/tree-ssa-sccvn.h @@ -298,6 +298,7 @@ tree vn_nary_simplify (vn_nary_op_t); unsigned do_rpo_vn (function *, edge, bitmap, /* iterate */ bool = false, /* eliminate */ bool = true, + /* skip_entry_phis */ bool = false, vn_lookup_kind = VN_WALKREWRITE); /* Private interface for PRE. */ diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc index 9a7c7d12dd8..8d169c33729 100644 --- a/gcc/tree-ssa-uninit.cc +++ b/gcc/tree-ssa-uninit.cc @@ -1500,7 +1500,7 @@ execute_early_warn_uninitialized (struct function *fun) elimination to compute edge reachability. Don't bother when we only warn for unconditionally executed code though. */ if (!optimize) - do_rpo_vn (fun, NULL, NULL, false, false, VN_NOWALK); + do_rpo_vn (fun, NULL, NULL, false, false, false, VN_NOWALK); else set_all_edges_as_executable (fun);