From patchwork Mon Aug 22 13:38:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp496806wro; Mon, 22 Aug 2022 06:39:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4uWl77RqX6wH4949EWP+NoGsIFlIMEPV3rs/06KsdgCCF6Ae+dvYKsz75Dxlks7TvfYhuV X-Received: by 2002:a05:6402:270a:b0:446:c9e9:6e00 with SMTP id y10-20020a056402270a00b00446c9e96e00mr3653365edd.315.1661175543335; Mon, 22 Aug 2022 06:39:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661175543; cv=none; d=google.com; s=arc-20160816; b=AcLXuqzP5Qn/Iqv7S8JZevXYGJm59qhZQiMKTdgcZsnq6z9tb/euSqz9eZs11Q2N6E Iw8Dk1xT+b++tCr/p5eD7H0FaD6uQ7hGyKoIJX2Gy9zymcrDlC2EgNTB5zLQkYFyas1l j0cFTnOk9wCrDY19ohZoC6han8gB6/r8E6rdhLPEv6K6BFan+oNTNWraCmtj7dRWhSY+ LkErkncpys+zzfsG6wFkOiwmVCTDp+eaMV1nGH7KAXtNlLMWnNynFWuE+tCn3kuNzFXw Uc/PccSUaeRssByzs7ec/fJgbUTxRy55aNZ//1n91DqDzg0AQkbWj2OzIsUnu9XvRspj OkLw== 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=tBCa0F0NZPNyqP85b9mIER+5fznWmZKYxHu4GjHt/u0=; b=IoEQA2/8D84sfyGKjOlhGGs0IcvcEPn9tEnlrgJ12DKfPQPojgHJvGUou8VmZjHVLS 9di7w87JAdbMu53dbf5ZDJm2W1XTyiutDYXNLPyXoOXrN26j7+ZIlFYT/YaWgqTnVgX0 Ml4zPcunSXVOBocVyHKHuUr6PBqRD92S7ghx07WFkjtzYqJ5qSWIgoC+3cuwQs+5w+k2 yltSNd/u1zKpDq3OA787rQYjoe10hCennrcVjNnPfuP7YmafzE3dK8B4nwp9TLHFBEfT qm+0OnCKXukc/flFuDEFulf7UOi234PklzgDoZKB8j6BOn/PDxogmXsdziQLk4rfacMt 7TUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ovspL0WH; 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 ho8-20020a1709070e8800b0073d866620aasi1704334ejc.676.2022.08.22.06.39.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 06:39:03 -0700 (PDT) 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=ovspL0WH; 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 391A53856DCE for ; Mon, 22 Aug 2022 13:39:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 391A53856DCE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661175542; bh=tBCa0F0NZPNyqP85b9mIER+5fznWmZKYxHu4GjHt/u0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ovspL0WHSfN35zZz12cmGjWoxudiFVWzwnv13Lug/Qr4Y4EVBp/lGEXL8nFY7hniy n84NmrxUpWoqtWomxjPrtIk0hA3ULu9Hhw29i8Ucb3ZKtNUXIU8hGbTK1PauN7qqup LezfNEbMdUSV/5+QDkWnuYNtfaG8vtNFwlXI7R18= 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:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 6A7483856DDD for ; Mon, 22 Aug 2022 13:38:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A7483856DDD 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 3CD9234ACA for ; Mon, 22 Aug 2022 13:38:19 +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 1D5F813523 for ; Mon, 22 Aug 2022 13:38:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Lz0eBsuGA2OOZwAAMHmgww (envelope-from ) for ; Mon, 22 Aug 2022 13:38:19 +0000 Date: Mon, 22 Aug 2022 15:38:18 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Refactor is_non_loop_exit_postdominating MIME-Version: 1.0 Message-Id: <20220822133819.1D5F813523@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.9 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, 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.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?1741868806685590598?= X-GMAIL-MSGID: =?utf-8?q?1741868806685590598?= That's a weird function in predicate analysis that currently looks like /* Return true if BB1 is postdominating BB2 and BB1 is not a loop exit bb. The loop exit bb check is simple and does not cover all cases. */ static bool is_non_loop_exit_postdominating (basic_block bb1, basic_block bb2) { if (!dominated_by_p (CDI_POST_DOMINATORS, bb2, bb1)) return false; if (single_pred_p (bb1) && !single_succ_p (bb2)) return false; return true; } One can refactor this to return (dominated_by_p (CDI_POST_DOMINATORS, bb2, bb1) && !(single_pred_p (bb1) && !single_succ_p (bb2))); Notable is that the comment refers to BB1 with respect to a loop exit but the test seems to be written with an exit edge bb1 -> bb2 in mind. From the three callers only a single one is guaranteed to have bb1 and bb2 connected directly with an edge. The patch now introduces a is_loop_exit function and inlines the post-dominance check which makes the find_control_equiv_block case simpler because the post-dominance check can be elided. It also avoids the double negation in compute_control_dep_chain and makes it obvious this is the case where we do look at an edge. For the main is_use_guarded API I chose to elide the loop exit test, if the use block post-dominates the definition block of the PHI node the use is always unconditional. I don't quite understand the loop exit special-casing of the remaining two uses though. Bootstrap and regtest running on x86_64-unknown-linux-gnu. The code is this way since the original r0-99656-g34f97b9407c6a3 so I'm not hoping for any insights ... :/ * gimple-predicate-analysis.cc (is_loop_exit): Split out from ... (is_non_loop_exit_postdominating): ... here. Remove after inlining ... (find_control_equiv_block): ... here. (compute_control_dep_chain): ... and here. (predicate::is_use_guarded): Do not excempt loop exits from short-cutting the case of the use post-dominating the PHI definition. --- gcc/gimple-predicate-analysis.cc | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index d1b0d1283dc..4cf05951ec7 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -46,19 +46,12 @@ #define DEBUG_PREDICATE_ANALYZER 1 -/* Return true if BB1 is postdominating BB2 and BB1 is not a loop exit - bb. The loop exit bb check is simple and does not cover all cases. */ +/* Return true if, when BB1 is postdominating BB2, BB1 is a loop exit. */ static bool -is_non_loop_exit_postdominating (basic_block bb1, basic_block bb2) +is_loop_exit (basic_block bb2, basic_block bb1) { - if (!dominated_by_p (CDI_POST_DOMINATORS, bb2, bb1)) - return false; - - if (single_pred_p (bb1) && !single_succ_p (bb2)) - return false; - - return true; + return single_pred_p (bb1) && !single_succ_p (bb2); } /* Find BB's closest postdominator that is its control equivalent (i.e., @@ -70,7 +63,7 @@ find_control_equiv_block (basic_block bb) basic_block pdom = get_immediate_dominator (CDI_POST_DOMINATORS, bb); /* Skip the postdominating bb that is also a loop exit. */ - if (!is_non_loop_exit_postdominating (pdom, bb)) + if (is_loop_exit (bb, pdom)) return NULL; /* If the postdominator is dominated by BB, return it. */ @@ -1112,10 +1105,11 @@ compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb, if (e->flags & (EDGE_FAKE | EDGE_ABNORMAL)) continue; - basic_block cd_bb = e->dest; cur_cd_chain.safe_push (e); - while (!is_non_loop_exit_postdominating (cd_bb, dom_bb)) + while (!dominated_by_p (CDI_POST_DOMINATORS, e->src, e->dest) + || is_loop_exit (e->src, e->dest)) { + basic_block cd_bb = e->dest; if (cd_bb == dep_bb) { /* Found a direct control dependence. */ @@ -1885,7 +1879,7 @@ predicate::is_use_guarded (gimple *use_stmt, basic_block use_bb, in the same bb. */ predicate use_preds (def_bb, use_bb, m_eval); - if (is_non_loop_exit_postdominating (use_bb, def_bb)) + if (dominated_by_p (CDI_POST_DOMINATORS, def_bb, use_bb)) { if (is_empty ()) {