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