From patchwork Tue Feb 14 14:21:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1742413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=A8H9ozwr; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PGNhH6RD9z23r4 for ; Wed, 15 Feb 2023 01:22:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF782385B519 for ; Tue, 14 Feb 2023 14:22:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF782385B519 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676384541; bh=JOQOFqSvbjXuyIXuFmjKJvPHn1oZa1ej6cpXC8Gzul8=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=A8H9ozwrlWgMhemTDFhZTL2PnYuW1gDAwH36HJPVombWXyS8OrEKyBRlPqy0VrEhp iqu1a03mucfHQUSohH2VGyhMTJ/LuX6hZz8Yr2vWdn0JqkFirP5Eztp9MIJVobxk/O HztI6M0bbjp2/yc4zzLkHWNkYqkqZqZoe71ittyg= 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 [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 1DD553858C36 for ; Tue, 14 Feb 2023 14:21:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1DD553858C36 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-out1.suse.de (Postfix) with ESMTPS id 1F08F22222; Tue, 14 Feb 2023 14:21:54 +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 09F8D13A21; Tue, 14 Feb 2023 14:21:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8eKHAQKZ62NCUQAAMHmgww (envelope-from ); Tue, 14 Feb 2023 14:21:54 +0000 Date: Tue, 14 Feb 2023 15:21:53 +0100 (CET) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] Speedup DF dataflow solver MIME-Version: 1.0 Message-Id: <20230214142154.09F8D13A21@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 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" The following makes sure to process blocks that follow the current block in the iteration order in the same iteration and only postpone blocks that would be visited earlier to the next iteration. For the all.i testcase in PR26854 at -O2 this shaves off 50% of the time to solve the DF RD problem, other problems also improve but not as drastically. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. OK for trunk? Thanks, Richard. PR middle-end/26854 * df-core.cc (df_worklist_propagate_forward): Put later blocks on worklist and only earlier blocks on pending. (df_worklist_propagate_backward): Likewise. (df_worklist_dataflow_doublequeue): Change the iteration to process new blocks in the same iteration if that maintains the iteration order. --- gcc/df-core.cc | 54 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/gcc/df-core.cc b/gcc/df-core.cc index e5ae9ab9348..38f69ac5743 100644 --- a/gcc/df-core.cc +++ b/gcc/df-core.cc @@ -874,7 +874,8 @@ make_pass_df_finish (gcc::context *ctxt) /* Helper function for df_worklist_dataflow. Propagate the dataflow forward. Given a BB_INDEX, do the dataflow propagation - and set bits on for successors in PENDING + and set bits on for successors in PENDING for earlier + and WORKLIST for later in bbindex_to_postorder if the out set of the dataflow has changed. AGE specify time when BB was visited last time. @@ -890,10 +891,11 @@ make_pass_df_finish (gcc::context *ctxt) static bool df_worklist_propagate_forward (struct dataflow *dataflow, - unsigned bb_index, - unsigned *bbindex_to_postorder, - bitmap pending, - sbitmap considered, + unsigned bb_index, + unsigned *bbindex_to_postorder, + bitmap worklist, + bitmap pending, + sbitmap considered, vec &last_change_age, int age) { @@ -924,7 +926,13 @@ df_worklist_propagate_forward (struct dataflow *dataflow, unsigned ob_index = e->dest->index; if (bitmap_bit_p (considered, ob_index)) - bitmap_set_bit (pending, bbindex_to_postorder[ob_index]); + { + if (bbindex_to_postorder[bb_index] + < bbindex_to_postorder[ob_index]) + bitmap_set_bit (worklist, bbindex_to_postorder[ob_index]); + else + bitmap_set_bit (pending, bbindex_to_postorder[ob_index]); + } } return true; } @@ -937,10 +945,11 @@ df_worklist_propagate_forward (struct dataflow *dataflow, static bool df_worklist_propagate_backward (struct dataflow *dataflow, - unsigned bb_index, - unsigned *bbindex_to_postorder, - bitmap pending, - sbitmap considered, + unsigned bb_index, + unsigned *bbindex_to_postorder, + bitmap worklist, + bitmap pending, + sbitmap considered, vec &last_change_age, int age) { @@ -971,7 +980,13 @@ df_worklist_propagate_backward (struct dataflow *dataflow, unsigned ob_index = e->src->index; if (bitmap_bit_p (considered, ob_index)) - bitmap_set_bit (pending, bbindex_to_postorder[ob_index]); + { + if (bbindex_to_postorder[bb_index] + < bbindex_to_postorder[ob_index]) + bitmap_set_bit (worklist, bbindex_to_postorder[ob_index]); + else + bitmap_set_bit (pending, bbindex_to_postorder[ob_index]); + } } return true; } @@ -1021,36 +1036,37 @@ df_worklist_dataflow_doublequeue (struct dataflow *dataflow, and pending is for the next. */ while (!bitmap_empty_p (pending)) { - bitmap_iterator bi; - unsigned int index; - std::swap (pending, worklist); - EXECUTE_IF_SET_IN_BITMAP (worklist, 0, index, bi) + do { + unsigned index = bitmap_first_set_bit (worklist); + bitmap_clear_bit (worklist, index); + unsigned bb_index; dcount++; - bitmap_clear_bit (pending, index); bb_index = blocks_in_postorder[index]; prev_age = last_visit_age[index]; if (dir == DF_FORWARD) changed = df_worklist_propagate_forward (dataflow, bb_index, bbindex_to_postorder, - pending, considered, + worklist, pending, + considered, last_change_age, prev_age); else changed = df_worklist_propagate_backward (dataflow, bb_index, bbindex_to_postorder, - pending, considered, + worklist, pending, + considered, last_change_age, prev_age); last_visit_age[index] = ++age; if (changed) last_change_age[index] = age; } - bitmap_clear (worklist); + while (!bitmap_empty_p (worklist)); } BITMAP_FREE (worklist);