From patchwork Sun May 7 04:50: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: 90819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1399163vqo; Sat, 6 May 2023 22:22:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7n3a07EUT1W5HmEwVcddD0GFvPd1RBZqwlcdKaB6Op2P45a5zqatZ9xNJMonRZ6z0+YtvU X-Received: by 2002:a17:907:7ba5:b0:94e:ff23:992a with SMTP id ne37-20020a1709077ba500b0094eff23992amr5750311ejc.59.1683436942387; Sat, 06 May 2023 22:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683436942; cv=none; d=google.com; s=arc-20160816; b=FGq3GVDKlkudlIvA3M0Feb40OilqKE2dVXGKuJ4h/xATY31Ze10ttdNsdti78vGxDT P/RbXIET4Z9K8D8ksP++J5zdO0Lt1Hd+SNI1vs6gvZETdyr/dS13i63AaoHlndk+mWuj rvSnjYmt12LZUP3OGwez0EJ9aANM6wZ0f87RJyBQoI7K+HXodw63q2B0UltauO4HFC8C DZZveszM97SMkgty6SVVdPdfZ8/IB9J9jZQTC9/fuhiTyKvXHqAstxMtZrUyhJUDoxZe Q4uu1jjeZHBf8WzsrWwhDY/2EY5Fyy3WcaQrxrrgEb1hO7LAg7u+qgp7x0+OUtheWFvV GvcA== 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=TuZLrK28IvFOuVxzORB2xwMwZRV3WoiHIGw9b6HAtlk=; b=jtHO9D9nB80FU4zOLPsLk2cS2Wc5Q54VWEvxRoEFv3YkzsjnE41Rb/9B2YbJtOTt7a IA0irGCVXmTFGRaRy4CgTWuG+U15V/GJNkntpWv8VFtkH2McJ3ayVyXhM/v6Hi9i4qhH YJlRVHxrx8S0BQaRt+zbR21H7qJchVo/xhLYGyCcR4Pd50ybJnrRFF+sS7cRqGVt+aP6 GChvgO0JyhfOO46aYOVWmjd/R+SMrv05EHLk+VnTN7nVISlvCXFQTzhWyzeFZZRPMClF hWLzhm19hGCBcHk31+Y+Gfry9CegKFHm1rZG1J8IviBpa5WK3HAOSjhypKuMuciV66oY FXBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I83QmiBk; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p11-20020aa7cc8b000000b0050bcf79525esi7513988edt.5.2023.05.06.22.22.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 22:22:22 -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=I83QmiBk; 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 4DF383857703 for ; Sun, 7 May 2023 05:22:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DF383857703 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683436941; bh=TuZLrK28IvFOuVxzORB2xwMwZRV3WoiHIGw9b6HAtlk=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=I83QmiBkPbXvIpeVaHlhySsuaRQRknlrh2v8W12IuhnXMdu7ijCS2+hDFJkxXkxyl FQBpNkgK80TU0LNMUAc0pqs2fLit2rvlZoVU0tNA59xUZvK8AZli2D8clAl+iFqYd3 rPALhm3u9Fwf6Va3Um7XzX6Koa77A2x40BiZShcc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 678573858D35 for ; Sun, 7 May 2023 05:21:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 678573858D35 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3474lGLo012490 for ; Sat, 6 May 2023 22:21:37 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3qdpdphd6x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 06 May 2023 22:21:36 -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, 6 May 2023 22:21:33 -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, 6 May 2023 22:21:33 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id C799025F895; Sat, 6 May 2023 21:50:31 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/3] PHIOPT: Add diamond bb form to factor_out_conditional_conversion Date: Sat, 6 May 2023 21:50:21 -0700 Message-ID: <20230507045021.1122928-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: M6sc2fr15WnPTB9CYWpwnPH45g7QUUoZ X-Proofpoint-ORIG-GUID: M6sc2fr15WnPTB9CYWpwnPH45g7QUUoZ 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?1765210551407169251?= X-GMAIL-MSGID: =?utf-8?q?1765211575614875051?= So the function factor_out_conditional_conversion already supports diamond shaped bb forms, just need to be called for such a thing. harden-cond-comp.c needed to be changed as we would optimize out the conversion now and that causes the compare hardening not needing to split the block which it was testing. So change it such that there would be no chance of optimization. Also add two testcases that showed the improvement. PR 103771 is solved in ifconvert also for the vectorizer but now it is solved in a general sense. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/49959 PR tree-optimization/103771 gcc/ChangeLog: * tree-ssa-phiopt.cc (pass_phiopt::execute): Support Diamond shapped bb form for factor_out_conditional_conversion. gcc/testsuite/ChangeLog: * c-c++-common/torture/harden-cond-comp.c: Change testcase slightly to avoid the new phiopt optimization. * gcc.dg/tree-ssa/abs-2.c: New test. * gcc.dg/tree-ssa/pr103771.c: New test. --- .../c-c++-common/torture/harden-cond-comp.c | 6 +++--- gcc/testsuite/gcc.dg/tree-ssa/abs-2.c | 20 +++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr103771.c | 18 +++++++++++++++++ gcc/tree-ssa-phiopt.cc | 2 +- 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/abs-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr103771.c diff --git a/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c b/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c index 5aad890a1d3..dcf364ee993 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cond-comp.c @@ -1,11 +1,11 @@ /* { dg-do compile } */ /* { dg-options "-fharden-conditional-branches -fharden-compares -fdump-tree-hardcbr -fdump-tree-hardcmp -ffat-lto-objects" } */ -int f(int i, int j) { +int f(int i, int j, int k, int l) { if (i == 0) - return j != 0; + return (j != 0) + l; else - return i * j != 0; + return (i * j != 0) * k; } /* { dg-final { scan-tree-dump-times "Splitting edge" 2 "hardcbr" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-2.c b/gcc/testsuite/gcc.dg/tree-ssa/abs-2.c new file mode 100644 index 00000000000..328b1802541 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-2.c @@ -0,0 +1,20 @@ +/* PR tree-optimization/49959 */ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-phiopt1-details" } */ + +#define ABS(X) (((X)>0)?(X):-(X)) +unsigned long +test_abs(int *cur) +{ + unsigned long sad = 0; + if (cur[0] > 0) + sad = cur[0]; + else + sad = -cur[0]; + return sad; +} + +/* We should figure out that test_abs has an ABS_EXPR in it. */ +/* { dg-final { scan-tree-dump " = ABS_EXPR" "phiopt1"} } */ +/* { dg-final { scan-tree-dump-times "changed to factor conversion out from" 1 "phiopt1"} } */ + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103771.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103771.c new file mode 100644 index 00000000000..97c9db846cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103771.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-phiopt1-details" } */ +/* { dg-final { scan-tree-dump-times "changed to factor conversion out from COND_EXPR." 1 "phiopt1" } } */ + +typedef unsigned char uint8_t; + +static uint8_t x264_clip_uint8 (int x) +{ + return x & (~255) ? (-x) >> 31 : x; +} + +void +mc_weight (uint8_t* __restrict dst, uint8_t* __restrict src, + int i_width,int i_scale) +{ + for(int x = 0; x < i_width; x++) + dst[x] = x264_clip_uint8 (src[x] * i_scale); +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index f14b7e8b7e6..41fea78dc8d 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -4087,7 +4087,7 @@ pass_phiopt::execute (function *) gphi *newphi; if (single_pred_p (bb1) - && !diamond_p + && EDGE_COUNT (merge->preds) == 2 && (newphi = factor_out_conditional_conversion (e1, e2, phi, arg0, arg1, cond_stmt)))