From patchwork Sun May 7 04:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 90816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1388568vqo; Sat, 6 May 2023 21:45:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jLCXP1n+8RoUIRJ2lZf9det8fw6/2btRbnJLJ3DM6XCyBioLm13Bao5qCJmqBn41xn5sS X-Received: by 2002:a17:907:94cf:b0:8b8:c06e:52d8 with SMTP id dn15-20020a17090794cf00b008b8c06e52d8mr6141425ejc.36.1683434728837; Sat, 06 May 2023 21:45:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683434728; cv=none; d=google.com; s=arc-20160816; b=uF9bdU1vtmsBFX2IgvTedy799YJT/bwJhmyB3noh/L+dYAta6aIk12/1itp1ytNYDV vfaHdMRgTn3VTaH8J0Mvsnw10pjvzix0m0pTA8brqsB8T/sQKHAoqeud9EEO6ygP+N4I +CZ76hhJADArzWxpobA6hszsZg14jDbUH6ycVeoWv1crFor4ufRk3he2Lumq3XOJXpbl dKGD/r/tfmfcXYTyLda3aiMH9o1fx0QIRtKgTqP/rQw73MJulatQ2lYcjNPsRRTRVAg8 ahlViUn6/Gw35DrZFMxWxga0mlySbftDriZZXwSvDHgvFMkNUknUU1skbXx9DM1XxNk2 yB0A== 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=uXJGM4YLeNzkLeHqSEZS0DvCvq8qfUDQ+OryTszePQc=; b=j/sEyHzd2HhVoSLj88iO1nI1/r7R8WiUeo2ExBkrh2Lrn9Jtmy5nd6Vv26sZx12cvN 1gAInQsJk/gavpJxabmqH+nycGaP/tAF3x3cU5uEO9+s3ohq9/7LO4Gthy54ahoVOz99 Z2IAaOrpJ/6q4BEazdcSq/7dtjskderM9xqOvFztbXC+oSmgWY3xbb1kKiYXZRLl0ULv jH30so0HP7YVs2x2/lpJZOAcPr5jZD4AUgo/0gxy+uC93j8+k7VXaJcInE5BjWTN/o9a P8ERs2bjkYbOq6ivQTGjxJ/IJcDM3bmJ4vyu4kIBs1KQtDLsaiEzCD70UTkQ2WKWfYIk OtIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vHj54QaZ; 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 c1-20020a17090603c100b009598c12f792si3785926eja.1039.2023.05.06.21.45.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 21:45:28 -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=vHj54QaZ; 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 1C5AA3858416 for ; Sun, 7 May 2023 04:45:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C5AA3858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683434727; bh=uXJGM4YLeNzkLeHqSEZS0DvCvq8qfUDQ+OryTszePQc=; 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=vHj54QaZr2S6Cw/3Ly8suAZgXJfGslQQkuTMi/j5iKL71NC+U70yKJiVQNZ1aAy2N 9mMQ0HOzVYWkGncUD6SS/IFwWUVx2JqrY5z5cwxkUZYCtk+AUsBkzdzLGAraMZCrPT ZyKYmHpy9s6E7aHYho5ju1x+hNcrdsUjIEU3sO+g= 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 BDCDF3858D35 for ; Sun, 7 May 2023 04:43:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDCDF3858D35 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 3474RIRJ011589 for ; Sat, 6 May 2023 21:43:43 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qdm8t25qr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 06 May 2023 21:43:43 -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, 6 May 2023 21:43:42 -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, 6 May 2023 21:43:42 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 9E67B626A71; Sat, 6 May 2023 21:43:41 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/3] PHIOPT: Loop over calling factor_out_conditional_conversion Date: Sat, 6 May 2023 21:43:31 -0700 Message-ID: <20230507044332.1122612-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230507044332.1122612-1-apinski@marvell.com> References: <20230507044332.1122612-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: Rn2OAjCc5yB7qwVXPo0eAzW-lTBr4xD8 X-Proofpoint-ORIG-GUID: Rn2OAjCc5yB7qwVXPo0eAzW-lTBr4xD8 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-07_02,2023-05-05_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?1765209254076443593?= X-GMAIL-MSGID: =?utf-8?q?1765209254076443593?= After adding diamond shaped bb support to factor_out_conditional_conversion, we can get a case where we have two conversions that needs factored out and then would have another phiopt happen. An example is: ``` static inline unsigned long long g(int t) { unsigned t1 = t; return t1; } unsigned long long f(int c, int d, int e) { unsigned long long t; if (c > d) t = g(c); else t = g(d); return t; } ``` In this case we should get a MAX_EXPR in phiopt1 with two casts. Before this patch, we would just factor out the outer cast and then wait till phiopt2 to factor out the inner cast. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (pass_phiopt::execute): Loop over factor_out_conditional_conversion. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-17.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/minmax-17.c | 21 ++++++++++++++++++ gcc/tree-ssa-phiopt.cc | 27 +++++++++++++---------- 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/minmax-17.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-17.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-17.c new file mode 100644 index 00000000000..bd737e6b4cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-17.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-phiopt1-details" } */ + +static inline unsigned long long g(int t) +{ + unsigned t1 = t; + return t1; +} +unsigned long long test_max(int c, int d, int e) +{ + unsigned long long t; + if (c > d) + t = g(c); + else + t = g(d); + return t; +} + +/* We should figure out that test_max has an MAX_EXPR in it. */ +/* { dg-final { scan-tree-dump " = MAX_EXPR" "phiopt1"} } */ +/* { dg-final { scan-tree-dump-times "changed to factor conversion out from" 2 "phiopt1"} } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 41fea78dc8d..7fe088b13ff 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -4085,20 +4085,23 @@ pass_phiopt::execute (function *) node. */ gcc_assert (arg0 != NULL_TREE && arg1 != NULL_TREE); - gphi *newphi; if (single_pred_p (bb1) - && EDGE_COUNT (merge->preds) == 2 - && (newphi = factor_out_conditional_conversion (e1, e2, phi, - arg0, arg1, - cond_stmt))) + && EDGE_COUNT (merge->preds) == 2) { - 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); + gphi *newphi = phi; + while (newphi) + { + 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); + newphi = factor_out_conditional_conversion (e1, e2, phi, + arg0, arg1, + cond_stmt); + } } /* Do the replacement of conditional if it can be done. */