From patchwork Fri Aug 26 12:34:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp214511wro; Fri, 26 Aug 2022 05:35:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5WiZKN/HvWy0nytNggALVZXuZttLB5f4d9wDA352U9R9XUR0E9S9p+ya0xyRH41HujUfJy X-Received: by 2002:a17:907:1690:b0:731:56b6:fded with SMTP id hc16-20020a170907169000b0073156b6fdedmr5473974ejc.119.1661517301602; Fri, 26 Aug 2022 05:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661517301; cv=none; d=google.com; s=arc-20160816; b=TBRcGV971Sr95cV1hZsYxNSdbWSh9rm1uozCT/HSD9MIEzag5pdyc3Ne9r8/tf4a0A tg5Be7Gr1xFrONFE0AIN090sehlKr7LzuZPEc/O8ZQgyVLH9MN5UHLfHrRGPCjswmHSE oAX38lj3zkBvgcutQImIAYLS/yxxrZWB3RQOA+J9IeV5XgrAjOgsjCzJ/rO6pFem+vGy lMzla2AIl9QaQWZfYqen+PkBrE+WKBzRXXa49vL4CvcMuFySSfIxmBjBvePIZ39rFpmj hdX4Yu0Xs64gyhkOQjL6QsP0jIcqdJ/Iq7EHLEoKxNEZLZu8jOWptnZ+cy5m+29rhARH Z65A== 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=p1Ldv9ZycINS3a78pmzjnVni7zZINXqmOY2sehhSNRk=; b=bjMH04TW4JwUIQLqMNHiPmi5lUWDsjM4cfU+H1/gIVKui1LlxFTj9Ic5vmB9lTRLFR FdPzmPDqAGEsnIjib3TVYBY5g/vUUkE7X1YqwklQIeqtgQJeaIpIhQMLxwTlv5Jygkzl nTxxlEJyxf4/bnKYG4KpAIwmzfJnysDPYqQvlTItS6RyNlfLcYwrws95dRbBaDZCrtZI lmP+YaqGARqzkUJMtY45/DUqkNz/GfZZ3SvGGXRtUHX4FxHLq3IkfvNZqzwVRXQlGB2Q hp7EZwByfWEek8oj3gF+2yFoZpv4rrYyx0qrxqYVntBTmARFLdvG0bGbyK3Tfyiktq/k E6wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VbxMQkib; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id sg42-20020a170907a42a00b0070bf25f1732si1286305ejc.155.2022.08.26.05.35.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 05:35:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VbxMQkib; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B0231385114E for ; Fri, 26 Aug 2022 12:34:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0231385114E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661517294; bh=p1Ldv9ZycINS3a78pmzjnVni7zZINXqmOY2sehhSNRk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VbxMQkibXAhpr7cuV5Bg93lPpdT40uD4PCmZuCEULbso6AcphukDRBgwlfAycsV9k QabFVVKeQbSy1w+m9qXviT/d40+3W8Faz9/M3s0f43t/G9AWozgITRc0IdmWvvr63x 953Y6sJbEc/uD7F7yxx2jtCJmiDh4uh3n1rwgkXs= 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 B418E3858C74 for ; Fri, 26 Aug 2022 12:34:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B418E3858C74 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 66B691F94E for ; Fri, 26 Aug 2022 12:34:09 +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 524BF13A7E for ; Fri, 26 Aug 2022 12:34:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0VPxEsG9CGMXFQAAMHmgww (envelope-from ) for ; Fri, 26 Aug 2022 12:34:09 +0000 Date: Fri, 26 Aug 2022 14:34:08 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] Improve compute_control_dep_chain documentation MIME-Version: 1.0 Message-Id: <20220826123409.524BF13A7E@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, 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?1742227166010407589?= X-GMAIL-MSGID: =?utf-8?q?1742227166010407589?= In the quest to understand how compute_control_dep_chain works I've produced the following two changes, documenting PR106754 on the way. Bootstrap and regtest is running on x86_64-unknown-linux-gnu, the changes should be no-ops but hopefully improve understanding of the code. --- The following refactors compute_control_dep_chain slightly by inlining is_loop_exit and factoring the check on the loop invariant condition. It also adds a comment as of how I understand the code and it's current problem. * gimple-predicate-analysis.cc (compute_control_dep_chain): Inline is_loop_exit and refactor, add comment about loop exits. --- gcc/gimple-predicate-analysis.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index 32542f93057..934e9516e7b 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -1110,6 +1110,10 @@ compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb, vec &cur_cd_chain, unsigned *num_calls, unsigned in_region = 0, unsigned depth = 0) { + /* In our recursive calls this doesn't happen. */ + if (single_succ_p (dom_bb)) + return false; + if (*num_calls > (unsigned)param_uninit_control_dep_attempts) { if (dump_file) @@ -1167,7 +1171,21 @@ compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb, basic_block cd_bb = e->dest; cur_cd_chain.safe_push (e); while (!dominated_by_p (CDI_POST_DOMINATORS, dom_bb, cd_bb) - || is_loop_exit (dom_bb, cd_bb)) + /* We want to stop when the CFG merges back from the + branch in dom_bb. The post-dominance check alone + falls foul of the case of a loop exit test branch + where the path on the loop exit post-dominates + the branch block. + The following catches this but will not allow + exploring the post-dom path further. For the + outermost recursion this means we will fail to + reach dep_bb while for others it means at least + dropping the loop exit predicate from the path + which is problematic as it increases the domain + spanned by the resulting predicate. + See gcc.dg/uninit-pred-11.c for the first case + and PR106754 for the second. */ + || single_pred_p (cd_bb)) { if (cd_bb == dep_bb) { @@ -1187,9 +1205,10 @@ compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb, break; /* Check if DEP_BB is indirectly control-dependent on DOM_BB. */ - if (compute_control_dep_chain (cd_bb, dep_bb, cd_chains, - num_chains, cur_cd_chain, - num_calls, in_region, depth + 1)) + if (!single_succ_p (cd_bb) + && compute_control_dep_chain (cd_bb, dep_bb, cd_chains, + num_chains, cur_cd_chain, + num_calls, in_region, depth + 1)) { found_cd_chain = true; break; From patchwork Fri Aug 26 12:34:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp214572wro; Fri, 26 Aug 2022 05:35:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR7FqxkAQgGc45B+y8OQNhqYoky8jdn3Pz89tdwFPygZLfplrURk7AATuEYXB7F6RL8jIiMJ X-Received: by 2002:aa7:d155:0:b0:447:e6b9:ae97 with SMTP id r21-20020aa7d155000000b00447e6b9ae97mr2281223edo.161.1661517311610; Fri, 26 Aug 2022 05:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661517311; cv=none; d=google.com; s=arc-20160816; b=BRvwyna0I21llX55NiqQlK6nSMhIssAVQNIglYUsfQ55YDeGReSvwULhme5+oq95XV oSYeXR/uj2Eb9xXaM3wizWU7bW8S1fO4iMyHNOx+4XjlXifau0qZLPxIWGYGO97y7CjC 7pxWHB3pDeXOj0OugAE8EKahvRbgZs0ucGHiYwr5R/mMyD5Qh5SGxhNEfKXIU9k03xrk 1ogCrLsmR7ym7mqN3Sv+HcjuKy2S5iQpGEn+J0svMZkOzh5pT9UtfDcnKUQnjd9GGSco ZYu6ex+fMRu45ogVLRcCFKoY2HXlV5pQVzEr0VaIFi2NHsDcUSq/P6YpwkwsbN9edw2u Jhlg== 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=RXEn1yVK7Xl+j0Wqvkg8xIr4EV/A3mXTA3BP1flZ6tU=; b=oHezWZMUGO+jLJ6e0YaHXGNPPcFWLh26nuAaGRVzb0KqSqwFCEaJG/b60cg/ts6t30 rQej5eGm5dtU1xiyi25f2VT7RO2Qo+DUZj7xTxK/xS0/RrKQQFIceYxz3ocO0pRZPhgv 2uulYT2wVgNVmRUBbNr3DLI3+QTZYy17zNmGcAf8JiZp6bNsS+XJLGLM52TrIt4rWngN 9eABVfhO4zSORV/7Y3mxKsov5G8u02eF23hh2gWBWDIMeO5e47jkamb+9fAey1pET9mS nMuMjP74Po8SFuNU/L4d0bFZxwtWifL5vfuLIYw0RuD/x8ohFhf0iY/PLBMUbY1dDZ0h GYUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=T8WM3pBR; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u16-20020a17090617d000b0073d88927a49si843250eje.124.2022.08.26.05.35.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 05:35:11 -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=T8WM3pBR; 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 834923851162 for ; Fri, 26 Aug 2022 12:35:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 834923851162 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661517304; bh=RXEn1yVK7Xl+j0Wqvkg8xIr4EV/A3mXTA3BP1flZ6tU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=T8WM3pBRtPyhI3w4trLnhFkME5ILsCuWmHbauieCr/ToyP6zRMegH+molQt5cIyGl g9V00TaY3IPBhGZifqUdceoLaCDwWrouzztK4m5AUKKfBDA5POScSM47Ma2eyaMfj7 rosqjBdieG5ZhXMuONiuaZVxnP365ms++fgjDu8E= 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 [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 5CE543854157 for ; Fri, 26 Aug 2022 12:34:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5CE543854157 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 4EA331F94E for ; Fri, 26 Aug 2022 12:34:14 +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 39C2D13A7E for ; Fri, 26 Aug 2022 12:34:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MyMjDca9CGMgFQAAMHmgww (envelope-from ) for ; Fri, 26 Aug 2022 12:34:14 +0000 Date: Fri, 26 Aug 2022 14:34:13 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] Refactor init_use_preds and find_control_equiv_block MIME-Version: 1.0 Message-Id: <20220826123414.39C2D13A7E@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 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?1742227176580403976?= X-GMAIL-MSGID: =?utf-8?q?1742227176580403976?= The following inlines find_control_equiv_block and is_loop_exit into init_use_preds and refactors that for better readability and similarity with the post-dominator walk in compute_control_dep_chain. * gimple-predicate-analysis.cc (is_loop_exit, find_control_equiv_block): Inline into single caller ... (uninit_analysis::init_use_preds): ... here and refactor. --- gcc/gimple-predicate-analysis.cc | 55 ++++++++++---------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index 934e9516e7b..e388bb37685 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -59,33 +59,6 @@ for the case corresponding to an edge. */ #define MAX_SWITCH_CASES 40 -/* Return true if, when BB1 is postdominating BB2, BB1 is a loop exit. */ - -static bool -is_loop_exit (basic_block bb2, basic_block bb1) -{ - return single_pred_p (bb1) && !single_succ_p (bb2); -} - -/* Find BB's closest postdominator that is its control equivalent (i.e., - that's controlled by the same predicate). */ - -static inline basic_block -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_loop_exit (bb, pdom)) - return NULL; - - /* If the postdominator is dominated by BB, return it. */ - if (dominated_by_p (CDI_DOMINATORS, pdom, bb)) - return pdom; - - return NULL; -} - /* Return true if X1 is the negation of X2. */ static inline bool @@ -1991,25 +1964,29 @@ bool uninit_analysis::init_use_preds (predicate &use_preds, basic_block def_bb, basic_block use_bb) { - gcc_assert (use_preds.is_empty ()); + gcc_assert (use_preds.is_empty () + && dominated_by_p (CDI_DOMINATORS, use_bb, def_bb)); /* Set CD_ROOT to the basic block closest to USE_BB that is the control equivalent of (is guarded by the same predicate as) DEF_BB that also - dominates USE_BB. */ + dominates USE_BB. This mimics the inner loop in + compute_control_dep_chain. */ basic_block cd_root = def_bb; - while (dominated_by_p (CDI_DOMINATORS, use_bb, cd_root)) + do { - /* Find CD_ROOT's closest postdominator that's its control - equivalent. */ - if (basic_block bb = find_control_equiv_block (cd_root)) - if (dominated_by_p (CDI_DOMINATORS, use_bb, bb)) - { - cd_root = bb; - continue; - } + basic_block pdom = get_immediate_dominator (CDI_POST_DOMINATORS, cd_root); - break; + /* Stop at a loop exit which is also postdominating cd_root. */ + if (single_pred_p (pdom) && !single_succ_p (cd_root)) + break; + + if (!dominated_by_p (CDI_DOMINATORS, pdom, cd_root) + || !dominated_by_p (CDI_DOMINATORS, use_bb, pdom)) + break; + + cd_root = pdom; } + while (1); /* Set DEP_CHAINS to the set of edges between CD_ROOT and USE_BB. Each DEP_CHAINS element is a series of edges whose conditions