From patchwork Mon May 1 16:37:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 89082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp46316vqo; Mon, 1 May 2023 09:38:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nsXCg+zUy3+0i9AO2Q0Rbp5pmL5wcvhGpYn2Lsr7NMcsE6mxnhqqDHNY9YDjZIqfr2o/x X-Received: by 2002:a17:907:9343:b0:960:ddba:e5c6 with SMTP id bv3-20020a170907934300b00960ddbae5c6mr12176112ejc.22.1682959081190; Mon, 01 May 2023 09:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682959081; cv=none; d=google.com; s=arc-20160816; b=l0lfKDsoOaDLCvfdLIQ/nri/+F745IDMQyz5HqywrAXHIiYaqmgk6d7Y1OPV26LJpH F8VUSe7Gywg4818WJ6D2lqjD1A2O2jYQoAh+64hR9LyJ09xLGmXeKc9ENeLGg/mUZ2Ga e3l2wjAA0/4K0VjrwaHnapmp5M9w1Y71g6WyRLjbVlm269gxd4agfu8CAYXaDO72rPWK nKupiYx7A6Cwvf5GL9CuqBEcNLTHOogXvUFZ/hewwqO0rt3VNNUe+18VxlcRSEqJip2D BfT+22uO7cKe6Abqr1oUKWiFp/wCBT1agVxxeb2vyah5JL/ffstdam3F7sbS7CblOru1 ovJw== 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=txF9SpFAstquBnfFFnMHfIMkMuh1qnftmhpNluODWdw=; b=t0eELxwP/kckrPl2/zYcqoCN8VqCtmy0k6lUzMZdkOUpOArbrLPVtOvPcF+i1rgK2p s26UtnppC8oHaNBPaQ78Wnie5OHOz2Eqel+mj8GezuQuUgC+92LNyIOODYi6PrvaSLe+ 4Lj0v5+nOpX1GT7t/GObN3j3kVxiisHEZ/P+FghACLhufBnTjBRkBFqZaPW6IhpzoC45 lr9soI/qJU7iqRPP5wVYeEW7JuHO484bWwkGn43W6IeG1Nq9lg2mFZk7oVWZDkxj3y3z 5Hph9ag0uNJjjHKkSwuWt4s+SjbDfBaBdY1gFvNOINq31hoGVHFlA6GYJPS8Xfpi/B1E dy2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KDoudEjV; 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 tl6-20020a170907c30600b0094ef947b269si18834411ejc.149.2023.05.01.09.38.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 09:38:01 -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=KDoudEjV; 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 CF3953858430 for ; Mon, 1 May 2023 16:37:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF3953858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682959079; bh=txF9SpFAstquBnfFFnMHfIMkMuh1qnftmhpNluODWdw=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=KDoudEjVEa0T3PtN+vKxWtIcV2Bw7e5K69gmaQjQF7TDNxh7asVXZrRo01a9GPS9w PQ5n1fe15UVeky1izrYjocGVH1NpS4YZECGu944KthzZlFENNWfqQu3vsVfRuKMm8l Qszl8d5/WIBefV5TA8QwXfKnnOtRiNNeZeqOx438= 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 806B93858D28 for ; Mon, 1 May 2023 16:37:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 806B93858D28 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 33UNOEQw006480 for ; Mon, 1 May 2023 09:37:11 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q90kry010-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 01 May 2023 09:37:11 -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; Mon, 1 May 2023 09:37:09 -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; Mon, 1 May 2023 09:37:09 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id 24FF23F7057; Mon, 1 May 2023 09:37:09 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] PHIOPT: Update comment about what the pass now does Date: Mon, 1 May 2023 09:37:00 -0700 Message-ID: <20230501163700.797083-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: tZ1qieWSOzt5IRvJPmsup020PfnoDRq1 X-Proofpoint-GUID: tZ1qieWSOzt5IRvJPmsup020PfnoDRq1 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-01_09,2023-04-27_01,2023-02-09_01 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SCC_5_SHORT_WORD_LINES, 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?1764710501545835262?= X-GMAIL-MSGID: =?utf-8?q?1764710501545835262?= I noticed I didn't update the comment about how the pass works after I initially added match_simplify_replacement. Anyways this updates the comment to be the current state of the pass. OK? gcc/ChangeLog: * tree-ssa-phiopt.cc: Update comment about how the transformation are implemented. --- gcc/tree-ssa-phiopt.cc | 67 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 147e8f186ce..47ca354fabe 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -3730,31 +3730,55 @@ gate_hoist_loads (void) } /* This pass tries to replaces an if-then-else block with an - assignment. We have four kinds of transformations. Some of these - transformations are also performed by the ifcvt RTL optimizer. + assignment. We have different kinds of transformations. + Some of these transformations are also performed by the ifcvt + RTL optimizer. - Conditional Replacement + PHI-OPT using Match-and-simplify infrastructure ----------------------- - This transformation, implemented in match_simplify_replacement, - replaces + The PHI-OPT pass will try to use match-and-simplify infrastructure + (gimple_simplify) to do transformations. This is implemented in + match_simplify_replacement. + The way it works is it replaces: bb0: if (cond) goto bb2; else goto bb1; bb1: bb2: - x = PHI <0 (bb1), 1 (bb0), ...>; + x = PHI ; - with + with a statement if it gets simplified from `cond ? b : a`. bb0: - x' = cond; - goto bb2; + x1 = cond ? b : a; bb2: - x = PHI ; + x = PHI ; + Bb1 might be removed as it becomes unreachable when doing the replacement. + Though bb1 does not have to be considered a forwarding basic block from bb0. + + Will try to see if `(!cond) ? a : b` gets simplified (iff !cond simplifies); + this is done not to have an explosion of patterns in match.pd. + Note bb1 does not need to be completely empty, it can contain + one statement which is known not to trap. - We remove bb1 as it becomes unreachable. This occurs often due to - gimplification of conditionals. + It also can handle the case where we have two forwarding bbs (diamond): + bb0: + if (cond) goto bb2; else goto bb1; + bb1: goto bb3; + bb2: goto bb3; + bb3: + x = PHI ; + And that is replaced with a statement if it is simplified + from `cond ? b : a`. + Again bb1 and bb2 does not have to be completely empty but + each can contain one statement which is known not to trap. + But in this case bb1/bb2 can only be forwarding basic blocks. + + This fully replaces the old "Conditional Replacement", + "ABS Replacement" transformations as they are now + implmeneted in match.pd. + Some parts of the "MIN/MAX Replacement" are re-implemented in match.pd. Value Replacement ----------------- @@ -3796,25 +3820,6 @@ gate_hoist_loads (void) t3 = t1 & t2; x = a; - ABS Replacement - --------------- - - This transformation, implemented in match_simplify_replacement, replaces - - bb0: - if (a >= 0) goto bb2; else goto bb1; - bb1: - x = -a; - bb2: - x = PHI ; - - with - - bb0: - x' = ABS_EXPR< a >; - bb2: - x = PHI ; - MIN/MAX Replacement -------------------