From patchwork Sat Apr 22 22:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1911394vqo; Sat, 22 Apr 2023 15:11:18 -0700 (PDT) X-Google-Smtp-Source: AKy350a21WH2/pVk09H4Wut/DabcAa4Km3pm5IIDQYt8qQwFsMlt0PkQ+aEwapqRKNernINNFfUv X-Received: by 2002:a17:906:49da:b0:94e:8556:f01c with SMTP id w26-20020a17090649da00b0094e8556f01cmr5166505ejv.57.1682201478378; Sat, 22 Apr 2023 15:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201478; cv=none; d=google.com; s=arc-20160816; b=q1BF/uIizJSUpYslW1MVA1NPzJuxHIh0ftoQGcojPlZ9VvpRoe3NvdtHm6UgWO6SJ2 kLbKbX3N4+xzpIC94LTfrGYXLYh8LJy3KVEO+lbNAxvan8CCImrOkyiK2LqonHAEIZoB Acp78MKmh3LDteAuqsiu/pG0+J2RHKyVYsd/PsT0wDHNr/GeJ6XmV5gpZ5EtwAvZdIkA XitjlqbnZ7TUslLtN7tfQ5h5jT/LNBMQaqCX1IPsWiIY7/Rn+d+vSRbW+JT3BO6ZqLQx w1fCfr6ZCv2SegtqQKj09LOIIjtEz8IlFikpLa8Y2ZL7aRoNGtK/zet9FMbOtbzfwM/2 71eA== 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=t1tkkM7l+3H6sUhTxjiOg+MvroIu15OaF55mekNOJKw=; b=W/ZE1oyxfIXPrLA9CjnQmyHwKGu4mAkCFXbZIf5ZzDk+TWD2q/QCqYeHVLvSFqs46f XXYZuGWyfVbYTPte3FcjEQ1jyZWONSnTdmTJRR3Tm6rFEH9UH/bc1/9yRzG26WJ3/bhw yJz6J0ck7e4N+YAhfYZa2ic8K3eL3Mn7v+0w/vEtJEkVlI3BkIE9d86nXIvgO6NghOQ9 p42Ijf0fZUc1+JEmVw77P2Y/0IDmmKb2vYsfkkkHTreZX1iTrGT6qWlCw2TU9iwGJceT Bl2DwlCGo7s+XRJrTFZ9erJpYEZgebwaG7/Fu9EIe4ZAX3ncvRb1DthkydhRex334aSA lIkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="aysG/kyI"; 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 d4-20020aa7c1c4000000b00506a69d4956si5668362edp.149.2023.04.22.15.11.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:11:18 -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="aysG/kyI"; 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 DE0903853824 for ; Sat, 22 Apr 2023 22:10:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE0903853824 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201429; bh=t1tkkM7l+3H6sUhTxjiOg+MvroIu15OaF55mekNOJKw=; 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=aysG/kyIHU22eBmo5fFIakpyOOPximGKn/DQjWBolIkloZjhK7BKozXAV4T3uu/Dp KVLji4jyqW4weFl2Savaj2xclIE3xgMjwRyDVfoXWQwIFPFQ/I0n5rx+eBXlbTvR38 HmOQQ+mPRKZKT3EGRSLOBSuzPsh4grMAaSnT4Ioo= 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 AE2FB3858C78 for ; Sat, 22 Apr 2023 22:09:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE2FB3858C78 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 33MLGWq9006595 for ; Sat, 22 Apr 2023 15:09:43 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhp9y-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:43 -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; Sat, 22 Apr 2023 15:09: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; Sat, 22 Apr 2023 15:09:30 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 30D973F7090; Sat, 22 Apr 2023 15:09:30 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/6] PHIOPT: Move check on diamond bb to tree_ssa_phiopt_worker from minmax_replacement Date: Sat, 22 Apr 2023 15:09:16 -0700 Message-ID: <20230422220921.452264-2-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: eSDCWGaBSgPPCoGW8yrAfTXPgyxZrqgy X-Proofpoint-GUID: eSDCWGaBSgPPCoGW8yrAfTXPgyxZrqgy 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.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?1763916097495565442?= X-GMAIL-MSGID: =?utf-8?q?1763916097495565442?= This moves the check to make sure on the diamond shaped form bbs that the the two middle bbs are only for that diamond shaped form earlier in the shared code. Also remove the redundant check for single_succ_p since that was already done before hand. The next patch will simplify the code even further and remove redundant checks. gcc/ChangeLog: * tree-ssa-phiopt.cc (tree_ssa_phiopt_worker): Move the diamond form check from ... (minmax_replacement): Here. --- gcc/tree-ssa-phiopt.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index d886c88215b..296ba646e62 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -220,6 +220,14 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) continue; } + if (diamond_p) + { + if (!single_pred_p (bb1) + || !single_pred_p (bb2) + || !single_succ_p (bb2)) + continue; + } + if (do_store_elim && !diamond_p) { /* Also make sure that bb1 only have one predecessor and that it @@ -2032,12 +2040,6 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_ tree alt_lhs, alt_op0, alt_op1; bool invert = false; - if (!single_pred_p (middle_bb) - || !single_pred_p (alt_middle_bb) - || !single_succ_p (middle_bb) - || !single_succ_p (alt_middle_bb)) - return false; - /* When THREEWAY_P then e1 will point to the edge of the final transition from middle-bb to end. */ if (true_edge == e0) 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); From patchwork Sat Apr 22 22:09:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1912082vqo; Sat, 22 Apr 2023 15:13:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YoGouAtPtfCHthx7MYawa1M3lyyd0z9L4XyKT4cgiPMvKVW301uN5969ghuAP341plWiBT X-Received: by 2002:aa7:c592:0:b0:508:3f08:ea0f with SMTP id g18-20020aa7c592000000b005083f08ea0fmr8337696edq.28.1682201606841; Sat, 22 Apr 2023 15:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201606; cv=none; d=google.com; s=arc-20160816; b=ZUYLu69vYZhabmQ0+l0OqrmQZ80Y+klbIgR85ZD0qoUwi9YLzfKuy+qsrmO2OlEKNY JeF1yg/TDt5PicFiiHydJF3qBRiKyPNkBrpeXIMIDsamUUYmWDCiSAJo666YMA4NlIte /6kT2tDv3VagkJhfZ88LfbdUUmO0MqPfoANGETb3/+PWVBvGksPWQwWT4vd2lpLSohxN sfmIqr+nW2A/hhZ5nue1Uximw+pEQJFCtw8FHX+Q8AW4G+1tvyy4slsonR7rjATMRpDn DNrW3scbFDGZiM/XCf49WgniAvDX8OGFJDsm66XNyr9i+kV5ml61tP+Zcghxg6ED2iVZ FMHQ== 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=U0UxIP8whi6dKflFbuI4GiwBkzqkEh9yppBHwYEuruk=; b=pJ8oa4D6D7em3AhvmzM7/WzUkjfpnoDpowQPwud5evGbCSZNV/LnbPYuFgJ5C45juY W4vysUFNMO7j1H1SHOjzir6pCrPrq/VKsQgQp8KqQcZiDnQDp9q4Vl9P6APhwx2TR/9A 9I23xYXfKDVN1T24XEWxoEZ6eoSquHoEPeV6EQ44RUnxSx4oz0S4Q62jdTcD4c84+nF+ KHdH8P6w7pLtvhVu4lLmzp5kwqvmo4P6MF1JLy4K1Vp+6ZzRY4iYoIkfrIc6z7qHXcu9 uKrHNmjPNUPtI+T9nu23rjyj+Vc2IRuQzRzwWmTioiF2Bn0uBdO02zYU1/AdU5WLWoxG vxKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pcV6Oz73; 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 d23-20020a50fb17000000b005068cb68ed6si6140600edq.630.2023.04.22.15.13.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:13:26 -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=pcV6Oz73; 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 54055385558A for ; Sat, 22 Apr 2023 22:11:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54055385558A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201495; bh=U0UxIP8whi6dKflFbuI4GiwBkzqkEh9yppBHwYEuruk=; 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=pcV6Oz73chsOkzKSg4wdm8cR8U4WMP5DgSLaifcVJfAn5i0KBVDWgEXDySfFlLCxL G8w1Qpa4tymfMFZrcpGGbsdQpBt2nPvSOlSi1DgTwZ9/1294O9aGeOp/kazWT2O6HI QLnA2mA4UMf4C5nh8gymArQzTA4ixtq9hLwiAJ/U= 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 251CF3858C36 for ; Sat, 22 Apr 2023 22:09:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 251CF3858C36 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 33MLGWqB006595 for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhp9y-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:44 -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; 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 202AE3F708D; Sat, 22 Apr 2023 15:09:31 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 3/6] PHIOPT: Allow other diamond uses when do_hoist_loads is true Date: Sat, 22 Apr 2023 15:09:18 -0700 Message-ID: <20230422220921.452264-4-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: yl72xDheU-o7YLmrIiCmPHiM07yQpzD- X-Proofpoint-GUID: yl72xDheU-o7YLmrIiCmPHiM07yQpzD- 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.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?1763916232318621394?= X-GMAIL-MSGID: =?utf-8?q?1763916232318621394?= While working on adding diamond shaped form to match-and-simplify phiopt, I Noticed that we would not reach there if do_hoist_loads was true. In the original code before the cleanups it was not obvious why but after I finished the cleanups, it was just a matter of removing a continue and that is what this patch does. This just happens also to fix a bug report that I noticed too. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: PR tree-optimize/68894 * tree-ssa-phiopt.cc (tree_ssa_phiopt_worker): Remove the continue for the do_hoist_loads diamond case. --- gcc/tree-ssa-phiopt.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 05f19825ce9..e4062f33efa 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -243,10 +243,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) 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; - } + hoist_adjacent_loads (bb, bb1, bb2, bb3); } gimple_stmt_iterator gsi; From patchwork Sat Apr 22 22:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1911508vqo; Sat, 22 Apr 2023 15:11:35 -0700 (PDT) X-Google-Smtp-Source: AKy350Zpxmo3u3WbHq0UmN6VFnQBOTNcoXmpcT0VHCVo11DOcz7pBxCIzX8P78RCn/6LapAD91um X-Received: by 2002:a17:906:a18c:b0:94a:6cc0:aa09 with SMTP id s12-20020a170906a18c00b0094a6cc0aa09mr6437930ejy.9.1682201495186; Sat, 22 Apr 2023 15:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201495; cv=none; d=google.com; s=arc-20160816; b=S3h/HcGVA8zkXJrOki3SSlSGw+MLUrGgfjuH+8p83u0Uy7boAey34c2SYnJGY+EPMb oKBQ0stYdIa3MLYuAJudJkusX5+0L/7O9FDjoYiWPIyd5WDTnOvfGsne86mgL8WS7H7K ckitHqHmbaeVcH9VlVxOXkwqZGSLMkphUy7IklF6T4yjqYzfL1dlLXzVI9lTVSXZ6PmY PZFrApiAgrw+HKki85dcRaWsTP7Vc4zdET04hFb/5Ex2n1yW7gYfSvgOH+O+0FIvrpBa Oc81m8HS/IpWj6KqisUIVx2rdfR9cQNEQk+ph8nU3EZHM8TLj9T7G1cnvaT/U8GzJOOB LTUw== 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=XlZL+OnzpbOTdT/mHQpxS4NTR+lCyHVgCUoMfllm1N4=; b=b7ZT8T12igBN45+3k72EErFqx3/olvAO+x7Mq/Zm46KRuAdHp0FD34CLk9r2EJXxK1 U3lcCDFm+ud/XQGlgCxA+CYM8g8Uo2Hf3ufpamYlpXeeM6vQm8/XTq6mhtPvN4fjobe4 bukF/jRwbA4aTFPiJ0tCB2f/AviU5vWyDKhZTOYILDUw3jdePO1o7Dj2BEQh6eQIU2Y6 vKlPF85n8MoNe8i3Tdh1jUSKEwkyG0COg/dFG7n2EPSWw8TfEYweNwkV25VXnxskilcy SuMwWsh1O1ewqb13CjyC76qGILAXGeafvJXL2ftBLAYXVzI3ZhDH9Oajhf6Awr4G4Ur9 l9nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FibGe8bl; 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 k22-20020a1709063e1600b009571aca2cafsi2870573eji.518.2023.04.22.15.11.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:11: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=FibGe8bl; 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 09EEB385558A for ; Sat, 22 Apr 2023 22:10:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09EEB385558A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201437; bh=XlZL+OnzpbOTdT/mHQpxS4NTR+lCyHVgCUoMfllm1N4=; 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=FibGe8blHP4c6KlTEMtetp+KMTN6OdAr+66ns2yi1vZjQs6gDvat4oC31NIEO4qGU ghNytXbVygDchqNM/qJGPMyHaFPReq5aFBU9/kVXKrUlXvz5l74/p69CV0ELgThrxS mtsyMg/rIvV/hAfD4ypgR//qxGbyoo5V6/7uXN8c= 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 CA9CB3858C2B for ; Sat, 22 Apr 2023 22:09:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA9CB3858C2B 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 33MLGWqA006595 for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhpa0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:43 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) 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-EXCH01.marvell.com (10.69.176.38) 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 959493F7090; Sat, 22 Apr 2023 15:09:31 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 4/6] PHIOPT: Factor out some code from match_simplify_replacement Date: Sat, 22 Apr 2023 15:09:19 -0700 Message-ID: <20230422220921.452264-5-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: 5CY9ng6M-8J8qjBTkBCu53-sXiasQL-F X-Proofpoint-GUID: 5CY9ng6M-8J8qjBTkBCu53-sXiasQL-F 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?1763916114924979893?= X-GMAIL-MSGID: =?utf-8?q?1763916114924979893?= This factors out the code checking if we have an empty bb or one statement that feeds into the phi so it can be used when adding diamond shaped bb form to match_simplify_replacement in the next patch. Also allows for some improvements in the next patches too. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): New function. (match_simplify_replacement): Call empty_bb_or_one_feeding_into_p instead of doing it inline. --- gcc/tree-ssa-phiopt.cc | 106 ++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 44 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index e4062f33efa..cb4d8788b56 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -940,6 +940,66 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt, return NULL; } +/* empty_bb_or_one_feeding_into_p returns true if bb was empty basic block + or it has one cheap preparation statement that feeds into the PHI + statement and it sets STMT to that statement. */ +static bool +empty_bb_or_one_feeding_into_p (basic_block bb, + gimple *phi, + gimple *&stmt) +{ + stmt = nullptr; + gimple *stmt_to_move = nullptr; + + if (empty_block_p (bb)) + return true; + + if (!single_pred_p (bb)) + return false; + + /* The middle bb cannot have phi nodes as we don't + move those assignments yet. */ + if (!gimple_seq_empty_p (phi_nodes (bb))) + return false; + + stmt_to_move = last_and_only_stmt (bb); + if (!stmt_to_move) + return false; + + if (gimple_vuse (stmt_to_move)) + return false; + + if (gimple_could_trap_p (stmt_to_move) + || gimple_has_side_effects (stmt_to_move)) + return false; + + if (gimple_uses_undefined_value_p (stmt_to_move)) + return false; + + /* Allow assignments and not no calls. + As const calls don't match any of the above, yet they could + still have some side-effects - they could contain + gimple_could_trap_p statements, like floating point + exceptions or integer division by zero. See PR70586. + FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p + should handle this. */ + if (!is_gimple_assign (stmt_to_move)) + return false; + + tree lhs = gimple_assign_lhs (stmt_to_move); + gimple *use_stmt; + use_operand_p use_p; + + /* Allow only a statement which feeds into the other stmt. */ + if (!lhs || TREE_CODE (lhs) != SSA_NAME + || !single_imm_use (lhs, &use_p, &use_stmt) + || use_stmt != phi) + return false; + + stmt = stmt_to_move; + return true; +} + /* The function match_simplify_replacement does the main work of doing the replacement using match and simplify. Return true if the replacement is done. Otherwise return false. @@ -965,50 +1025,8 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, /* If the basic block only has a cheap preparation statement, allow it and move it once the transformation is done. */ - if (!empty_block_p (middle_bb)) - { - if (!single_pred_p (middle_bb)) - return false; - - /* The middle bb cannot have phi nodes as we don't - move those assignments yet. */ - if (!gimple_seq_empty_p (phi_nodes (middle_bb))) - return false; - - stmt_to_move = last_and_only_stmt (middle_bb); - if (!stmt_to_move) - return false; - - if (gimple_vuse (stmt_to_move)) - return false; - - if (gimple_could_trap_p (stmt_to_move) - || gimple_has_side_effects (stmt_to_move)) - return false; - - if (gimple_uses_undefined_value_p (stmt_to_move)) - return false; - - /* Allow assignments and not no calls. - As const calls don't match any of the above, yet they could - still have some side-effects - they could contain - gimple_could_trap_p statements, like floating point - exceptions or integer division by zero. See PR70586. - FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p - should handle this. */ - if (!is_gimple_assign (stmt_to_move)) - return false; - - tree lhs = gimple_assign_lhs (stmt_to_move); - gimple *use_stmt; - use_operand_p use_p; - - /* Allow only a statement which feeds into the phi. */ - if (!lhs || TREE_CODE (lhs) != SSA_NAME - || !single_imm_use (lhs, &use_p, &use_stmt) - || use_stmt != phi) - return false; - } + if (!empty_bb_or_one_feeding_into_p (middle_bb, phi, stmt_to_move)) + return false; /* At this point we know we have a GIMPLE_COND with two successors. One successor is BB, the other successor is an empty block which From patchwork Sat Apr 22 22:09:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1911524vqo; Sat, 22 Apr 2023 15:11:38 -0700 (PDT) X-Google-Smtp-Source: AKy350bT9bQNpQoFag16DSfyFZK4/PRjwhbE79wHBH13aLh9r9usZgiiD1pb09Xklw5VfnYjj02x X-Received: by 2002:a17:906:cb9b:b0:953:1f45:3ced with SMTP id mf27-20020a170906cb9b00b009531f453cedmr6192576ejb.8.1682201498326; Sat, 22 Apr 2023 15:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201498; cv=none; d=google.com; s=arc-20160816; b=04sfvijZkcnDtthcIo3qxIfupIcAAtyamxL8XfAu83Ep0cn6a1600CIJROOVKEUTb8 6Hnm8b8AHLcU4sYHiEJpO0i7L7ithqDTOP7FrtEVeFCAPb8+FvqYydcR0skXJEr4z00w VTs5V/omzo1XXCELu9uQL8ffZsAFXQMP8CI/fxuQ+tIcBv0SOfkjKSGidrxP/nqk6xk4 Inb2hUeb1OXEIaCYUqGmUwvgSjKEooATAF4yLvQH3NBHq7sN0+eso9xlKEmZVcZvTF7M 18qct/+gNpcGTalZreApRLLfSPcKYxPMiIEjh9DoED+Jyxv7vq35acbCWLHeJn/tL6DW Gyrw== 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=70yBC6Tngm2NSXLKMIoxaw8cEQ6mozev4dYAcDbhjWM=; b=TjvR7rcZmS8N48brUEOpA0C08UifpJwaCKAzo7xfu24F+KSKHOvKZ66+rYdVb3Vt16 NceHY/WgLGzd85eR5FF9D1hvSDIY5ieSAG0LdpPPIAt9T5Yhli/eKpi+mA6F1NG28twN UJone0ei4w336vX7UMr4IwbAwG0Ky7zVs0b/vb09scDI4HWSW+gGQYF0xKS7YkiHT1Ap yp2hrgXCk+qLWRElhojwlRrc6mRkW7b1HlCY58dQFavoQVtMUAy7INj1bVId3WMQ9/Ix hMEHGsLYXQNAbQuWc+Lqcaiw7jjQwhr3MsawBJxF/+rlw89D8i6caCF2hID87d5h+OhZ Q1fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FkDbRag+; 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 gv12-20020a170906f10c00b0094f3a2fa2cfsi5645156ejb.146.2023.04.22.15.11.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:11:38 -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=FkDbRag+; 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 554B63851C15 for ; Sat, 22 Apr 2023 22:10:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554B63851C15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201438; bh=70yBC6Tngm2NSXLKMIoxaw8cEQ6mozev4dYAcDbhjWM=; 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=FkDbRag+on9quk5/lb++tMyJDxr6skD2Qad8LDII4umIMkujksTeRkrLY6EGPL6NJ XJHamCMol2Gersr8+5Uz/w3PAC/I7IGQp/HHpOOEe25xxU9CcwVIDGSMCYzjmlhQa3 mEEdVVUUo+xyLj4Q5SrFunCXmsCVzVUA7pUiQvyk= 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 8D7C63858409 for ; Sat, 22 Apr 2023 22:09:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D7C63858409 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 33MLGWqD006595 for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhp9y-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:44 -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; Sat, 22 Apr 2023 15:09:32 -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; Sat, 22 Apr 2023 15:09:32 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 0FBD03F709B; Sat, 22 Apr 2023 15:09:31 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 5/6] PHIOPT: Ignore predicates for match-and-simplify phi-opt Date: Sat, 22 Apr 2023 15:09:20 -0700 Message-ID: <20230422220921.452264-6-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: miUDq592cyj5aOHxh6RxQN6-EiZT6nW3 X-Proofpoint-GUID: miUDq592cyj5aOHxh6RxQN6-EiZT6nW3 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.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?1763916118585248123?= X-GMAIL-MSGID: =?utf-8?q?1763916118585248123?= This fixes a missed optimization where early phi-opt would not work when there was predicates. The easiest fix is to change empty_bb_or_one_feeding_into_p to ignore those statements while checking for only feeding statement. Note phi-opt-23.c and phi-opt-24.c still fail as we don't handle diamond form in match_and_simplify phiopt yet. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): Instead of calling last_and_only_stmt, look for the last statement manually. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ssa-ifcombine-13.c: Add -fno-ssa-phiopt. --- .../gcc.dg/tree-ssa/ssa-ifcombine-13.c | 4 +++- gcc/tree-ssa-phiopt.cc | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c index 425eb3d6481..7976544c79b 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c @@ -1,5 +1,7 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1" } */ +/* Disable phi-opt as it is no longer confused by predicate which had allowed ifcombine to work in the past. + Note this testcase is about ifcombine rather than phi-opt. */ +/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1 -fno-ssa-phiopt" } */ _Bool f1(_Bool a, _Bool b) { diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index cb4d8788b56..ffd6a4e6f35 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -962,9 +962,27 @@ empty_bb_or_one_feeding_into_p (basic_block bb, if (!gimple_seq_empty_p (phi_nodes (bb))) return false; - stmt_to_move = last_and_only_stmt (bb); + gimple_stmt_iterator gsi; + + gsi = gsi_start_nondebug_after_labels_bb (bb); + while (!gsi_end_p (gsi)) + { + gimple *s = gsi_stmt (gsi); + gsi_next_nondebug (&gsi); + /* Skip over Predict and nop statements. */ + if (gimple_code (s) == GIMPLE_PREDICT + || gimple_code (s) == GIMPLE_NOP) + continue; + /* If there is more one statement return false. */ + if (stmt_to_move) + return false; + stmt_to_move = s; + } + + /* The only statement here was a Predict or a nop statement + so return true. */ if (!stmt_to_move) - return false; + return true; if (gimple_vuse (stmt_to_move)) return false; From patchwork Sat Apr 22 22:09:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1912111vqo; Sat, 22 Apr 2023 15:13:30 -0700 (PDT) X-Google-Smtp-Source: AKy350YgQcCo9q7+AUjf4rBFvf2VmGDfNWQfcfg59F9XniSra5qH1qNq7uzqNIuqZN5elPfBH2f3 X-Received: by 2002:a17:907:961d:b0:94a:653b:ba41 with SMTP id gb29-20020a170907961d00b0094a653bba41mr5980285ejc.15.1682201609979; Sat, 22 Apr 2023 15:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201609; cv=none; d=google.com; s=arc-20160816; b=aBH3TRsHPzyXI14iSP9BpywoXJN3vdvaW8qLqaFN+BXRbAcPkX+mcS4bT48eQHs1Dk iT8Dvg9qcmKQI+DsLVOFp3JRa1FN7XlIQKFnE6YN/CnSXZQ4nzaGvR1SW4svX8zd11IP a2OdaMyw9sAH+dqmJ+leg7mLCde1copQ8XFVZA1DA1Cugff6Klr8CHeT4oEwf14PRQHc kGeJeHqUilvoPkZFz90eKH8C0mDs9NgrPciNaXu6exAOcD78/30g5L3lBr3Q4cBlRQyX Ylzu9NXd7YhRTfQyozin1bVzu3Smpk3ISYUBZ7hN1mgqw/E6LQFnRzKc5k3Pjci4kjMh I71g== 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=AHYmZ7XMm8PvDzUN0rS6zIob1x1sLFjSiveAtU8otto=; b=UOL9euebAXfe2ryz25ufBFKzcQ0qxRwvPV4WxcBa0UjzC0Iqvzvn4Iqi/Dm91T5vER alS/jUHETFpQnbmiPtMc8MQYl+xpn/ce9nCUlfUOD+yA1rv8Xkgt3Vnj0GMiRHZF+wVx Gs5yqHaKM5+tahykU1T7k/YDmC4frvRLEF7TobQq2GRHht8GHkZikWM+OWDbnk/83Yhg PytiJIqblCptgoJpzR+fHrvFtQLkAywOAraFq7Rt3mq2YpjmfBzz3jNInWYk1HeFXqzN Sv8FXkam7c7QnM1S+zDA+Sp/BDy52WLa7VgN2HUJzr9LXDpOf0fqIIFZVg3t/HlOwjB9 cRFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DppP1v5J; 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 l20-20020a1709065a9400b0094f9cd7adf3si2608732ejq.1008.2023.04.22.15.13.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:13:29 -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=DppP1v5J; 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 CD47E3834691 for ; Sat, 22 Apr 2023 22:11:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD47E3834691 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201496; bh=AHYmZ7XMm8PvDzUN0rS6zIob1x1sLFjSiveAtU8otto=; 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=DppP1v5Jvqm/YsCrKgsKUh0vXl4sgU63c2fSVeAzCFnj6vlS91Xe212ygJTor7CNg kBuCnoc07dY38ktTUVW3zvaaBHEny7ZrEQ0zFLqtzcLDGjQ2Dgbth4xsiIK9Vgtiah +wx3T/8PWAiGw9sY9Lv2YW2ocrp/puNkBA9dxBEA= 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 4661E3858401 for ; Sat, 22 Apr 2023 22:09:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4661E3858401 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 33MLGWqC006595 for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhpa0-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:44 -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:32 -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:32 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 7F9613F708D; Sat, 22 Apr 2023 15:09:32 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 6/6] PHIOPT: Add support for diamond shaped bb to match_simplify_replacement Date: Sat, 22 Apr 2023 15:09:21 -0700 Message-ID: <20230422220921.452264-7-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: zgGlF2fdLttvt9pGSku5Dk8SlJ3FKoIZ X-Proofpoint-GUID: zgGlF2fdLttvt9pGSku5Dk8SlJ3FKoIZ 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?1763916235229599012?= X-GMAIL-MSGID: =?utf-8?q?1763916235229599012?= This adds diamond shaped form of basic blocks to match_simplify_replacement. This is the patch is the start of removing/moving all of what minmax_replacement does to match.pd to reduce the code duplication. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note phi-opt-{23,24}.c testcase had an incorrect xfail as there should have been 2 if still because f4/f5 would not be transformed as -ABS is not allowable during early phi-opt. gcc/ChangeLog: * tree-ssa-phiopt.cc (match_simplify_replacement): Add new arguments and support diamond shaped basic block form. (tree_ssa_phiopt_worker): Update call to match_simplify_replacement gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-23.c: Update testcase. * gcc.dg/tree-ssa/phi-opt-24.c: Likewise. --- gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c | 4 +-- gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c | 4 +-- gcc/tree-ssa-phiopt.cc | 37 ++++++++++++++++++---- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c index ff658cd16a7..86aab955d5e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c @@ -38,7 +38,7 @@ int f5(int A) return -A; } -/* These should be optimized in phiopt1 but is confused by predicts. */ -/* { dg-final { scan-tree-dump-not "if" "phiopt1" { xfail *-*-* } } } */ +/* f4 and f5 are not allowed to be optimized in early phi-opt. */ +/* { dg-final { scan-tree-dump-times "if" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-not "if" "phiopt2" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c index eb89decb4bf..bd8308efa0e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c @@ -38,7 +38,7 @@ float f5(float A) return -A; } -/* These should be optimized in phiopt1 but is confused by predicts. */ -/* { dg-final { scan-tree-dump-not "if" "phiopt1" { xfail *-*-* } } } */ +/* f4 and f5 are not allowed to be optimized in early phi-opt. */ +/* { dg-final { scan-tree-dump-times "if" 2 "phiopt1" } } */ /* { dg-final { scan-tree-dump-not "if" "phiopt2" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index ffd6a4e6f35..757e44692ed 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -57,8 +57,8 @@ along with GCC; see the file COPYING3. If not see static bool two_value_replacement (basic_block, basic_block, edge, gphi *, tree, tree); -static bool match_simplify_replacement (basic_block, basic_block, - edge, edge, gphi *, tree, tree, bool); +static bool match_simplify_replacement (basic_block, basic_block, basic_block, + edge, edge, gphi *, tree, tree, bool, bool); static gphi *factor_out_conditional_conversion (edge, edge, gphi *, tree, tree, gimple *); static int value_replacement (basic_block, basic_block, @@ -304,9 +304,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool 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)) + else if (match_simplify_replacement (bb, bb1, bb2, e1, e2, phi, + arg0, arg1, early_p, diamond_p)) cfgchanged = true; else if (!early_p && !diamond_p @@ -1026,8 +1025,10 @@ empty_bb_or_one_feeding_into_p (basic_block bb, static bool match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, + basic_block middle_bb_alt, edge e0, edge e1, gphi *phi, - tree arg0, tree arg1, bool early_p) + tree arg0, tree arg1, bool early_p, + bool threeway_p) { gimple *stmt; gimple_stmt_iterator gsi; @@ -1035,6 +1036,7 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, gimple_seq seq = NULL; tree result; gimple *stmt_to_move = NULL; + gimple *stmt_to_move_alt = NULL; auto_bitmap inserted_exprs; /* Special case A ? B : B as this will always simplify to B. */ @@ -1046,6 +1048,12 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, if (!empty_bb_or_one_feeding_into_p (middle_bb, phi, stmt_to_move)) return false; + if (threeway_p + && middle_bb != middle_bb_alt + && !empty_bb_or_one_feeding_into_p (middle_bb_alt, phi, + stmt_to_move_alt)) + return false; + /* At this point we know we have a GIMPLE_COND with two successors. One successor is BB, the other successor is an empty block which falls through into BB. @@ -1110,6 +1118,23 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, reset_flow_sensitive_info (name); } + if (stmt_to_move_alt) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "statement un-sinked:\n"); + print_gimple_stmt (dump_file, stmt_to_move_alt, 0, + TDF_VOPS|TDF_MEMSYMS); + } + + tree name = gimple_get_lhs (stmt_to_move_alt); + // Mark the name to be renamed if there is one. + bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name)); + gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt_to_move_alt); + gsi_move_before (&gsi1, &gsi); + reset_flow_sensitive_info (name); + } + replace_phi_edge_with_variable (cond_bb, e1, phi, result, inserted_exprs); /* Add Statistic here even though replace_phi_edge_with_variable already