From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 52C8E385840F for ; Fri, 3 Sep 2021 14:37:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 52C8E385840F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-wXRKOuwBM3WgIJjCGXc77g-1; Fri, 03 Sep 2021 10:37:23 -0400 X-MC-Unique: wXRKOuwBM3WgIJjCGXc77g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D72C101371B; Fri, 3 Sep 2021 14:37:22 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4460100164A; Fri, 3 Sep 2021 14:37:21 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 183EbEBa742583 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 Sep 2021 16:37:20 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 183DuKdH735591; Fri, 3 Sep 2021 15:56:20 +0200 From: Aldy Hernandez To: GCC patches Subject: [PATCH] Abstract PHI and forwarder block checks in jump threader. Date: Fri, 3 Sep 2021 15:56:07 +0200 Message-Id: <20210903135608.735535-2-aldyh@redhat.com> In-Reply-To: <20210903135608.735535-1-aldyh@redhat.com> References: <20210903135608.735535-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 03 Sep 2021 14:37:25 -0000 This patch abstracts out a couple common idioms in the forward threader that I found useful while navigating the code base. Tested on x86-64 Linux. OK? gcc/ChangeLog: * tree-ssa-threadedge.c (has_phis_p): New. (forwarder_block_p): New. (potentially_threadable_block): Call forwarder_block_p. (jump_threader::thread_around_empty_blocks): Call has_phis_p. (jump_threader::thread_through_normal_block): Call forwarder_block_p. --- gcc/tree-ssa-threadedge.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index e57f6d3e39c..3db54a199fd 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -95,6 +95,21 @@ jump_threader::thread_through_all_blocks (bool may_peel_loop_headers) return m_registry->thread_through_all_blocks (may_peel_loop_headers); } +static inline bool +has_phis_p (basic_block bb) +{ + return !gsi_end_p (gsi_start_phis (bb)); +} + +/* Return TRUE for a forwarder block which is defined as having PHIs + but no instructions. */ + +static bool +forwarder_block_p (basic_block bb) +{ + return gsi_end_p (gsi_start_nondebug_bb (bb)) && has_phis_p (bb); +} + /* Return TRUE if we may be able to thread an incoming edge into BB to an outgoing edge from BB. Return FALSE otherwise. */ @@ -107,9 +122,8 @@ potentially_threadable_block (basic_block bb) not optimized away because they forward from outside a loop to the loop header. We want to thread through them as we can sometimes thread to the loop exit, which is obviously profitable. - the interesting case here is when the block has PHIs. */ - if (gsi_end_p (gsi_start_nondebug_bb (bb)) - && !gsi_end_p (gsi_start_phis (bb))) + The interesting case here is when the block has PHIs. */ + if (forwarder_block_p (bb)) return true; /* If BB has a single successor or a single predecessor, then @@ -854,7 +868,7 @@ jump_threader::thread_around_empty_blocks (vec *path, /* The key property of these blocks is that they need not be duplicated when threading. Thus they cannot have visible side effects such as PHI nodes. */ - if (!gsi_end_p (gsi_start_phis (bb))) + if (has_phis_p (bb)) return false; /* Skip over DEBUG statements at the start of the block. */ @@ -994,8 +1008,7 @@ jump_threader::thread_through_normal_block (vec *path, { /* First case. The statement simply doesn't have any instructions, but does have PHIs. */ - if (gsi_end_p (gsi_start_nondebug_bb (e->dest)) - && !gsi_end_p (gsi_start_phis (e->dest))) + if (forwarder_block_p (e->dest)) return 0; /* Second case. */ -- 2.31.1