From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 452803858D28 for ; Mon, 7 Aug 2023 13:22:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 452803858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id E832921A22 for ; Mon, 7 Aug 2023 13:21:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691414519; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=//ALTGa5c5HnricDbwwBchlsRvzfZx+adIG6ONzHoZU=; b=pK5O9OO7fqojmjxipgLw+F+taQX105DsLHTA+aykWse2M5AhcwrG0vu/o1ls9Rs8OiOaBw 0+ZX+s1z2GlQZrIdWwrdPseb6wGtiuy7cK20QTE1FQZbsVlT6+peCYRUV4TU/dV6MwO6FP aQV/RgjhQVXIu0zVGHNEKqxU3iGhZzQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691414519; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=//ALTGa5c5HnricDbwwBchlsRvzfZx+adIG6ONzHoZU=; b=YWhyVpWuAIHIwA3ct9DpqoZKUrNrt2S14NzdSVSnJJBOP9R/AElPweDehTrpah9Sbznioo r/REMGrLrwFGSsCA== 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 DE9072C142 for ; Mon, 7 Aug 2023 13:21:59 +0000 (UTC) Date: Mon, 7 Aug 2023 13:21:59 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Use RPO order for sinking 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.6 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20230807132159.uOL-3-GqYayIV9_zAKbPDbcg0OAwTPtPAWI0dptJpKw@z> The following makes us use RPO order instead of walking post-dominators. This ensures we visit a block before any predecessors. I've seen some extra sinking because of this in a larger testcase but failed to reduce a smaller one (processing of post-dominator sons is unordered so I failed to have "luck"). Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * tree-ssa-sink.cc (pass_sink_code::execute): Do not calculate post-dominators. Calculate RPO on the inverted graph and process blocks in that order. --- gcc/tree-ssa-sink.cc | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc index 5cf9e737e84..6ad9d21589e 100644 --- a/gcc/tree-ssa-sink.cc +++ b/gcc/tree-ssa-sink.cc @@ -824,26 +824,17 @@ pass_sink_code::execute (function *fun) connect_infinite_loops_to_exit (); memset (&sink_stats, 0, sizeof (sink_stats)); calculate_dominance_info (CDI_DOMINATORS); - calculate_dominance_info (CDI_POST_DOMINATORS); virtual_operand_live vop_live; - auto_vec worklist; - worklist.quick_push (EXIT_BLOCK_PTR_FOR_FN (fun)); - do - { - basic_block bb = worklist.pop (); - todo |= sink_code_in_bb (bb, vop_live); - for (basic_block son = first_dom_son (CDI_POST_DOMINATORS, bb); - son; - son = next_dom_son (CDI_POST_DOMINATORS, son)) - worklist.safe_push (son); - } - while (!worklist.is_empty ()); + int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); + int n = inverted_rev_post_order_compute (fun, rpo); + for (int i = 0; i < n; ++i) + todo |= sink_code_in_bb (BASIC_BLOCK_FOR_FN (fun, rpo[i]), vop_live); + free (rpo); statistics_counter_event (fun, "Sunk statements", sink_stats.sunk); statistics_counter_event (fun, "Commoned stores", sink_stats.commoned); - free_dominance_info (CDI_POST_DOMINATORS); remove_fake_exit_edges (); loop_optimizer_finalize (); -- 2.35.3