From patchwork Sat Apr 22 22:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86642 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1912029vqo; Sat, 22 Apr 2023 15:13:16 -0700 (PDT) X-Google-Smtp-Source: AKy350bo40nV0ssCKDSbINoG6QyeUr6b0tg4ZX++7toFG/WcZMJB4tPHQCJ8QCkaCDpHiw3Wfmps X-Received: by 2002:a05:6402:26c4:b0:504:77ed:5a33 with SMTP id x4-20020a05640226c400b0050477ed5a33mr13121586edd.8.1682201595875; Sat, 22 Apr 2023 15:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201595; cv=none; d=google.com; s=arc-20160816; b=ycs2wYpLr3g/QiRCqBjlksi0KfScvWDZo0jaBe9IYTxV6fvKJYPxIXbtDi5R8RWBVv ENa+k5pbA2teN9hIukFL88gPtYHG21hwRfPDwqtSAtzPfbND25bjg6O2xLldOxqoAQWF 34sxab+fbgeo4+HzVqGZRIa69B3/j0Bw0I9Z/ijYmqfokiOHsCRoH7bx/UHHGBoewcY4 dCvopv6yhoh7rr0bTke9/+J8xDGm44kpbaY6aCCt/L2gxZ4Fyo5sZgIQUu2SSs5aLbb9 WzedwCRy5QMjEjJrv1s4784q7zjDADdOwDuXKOi4WJIqz6BSsghZwUteM2Y7rFdNEBe/ TvPg== 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=0xHEgOLNm/Z14zJoUj3JHp2RJ2f8+dyOjBNoeJeOUA0=; b=Mb4ZRBe+oX5Uhh1N9vzNMCbTbZGTEHhI+QTv1RQXVmtDZw/X3VTf1loK4vNcflCnLn IqsMUHR6nXQfAnaHMM6aKEqEcGbowZXp58fm5YgBDJzzh0gIMZWc0DE5eWDsVIxXaMjl Uehuc5zORHpkpx5jcnvLdHGGCYHvtlG+bPUBxwIUIuW7AV65WjeRg+u+CnpM7tRcewb/ diF8oi4mgrcZoo2zesgbyJiOsm97ZtZNiy+7buTa+vr7dsWXm8mAp3fSe/gKFgcrMEzn wmX4T8nhON4jmx/kbUcz3YEx403sTnU9vaCTTNlJtoLHS/RHO7aAAXWNRPX4Ta3NBRWd huVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JQ0YzgrD; 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 q3-20020a056402032300b005002d6ebd39si5717021edw.19.2023.04.22.15.13.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:13:15 -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=JQ0YzgrD; 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 37348385701A for ; Sat, 22 Apr 2023 22:11:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37348385701A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201489; bh=0xHEgOLNm/Z14zJoUj3JHp2RJ2f8+dyOjBNoeJeOUA0=; 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=JQ0YzgrDSnOSGkZF1SrpiWOv+zfRKo/qD81NbdSXfenGPAR1t4cT4GF8gLUCs5XQZ q++o6DDWI6+4wHzhmgQfkXVan7NMrGaN3JeY7g9aR1TNwQqtnleLhi/DHPrmUIjDsT g0lnNAjQ+2yuw1nTcTHPDJacLMIELn/q6Oa2BtJw= 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 8417D3858C74 for ; Sat, 22 Apr 2023 22:09:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8417D3858C74 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 33MLGWq8006595 for ; Sat, 22 Apr 2023 15:09:43 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhpa0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:43 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 22 Apr 2023 15:09:31 -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; Sat, 22 Apr 2023 15:09:31 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 9E6013F709B; Sat, 22 Apr 2023 15:09:30 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/6] PHIOPT: Cleanup tree_ssa_phiopt_worker code Date: Sat, 22 Apr 2023 15:09:17 -0700 Message-ID: <20230422220921.452264-3-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230422220921.452264-1-apinski@marvell.com> References: <20230422220921.452264-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: SKuCozzX8lBr1V4sF8DLij1vkChTnDsr X-Proofpoint-GUID: SKuCozzX8lBr1V4sF8DLij1vkChTnDsr 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-04-22_15,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.6 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?1763916220311078452?= X-GMAIL-MSGID: =?utf-8?q?1763916220311078452?= This patch cleans up tree_ssa_phiopt_worker by merging common code. Making do_store_elim handled earlier. Note this does not change any overall logic of the code, just moves code around enough to be able to do this. This will make it easier to move code around even more and a few other fixes I have. Plus I think all of the do_store_elim code really should move to its own function as how much code is shared is now obvious not much. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-ssa-phiopt.cc (tree_ssa_phiopt_worker): Rearrange code for better code readability. --- gcc/tree-ssa-phiopt.cc | 212 +++++++++++++++++++++-------------------- 1 file changed, 107 insertions(+), 105 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 296ba646e62..05f19825ce9 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -175,10 +175,14 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) std::swap (bb1, bb2); std::swap (e1, e2); } - else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest) + else if (EDGE_SUCC (bb1, 0)->dest == EDGE_SUCC (bb2, 0)->dest + && single_succ_p (bb2)) { diamond_p = true; e2 = EDGE_SUCC (bb2, 0); + /* Make sure bb2 is just a fall through. */ + if ((e2->flags & EDGE_FALLTHRU) == 0) + continue; } else continue; @@ -190,46 +194,23 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) || (e1->flags & EDGE_FALLTHRU) == 0) continue; - if (do_store_elim && diamond_p) + if (do_store_elim) { - basic_block bb3 = e1->dest; - - if (!single_succ_p (bb2) - || (e2->flags & EDGE_FALLTHRU) == 0 - || EDGE_COUNT (bb3->preds) != 2) - continue; - if (cond_if_else_store_replacement (bb1, bb2, bb3)) - cfgchanged = true; - continue; - } - else if (do_hoist_loads && diamond_p) - { - basic_block bb3 = e1->dest; - - if (!FLOAT_TYPE_P (TREE_TYPE (gimple_cond_lhs (cond_stmt))) - && single_succ_p (bb2) - && single_pred_p (bb1) - && single_pred_p (bb2) - && EDGE_COUNT (bb->succs) == 2 - && EDGE_COUNT (bb3->preds) == 2 - /* If one edge or the other is dominant, a conditional move - is likely to perform worse than the well-predicted branch. */ - && !predictable_edge_p (EDGE_SUCC (bb, 0)) - && !predictable_edge_p (EDGE_SUCC (bb, 1))) - hoist_adjacent_loads (bb, bb1, bb2, bb3); - continue; - } - - if (diamond_p) - { - if (!single_pred_p (bb1) - || !single_pred_p (bb2) - || !single_succ_p (bb2)) - continue; - } + if (diamond_p) + { + basic_block bb3 = e1->dest; + + /* Only handle sinking of store from 2 bbs only, + The middle bbs don't need to come from the + if always since we are sinking rather than + hoisting. */ + if (EDGE_COUNT (bb3->preds) != 2) + continue; + if (cond_if_else_store_replacement (bb1, bb2, bb3)) + cfgchanged = true; + continue; + } - if (do_store_elim && !diamond_p) - { /* Also make sure that bb1 only have one predecessor and that it is bb. */ if (!single_pred_p (bb1) @@ -243,85 +224,106 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) continue; if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) cfgchanged = true; + continue; } - else + + if (diamond_p) { - gimple_stmt_iterator gsi; - bool candorest = true; + basic_block bb3 = e1->dest; + + if (!single_pred_p (bb1) + || !single_pred_p (bb2)) + continue; - /* Check that we're looking for nested phis. */ - basic_block merge = diamond_p ? EDGE_SUCC (bb2, 0)->dest : bb2; - gimple_seq phis = phi_nodes (merge); + if (do_hoist_loads + && !FLOAT_TYPE_P (TREE_TYPE (gimple_cond_lhs (cond_stmt))) + && EDGE_COUNT (bb->succs) == 2 + && EDGE_COUNT (bb3->preds) == 2 + /* If one edge or the other is dominant, a conditional move + is likely to perform worse than the well-predicted branch. */ + && !predictable_edge_p (EDGE_SUCC (bb, 0)) + && !predictable_edge_p (EDGE_SUCC (bb, 1))) + { + hoist_adjacent_loads (bb, bb1, bb2, bb3); + continue; + } + } - /* Value replacement can work with more than one PHI - so try that first. */ - if (!early_p && !diamond_p) - for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) + gimple_stmt_iterator gsi; + bool candorest = true; + + /* Check that we're looking for nested phis. */ + basic_block merge = diamond_p ? EDGE_SUCC (bb2, 0)->dest : bb2; + gimple_seq phis = phi_nodes (merge); + + /* Value replacement can work with more than one PHI + so try that first. */ + if (!early_p && !diamond_p) + for (gsi = gsi_start (phis); !gsi_end_p (gsi); gsi_next (&gsi)) + { + phi = as_a (gsi_stmt (gsi)); + arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1) == 2) { - phi = as_a (gsi_stmt (gsi)); - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); - if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1) == 2) - { - candorest = false; - cfgchanged = true; - break; - } + candorest = false; + cfgchanged = true; + break; } + } - if (!candorest) - continue; + if (!candorest) + continue; - phi = single_non_singleton_phi_for_edges (phis, e1, e2); - if (!phi) - continue; + phi = single_non_singleton_phi_for_edges (phis, e1, e2); + if (!phi) + continue; + + arg0 = gimple_phi_arg_def (phi, e1->dest_idx); + arg1 = gimple_phi_arg_def (phi, e2->dest_idx); + /* Something is wrong if we cannot find the arguments in the PHI + node. */ + gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); + + gphi *newphi; + if (single_pred_p (bb1) + && !diamond_p + && (newphi = factor_out_conditional_conversion (e1, e2, phi, + arg0, arg1, + cond_stmt))) + { + phi = newphi; + /* factor_out_conditional_conversion may create a new PHI in + BB2 and eliminate an existing PHI in BB2. Recompute values + that may be affected by that change. */ arg0 = gimple_phi_arg_def (phi, e1->dest_idx); arg1 = gimple_phi_arg_def (phi, e2->dest_idx); - - /* Something is wrong if we cannot find the arguments in the PHI - node. */ gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); - - gphi *newphi; - if (single_pred_p (bb1) - && !diamond_p - && (newphi = factor_out_conditional_conversion (e1, e2, phi, - arg0, arg1, - cond_stmt))) - { - phi = newphi; - /* factor_out_conditional_conversion may create a new PHI in - BB2 and eliminate an existing PHI in BB2. Recompute values - that may be affected by that change. */ - arg0 = gimple_phi_arg_def (phi, e1->dest_idx); - arg1 = gimple_phi_arg_def (phi, e2->dest_idx); - gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); - } - - /* Do the replacement of conditional if it can be done. */ - if (!early_p - && !diamond_p - && two_value_replacement (bb, bb1, e2, phi, arg0, arg1)) - cfgchanged = true; - else if (!diamond_p - && match_simplify_replacement (bb, bb1, e1, e2, phi, - arg0, arg1, early_p)) - cfgchanged = true; - else if (!early_p - && !diamond_p - && single_pred_p (bb1) - && cond_removal_in_builtin_zero_pattern (bb, bb1, e1, e2, - phi, arg0, arg1)) - cfgchanged = true; - else if (minmax_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1, - diamond_p)) - cfgchanged = true; - else if (single_pred_p (bb1) - && !diamond_p - && spaceship_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) - cfgchanged = true; } + + /* Do the replacement of conditional if it can be done. */ + if (!early_p + && !diamond_p + && two_value_replacement (bb, bb1, e2, phi, arg0, arg1)) + cfgchanged = true; + else if (!diamond_p + && match_simplify_replacement (bb, bb1, e1, e2, phi, + arg0, arg1, early_p)) + cfgchanged = true; + else if (!early_p + && !diamond_p + && single_pred_p (bb1) + && cond_removal_in_builtin_zero_pattern (bb, bb1, e1, e2, + phi, arg0, arg1)) + cfgchanged = true; + else if (minmax_replacement (bb, bb1, bb2, e1, e2, phi, arg0, arg1, + diamond_p)) + cfgchanged = true; + else if (single_pred_p (bb1) + && !diamond_p + && spaceship_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) + cfgchanged = true; } free (bb_order);