From patchwork Wed May 3 23:12:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 89870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1668106vqo; Wed, 3 May 2023 16:13:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7w4D5UVtM6QXOzJEHOwdKYJEwMtdGHF1AFfhiraSi94gJ0XWDqiq1QBtBm5Pll7dLlRnoZ X-Received: by 2002:a05:6402:716:b0:50b:c3f0:fb9d with SMTP id w22-20020a056402071600b0050bc3f0fb9dmr9949560edx.41.1683155615737; Wed, 03 May 2023 16:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683155615; cv=none; d=google.com; s=arc-20160816; b=twc8ETuSmDnQXyZcVvZ4IxK2+vdDNXdlOjN2rc1O0mHIiENkIomBc3sBSd8+IBGNng 3y8ufnbMdc+4SjNB7JTExjeqQWCcZCNTjJwzw/K6JH8u4Mu4AZgufcx9ODkXooF3aJBH C28HnUp1UG/kAiBQ3e03VBfRu1JCWsGuhjDz7hidqfLWxI/Tf+AuDGrODku/aQ+UFuTE hOV/uQQ8OKx3AANmIxftsM63pUHrO4NiKOJZCN0uN4r5xCjNigFgrGtwwsMht2CkNQxu 0M2Dd+HqwGieFbkOKLl4PMKYHaMJaAItmDFr4Emh8zlpv6DrlsX9PXygrJAXnKJCjGSs eA6A== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=olevAcF0NVNZLbUVnE69JwpBkkSbTC8A/2RSfr424K8=; b=hFBK6OopErNjKkb0XOiRM9aZGwbzNVPXxU6kjGcwTAbGgZM22CdqURjNCCQ65xETTq jiB2PbpbaIut2s7HipavEf0yJgqoo+R/JdDPP3MP5TCBJ8lJ+MTWXfhLNpOoSslsh7Qa r5wE4BDd3cLfmkcXtSvc5OVfI2iSLvrWekvYQNiP5E0H/sLSNavCbU/hVuuXB5F4xTvK KowyvBE9Miwq8h2SLazw3xWQ3BKubm3C8nWBojojRomKf328XbYp5cqyNbbQsPyuCumP 74I+zf3MOj1kITKHmfptW1VCNr5nY60VaUiHJmOO/BD3F2X17/n/SHoKWg0nBCdbH/a1 +o7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FOUnvA3G; 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 y23-20020aa7c257000000b0050b79388bbesi1908779edo.55.2023.05.03.16.13.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 16:13:35 -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=FOUnvA3G; 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 4125C385701E for ; Wed, 3 May 2023 23:13:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4125C385701E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683155600; bh=olevAcF0NVNZLbUVnE69JwpBkkSbTC8A/2RSfr424K8=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FOUnvA3G3M0FB0izvhJ8+z+8MyEBHxXSKUR1+kDpGEi603Y4YSDHnHIhlPzhJPfuk uj7TIppd2Xj7ojdOSB4mm9e8qZfn4ee5wiUlrnyhz8PHx5nmJbyhllfhn/3FuCxvIm JbvxcFwXx14kzvoEp6cWegp97BTYwmcV8ANrDyQM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 6CC783858D28 for ; Wed, 3 May 2023 23:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CC783858D28 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343MkQoD012197 for ; Wed, 3 May 2023 16:12:32 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qc0pq834q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 03 May 2023 16:12:32 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 3 May 2023 16:12:29 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 3 May 2023 16:12:29 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 2E4785B6928; Wed, 3 May 2023 16:12:29 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/2] Move copy_phi_arg_into_existing_phi to common location and use it Date: Wed, 3 May 2023 16:12:23 -0700 Message-ID: <20230503231224.931656-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: KxCc8v3uCcGxR8hCRw1sY1uiknRNnLvk X-Proofpoint-ORIG-GUID: KxCc8v3uCcGxR8hCRw1sY1uiknRNnLvk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski 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?1764916582669542548?= X-GMAIL-MSGID: =?utf-8?q?1764916582669542548?= While improving replace_phi_edge_with_variable for the diamond formed bb case, I need a way to copy phi entries from one edge to another as I am removing a forwarding bb inbetween. I was pointed out that jump threading code had copy_phi_arg_into_existing_phi which I can use. I also noticed that both gimple_duplicate_sese_tail and remove_forwarder_block have similar code so it makes sense to use that function in those two locations too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-cfg.cc (copy_phi_args): New function (gimple_duplicate_sese_tail): Use it instead of doing it inline. * tree-cfg.h (copy_phi_args): New declaration. * tree-cfgcleanup.cc (remove_forwarder_block): Use copy_phi_args instead of implementing it inline. gcc/ChangeLog: * tree-ssa-threadupdate.cc (copy_phi_arg_into_existing_phi): Move to ... * tree-cfg.cc (copy_phi_arg_into_existing_phi): Here and remove static. (gimple_duplicate_sese_tail): Use copy_phi_arg_into_existing_phi instead of an inline version of it. * tree-cfgcleanup.cc (remove_forwarder_block): Likewise. * tree-cfg.h (copy_phi_arg_into_existing_phi): New declaration. --- gcc/tree-cfg.cc | 38 +++++++++++++++++++++++++----------- gcc/tree-cfg.h | 1 + gcc/tree-cfgcleanup.cc | 12 ++---------- gcc/tree-ssa-threadupdate.cc | 25 ------------------------ 4 files changed, 30 insertions(+), 46 deletions(-) diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 4927fc0a8d9..a94dc3c2eea 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -6802,6 +6802,32 @@ bb_part_of_region_p (basic_block bb, basic_block* bbs, unsigned n_region) return false; } + +/* For each PHI in BB, copy the argument associated with SRC_E to TGT_E. + Assuming the argument exists, just does not have a value. */ + +void +copy_phi_arg_into_existing_phi (edge src_e, edge tgt_e) +{ + int src_idx = src_e->dest_idx; + int tgt_idx = tgt_e->dest_idx; + + /* Iterate over each PHI in e->dest. */ + for (gphi_iterator gsi = gsi_start_phis (src_e->dest), + gsi2 = gsi_start_phis (tgt_e->dest); + !gsi_end_p (gsi); + gsi_next (&gsi), gsi_next (&gsi2)) + { + gphi *src_phi = gsi.phi (); + gphi *dest_phi = gsi2.phi (); + tree val = gimple_phi_arg_def (src_phi, src_idx); + location_t locus = gimple_phi_arg_location (src_phi, src_idx); + + SET_PHI_ARG_DEF (dest_phi, tgt_idx, val); + gimple_phi_arg_set_location (dest_phi, tgt_idx, locus); + } +} + /* Duplicates REGION consisting of N_REGION blocks. The new blocks are stored to REGION_COPY in the same order in that they appear in REGION, if REGION_COPY is not NULL. ENTRY is the entry to @@ -6847,9 +6873,6 @@ gimple_duplicate_sese_tail (edge entry, edge exit, gimple_stmt_iterator gsi; edge sorig, snew; basic_block exit_bb; - gphi_iterator psi; - gphi *phi; - tree def; class loop *target, *aloop, *cloop; gcc_assert (EDGE_COUNT (exit->src->succs) == 2); @@ -6947,14 +6970,7 @@ gimple_duplicate_sese_tail (edge entry, edge exit, gcc_assert (single_succ_edge (region_copy[i])); e = redirect_edge_and_branch (single_succ_edge (region_copy[i]), exit_bb); PENDING_STMT (e) = NULL; - for (psi = gsi_start_phis (exit_bb); - !gsi_end_p (psi); - gsi_next (&psi)) - { - phi = psi.phi (); - def = PHI_ARG_DEF (phi, nexits[0]->dest_idx); - add_phi_arg (phi, def, e, gimple_phi_arg_location_from_edge (phi, e)); - } + copy_phi_arg_into_existing_phi (nexits[0], e); } e = redirect_edge_and_branch (nexits[1], nexits[0]->dest); PENDING_STMT (e) = NULL; diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h index 9b56a68fe9d..9a1605be305 100644 --- a/gcc/tree-cfg.h +++ b/gcc/tree-cfg.h @@ -113,6 +113,7 @@ extern basic_block gimple_switch_default_bb (function *, gswitch *); extern edge gimple_switch_edge (function *, gswitch *, unsigned); extern edge gimple_switch_default_edge (function *, gswitch *); extern bool cond_only_block_p (basic_block); +extern void copy_phi_arg_into_existing_phi (edge, edge); /* Return true if the LHS of a call should be removed. */ diff --git a/gcc/tree-cfgcleanup.cc b/gcc/tree-cfgcleanup.cc index 42b25312122..193d87e3278 100644 --- a/gcc/tree-cfgcleanup.cc +++ b/gcc/tree-cfgcleanup.cc @@ -610,17 +610,9 @@ remove_forwarder_block (basic_block bb) if (s == e) { - /* Create arguments for the phi nodes, since the edge was not + /* Copy arguments for the phi nodes, since the edge was not here before. */ - for (gphi_iterator psi = gsi_start_phis (dest); - !gsi_end_p (psi); - gsi_next (&psi)) - { - gphi *phi = psi.phi (); - location_t l = gimple_phi_arg_location_from_edge (phi, succ); - tree def = gimple_phi_arg_def (phi, succ->dest_idx); - add_phi_arg (phi, unshare_expr (def), s, l); - } + copy_phi_arg_into_existing_phi (succ, s); } } diff --git a/gcc/tree-ssa-threadupdate.cc b/gcc/tree-ssa-threadupdate.cc index 33a91063638..d5416b21a78 100644 --- a/gcc/tree-ssa-threadupdate.cc +++ b/gcc/tree-ssa-threadupdate.cc @@ -511,31 +511,6 @@ fwd_jt_path_registry::lookup_redirection_data (edge e, insert_option insert) } } -/* Similar to copy_phi_args, except that the PHI arg exists, it just - does not have a value associated with it. */ - -static void -copy_phi_arg_into_existing_phi (edge src_e, edge tgt_e) -{ - int src_idx = src_e->dest_idx; - int tgt_idx = tgt_e->dest_idx; - - /* Iterate over each PHI in e->dest. */ - for (gphi_iterator gsi = gsi_start_phis (src_e->dest), - gsi2 = gsi_start_phis (tgt_e->dest); - !gsi_end_p (gsi); - gsi_next (&gsi), gsi_next (&gsi2)) - { - gphi *src_phi = gsi.phi (); - gphi *dest_phi = gsi2.phi (); - tree val = gimple_phi_arg_def (src_phi, src_idx); - location_t locus = gimple_phi_arg_location (src_phi, src_idx); - - SET_PHI_ARG_DEF (dest_phi, tgt_idx, val); - gimple_phi_arg_set_location (dest_phi, tgt_idx, locus); - } -} - /* Given ssa_name DEF, backtrack jump threading PATH from node IDX to see if it has constant value in a flow sensitive manner. Set LOCUS to location of the constant phi arg and return the value. From patchwork Wed May 3 23:12:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 89871 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1668130vqo; Wed, 3 May 2023 16:13:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4MjaauZuO1E3CT/i5Qs0aiqBzUlYtvaEdIKmn7MdhU6OPRJak4FryIW+f5eDShl6dNVJwo X-Received: by 2002:aa7:d1d5:0:b0:50b:c704:2dda with SMTP id g21-20020aa7d1d5000000b0050bc7042ddamr9648155edp.8.1683155618997; Wed, 03 May 2023 16:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683155618; cv=none; d=google.com; s=arc-20160816; b=0TxjgCAQjMBBqDSHWnXdP0pjWsRSc1Y2Dpjl/f7+Vg77B2/JoXvSXY0wwfOe6ok9EY KSoWRurrdfdK3RDTCpsGPbN74hhLrriAKvC03+kskcpxPFZ7DYhbEiZHyDHyOm51aEKS 9UTgd4vpABAkpeV+YGJADh7RtDj+x9sAVKxvBh8I1YhYaB1WfXnL7sjwuGLDVMFvO4Zx vVw1UaUj8BNjJqZnMn1YhNRYK3rXgbgMR2X1KN//FdFE539mpJPUjIM4Cb1nW4SzfP3u sBPdp7CmNivB3wJFG5oNivIp3SYNS640hUY0eKSthEcgkJBQrp58yphZnys90zZ0VgDK 0snw== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=dxuzuWG7QCxELA38AvXtXfXK2YuxvM5kdxa0WJhmUu8=; b=yf8+BZ6Vo4U97qyeWjCZtE8M4ecTtzA+H05OQ6ZTW+yQwj9ymOsHhyXz5wF6G/kO86 Vf1b2rsdARqmPo+/WvVNAplC3deyyRGPNsv1hqLtd3tjv6NdXg2iuFepOP7UHvwQrxtd Y71vSRLcdnlQArhhjYSxDve+vgurYlBdalZ8tL2xZCUY4GCPn2OeAUMGJbGfcuwcuMYh +DEDphh94AdZun8iwRaYgijSvP7BA4I2lmXQCRJ7aZwafzikmQeC/ieHAXtc2iT2oOwW xydQ+veEL8PKlWgiIJAqR6j7t8DjoRwCon5SsCPB7pJTSMsJUvPYHhwkfKaRXXea+r/w xOUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=V0OkJ9To; 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 r21-20020aa7cfd5000000b00506730cbd0dsi1907125edy.518.2023.05.03.16.13.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 16:13:38 -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=V0OkJ9To; 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 77A3C3857025 for ; Wed, 3 May 2023 23:13:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77A3C3857025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683155602; bh=dxuzuWG7QCxELA38AvXtXfXK2YuxvM5kdxa0WJhmUu8=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=V0OkJ9TogMOSEtJc1kZsQEhfyabJgwjKPP1lveZzRcnINLTWrurVDpm8AZnjbVLXn Sa/XcdZh/1xDvM3y4oB9rwloldfO+oNHfPQGQt4oqTFIAPbv4Yd97TV2kEHbdpPaNK n98RF+0owEkhDUUV7opixuLxzS6Z2eycHLJ9LD8Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id E526F3858D33 for ; Wed, 3 May 2023 23:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E526F3858D33 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343MkQoF012197 for ; Wed, 3 May 2023 16:12:33 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qc0pq834q-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 03 May 2023 16:12:32 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 3 May 2023 16:12:30 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 3 May 2023 16:12:30 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 9F6A85B6929; Wed, 3 May 2023 16:12:29 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCHv2 2/2] PHIOPT: Improve replace_phi_edge_with_variable for diamond shapped bb Date: Wed, 3 May 2023 16:12:24 -0700 Message-ID: <20230503231224.931656-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503231224.931656-1-apinski@marvell.com> References: <20230503231224.931656-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: LVkpD3RzWiT0zayomBYDashj0nbW8NMH X-Proofpoint-ORIG-GUID: LVkpD3RzWiT0zayomBYDashj0nbW8NMH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski 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?1764916586224551730?= X-GMAIL-MSGID: =?utf-8?q?1764916586224551730?= While looking at differences between what minmax_replacement and match_simplify_replacement does. I noticed that they sometimes chose different edges to remove. I decided we should be able to do better and be able to remove both empty basic blocks in the case of match_simplify_replacement as that moves the statements. This also updates the testcases as now match_simplify_replacement will remove the unused MIN/MAX_EXPR and they were checking for those. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (replace_phi_edge_with_variable): Handle diamond form bb with forwarder only empty blocks better. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-15.c: Update test. * gcc.dg/tree-ssa/minmax-16.c: Update test. * gcc.dg/tree-ssa/minmax-3.c: Update test. * gcc.dg/tree-ssa/minmax-4.c: Update test. * gcc.dg/tree-ssa/minmax-5.c: Update test. * gcc.dg/tree-ssa/minmax-8.c: Update test. --- gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c | 3 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c | 9 ++---- gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c | 2 +- gcc/tree-ssa-phiopt.cc | 35 ++++++++++++++++++++++- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c index 8a39871c938..6731f91e6c3 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c @@ -30,5 +30,6 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ +/* There should only be two MIN_EXPR left, the 3rd one was removed. */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c index 623b12b3f74..094364e6424 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c @@ -25,11 +25,8 @@ main (void) return 0; } -/* After phiopt1, there really should be only 3 MIN_EXPR in the IR (including debug statements). - But the way phiopt does not cleanup the CFG all the time, the PHI might still reference the - alternative bb's moved statement. - Note in the end, we do dce the statement and other debug statements to end up with only 2 MIN_EXPR. - So check that too. */ -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 4 "phiopt1" } } */ +/* After phiopt1, will be only 2 MIN_EXPR in the IR (including debug statements). */ +/* xk will only have the final result so the extra debug info does not change anything. */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c index 2af10776346..521afe3e4d9 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c @@ -25,5 +25,5 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c index 973f39bfed3..49e27185b5e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c @@ -26,4 +26,4 @@ main (void) } /* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 3 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c index 34e4e720511..194c881cc98 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c @@ -25,5 +25,5 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c index 0160e573fef..d5cb53145ea 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c @@ -26,4 +26,4 @@ main (void) } /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */ -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index fbc1fd66607..7ba24211025 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -94,6 +94,7 @@ replace_phi_edge_with_variable (basic_block cond_block, basic_block bb = gimple_bb (phi); gimple_stmt_iterator gsi; tree phi_result = PHI_RESULT (phi); + bool deleteboth = false; /* Duplicate range info if they are the only things setting the target PHI. This is needed as later on, the new_tree will be replacing @@ -137,7 +138,14 @@ replace_phi_edge_with_variable (basic_block cond_block, keep_edge = EDGE_SUCC (cond_block, 1); } else if ((keep_edge = find_edge (cond_block, e->src))) - ; + { + basic_block bb1 = EDGE_SUCC (cond_block, 0)->dest; + basic_block bb2 = EDGE_SUCC (cond_block, 1)->dest; + if (single_pred_p (bb1) && single_pred_p (bb2) + && single_succ_p (bb1) && single_succ_p (bb2) + && empty_block_p (bb1) && empty_block_p (bb2)) + deleteboth = true; + } else gcc_unreachable (); @@ -148,6 +156,31 @@ replace_phi_edge_with_variable (basic_block cond_block, e->probability = profile_probability::always (); delete_basic_block (edge_to_remove->dest); + /* Eliminate the COND_EXPR at the end of COND_BLOCK. */ + gsi = gsi_last_bb (cond_block); + gsi_remove (&gsi, true); + } + else if (deleteboth) + { + basic_block bb1 = EDGE_SUCC (cond_block, 0)->dest; + basic_block bb2 = EDGE_SUCC (cond_block, 1)->dest; + + edge newedge = redirect_edge_and_branch (keep_edge, bb); + + /* The new edge should be the same. */ + gcc_assert (newedge == keep_edge); + + keep_edge->flags |= EDGE_FALLTHRU; + keep_edge->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE); + keep_edge->probability = profile_probability::always (); + + /* Copy the edge's phi entry from the old one. */ + copy_phi_arg_into_existing_phi (e, keep_edge); + + /* Delete the old 2 empty basic blocks */ + delete_basic_block (bb1); + delete_basic_block (bb2); + /* Eliminate the COND_EXPR at the end of COND_BLOCK. */ gsi = gsi_last_bb (cond_block); gsi_remove (&gsi, true);