From patchwork Tue Feb 7 13:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 53889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2858519wrn; Tue, 7 Feb 2023 05:50:05 -0800 (PST) X-Google-Smtp-Source: AK7set9YjqElBsRUzw3Y3UXF6ZVotS10XEcIwgG7hMKZcoW2u8zAHG7VicG94TJ3fWYubk1qAeAi X-Received: by 2002:a17:907:948a:b0:893:7668:1f34 with SMTP id dm10-20020a170907948a00b0089376681f34mr16658529ejc.35.1675777805767; Tue, 07 Feb 2023 05:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675777805; cv=none; d=google.com; s=arc-20160816; b=EJTuWHnAhFuejlfZN8szvteiPuoBydvvCN3lfzoq+BAK4znb+zODMKQ2z6zuBQQ4AV ZaU2+cskkoNd+3+sO5orcxJ5l+YrT/8L/u6/XhtDrE2mtGOPwfmsnnRkxJYEeLTyqbPp M3StnhtFUy0/yEfPpdWU3pOYt571Xc/RySkol2z84pg5XvXC5eUp1cEPwN5+x3BNE9Rs FGAQ7Afk/wTUfvc7RLWaevToqkMc2vVBFg/KlyVGU5vJG7j8FJDd3p2ffJCiK5639iSK usQEC1MRsCu2J+oTgECUvmlNG+l0mVqHqadIf86JxBjKt7SeN+ktKNWHthduFh6eNHD0 6XfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=vaugI5SLbZ+Gyjw+gkj6JpzCxuLUXNuZs9kf4oOCJS4=; b=XoGuzusvVWY0hQIL5rQY2e6S7LOasVlpwTJuvw5WUEpe+WMy4H12m70DaDvuL/Iciq a+f+v1kUiMiUmG6musN6hjZ03AmhQTOvtIJGXWj4FJVBhq6B1sZ6/YmWpJg8LOhVjXRM +coZkMV0BJ7DLhjqy/kLZeDAuDMQrERc1P6Qk14SouiUF9BfcOtbwvA3EVs8j8jLqIdT 8NDaah+fPfmGkd2BZCjvuf8G4zQvb+FUjJlBxsNz+Tk8Tl0NyZv1elFcfueUo0HA7qrb GLAHXc58paBIYDbeK6cYdsua6erlvL+R3E9L230UxaBSxXo/FR0zdoXaGKQfEwMo4DBn Yh0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=trFcFPSG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id et6-20020a056402378600b004a63aa10371si15272563edb.277.2023.02.07.05.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 05:50:05 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=trFcFPSG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1E0C3858404 for ; Tue, 7 Feb 2023 13:50:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1E0C3858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675777804; bh=vaugI5SLbZ+Gyjw+gkj6JpzCxuLUXNuZs9kf4oOCJS4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=trFcFPSG0Pmqwg+c3ZLlSRIhHLN0j2x3PuzMt805LKw3hbP8hQof5y6MzoRJNzV/l 73qio4TSmsbJ02XZvI1I6JXoyeB7PhYx6hg2TPVcp9iyz7Nnq+tikuYfy/I0cOwXIl yqe9oqbu36DpZasgvwjzdV2oJkExw+huxDrgTahc= 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 955143858D33 for ; Tue, 7 Feb 2023 13:49:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 955143858D33 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 9ED395D8B7 for ; Tue, 7 Feb 2023 13:49:20 +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 8BDD3139ED for ; Tue, 7 Feb 2023 13:49:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qSIPIeBW4mOAewAAMHmgww (envelope-from ) for ; Tue, 07 Feb 2023 13:49:20 +0000 Date: Tue, 7 Feb 2023 14:49:20 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/26854 - slow bitmap operations MIME-Version: 1.0 Message-Id: <20230207134920.8BDD3139ED@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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757180388204909604?= X-GMAIL-MSGID: =?utf-8?q?1757180388204909604?= With the compiler.i testcase from the PR one can see bitmap_set_bit very high in the profile, originating from SSA update and alias stmt walking. For SSA update mark_block_for_update essentially performs redundant bitmap_set_bits and is called via insert_updated_phi_nodes_for as EXECUTE_IF_SET_IN_BITMAP (pruned_idf, 0, i, bi) ... mark_block_for_update (bb); FOR_EACH_EDGE (e, ei, bb->preds) if (e->src->index >= 0) mark_block_for_update (e->src); which is quite random in the access pattern and runs into the O(n) case of the linked list bitmap representation. Switching blocks_to_update to tree view around insert_updated_phi_nodes_for improves SSA update time from tree SSA incremental : 4.26 ( 3%) to tree SSA incremental : 2.98 ( 2%) Likewise the visited bitmap allocated by the alias walker benefits from using the tree view in case of large CFGs and we see an improvement from alias stmt walking : 10.53 ( 9%) to alias stmt walking : 4.05 ( 4%) Bootstrap and regtest running on x86_64-unknown-linux-gnu. PR tree-optimization/26854 * tree-into-ssa.cc (update_ssa): Turn blocks_to_update to tree view around insert_updated_phi_nodes_for. * tree-ssa-alias.cc (maybe_skip_until): Allocate visited bitmap in tree view. (walk_aliased_vdefs_1): Likewise. --- gcc/tree-into-ssa.cc | 4 ++++ gcc/tree-ssa-alias.cc | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/tree-into-ssa.cc b/gcc/tree-into-ssa.cc index 067d29698f9..2e322990456 100644 --- a/gcc/tree-into-ssa.cc +++ b/gcc/tree-into-ssa.cc @@ -3561,6 +3561,8 @@ update_ssa (unsigned update_flags) bitmap_initialize (&dfs[bb->index], &bitmap_default_obstack); compute_dominance_frontiers (dfs); + bitmap_tree_view (blocks_to_update); + /* insert_update_phi_nodes_for will call add_new_name_mapping when inserting new PHI nodes, but it will not add any new members to OLD_SSA_NAMES. */ @@ -3574,6 +3576,8 @@ update_ssa (unsigned update_flags) FOR_EACH_VEC_ELT (symbols_to_rename, i, sym) insert_updated_phi_nodes_for (sym, dfs, update_flags); + bitmap_list_view (blocks_to_update); + FOR_EACH_BB_FN (bb, cfun) bitmap_clear (&dfs[bb->index]); free (dfs); diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index 7089e8b5bf3..81bc51ed4ad 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -3657,7 +3657,10 @@ maybe_skip_until (gimple *phi, tree &target, basic_block target_bb, basic_block bb = gimple_bb (phi); if (!*visited) - *visited = BITMAP_ALLOC (NULL); + { + *visited = BITMAP_ALLOC (NULL); + bitmap_tree_view (*visited); + } bitmap_set_bit (*visited, SSA_NAME_VERSION (PHI_RESULT (phi))); @@ -3949,7 +3952,10 @@ walk_aliased_vdefs_1 (ao_ref *ref, tree vdef, { unsigned i; if (!*visited) - *visited = BITMAP_ALLOC (NULL); + { + *visited = BITMAP_ALLOC (NULL); + bitmap_tree_view (*visited); + } for (i = 0; i < gimple_phi_num_args (def_stmt); ++i) { int res = walk_aliased_vdefs_1 (ref,