From patchwork Sun May 7 04:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 90817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1394291vqo; Sat, 6 May 2023 22:06:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AnS7414ptSCZM2PtJ9vb7v9ZO5MCjWm4zmcKE7RnR8ft6C11pdSaucV0kz/y4xi2rlZ/c X-Received: by 2002:a17:907:608c:b0:962:582d:89c3 with SMTP id ht12-20020a170907608c00b00962582d89c3mr6246502ejc.22.1683435965701; Sat, 06 May 2023 22:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683435965; cv=none; d=google.com; s=arc-20160816; b=e8XsyAIdBTnNxafE8OHcSz9Eq4aAxKeiNFfkWSOW44FXV8Bp2KqNSTaoOOgpNxEpYR K5MOvSHep52M/pbHM6GM20M9fKqzbyoSAo/0z98CkEMkgzMDI2+IadAOnzhQ2EWrPoFy dc5UxbF1SaHa/RhVG7dWJUlOgU/FpXL+jd1xfU1Y8b0T7FHiR7VHD7Bz+QFufgcGCoQG N2XXOcFShsiORMT/SVmfxLBde1mJAk6QHLeH7WPCGdnFjOR5WMVLSluTwvaKHjR03dam +jbrpnocXrK49oE50Y7BTmXq2y2Mz7gzvU8SQkGetEN0ZR47HENeppLC3qMZZqZtcV3J HgDg== 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=sbgwJyDADrEOSJfcf+dtEhgJs0vQh18jHHdqQKcFB2OC76RMnljj6iPt13JnlJwbTK w5GtNhoHOJdGY0F36RMYz1odowda+qk6qteb+YJsVCNJVpKPZlbThmmR7TPMVbKcDuC0 Hz1LWGGNmq+Z6reGKDKATEzhZHvrou/3Cg4GZrLdxNL93P1+7KGpIRWS2mVXq5UOgO/u hWvw8Cn6tCKjGNhbnQMUrTnaAMAc8F4MdYxbIlBZoaqYiG+t1LCGlnEPOTatZmPXsY/h 7hcc3rbyBazbwagnwpYHytjhSWhjaz93iCLy8WLALeZizL7by338dbCU3pREEB1WkaTd 1C4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=To1BswSf; 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 r7-20020a1709064d0700b00957c0cf514csi3735216eju.772.2023.05.06.22.06.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 22:06:05 -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=To1BswSf; 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 4E1793858401 for ; Sun, 7 May 2023 05:06:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E1793858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683435964; bh=TuZLrK28IvFOuVxzORB2xwMwZRV3WoiHIGw9b6HAtlk=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=To1BswSfAjxcBYC/Tc+m7nP2WG+dzJB+YFbdfu70MBKuZrHCszDpmI+3ZYIHGxs1h yvMCwpkJ4mGeHkr8FD0G6jVy9PPtNfxJqEw4n5WwwBF3VWopnuCkUJQGir+XGQbPlW KR/EkyJmLTmLwPf23iPug0pxxj4UMpa8EPspzSXg= 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 D89DE3858D35 for ; Sun, 7 May 2023 05:05:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D89DE3858D35 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 3474rJnh023426 for ; Sat, 6 May 2023 22:05:20 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3qdpdphcge-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 06 May 2023 22:05:19 -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 22:05:16 -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 22:05:16 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 1B6C5626A73; Sat, 6 May 2023 21:43:41 -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:43:30 -0700 Message-ID: <20230507044332.1122612-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: as2nOVdWPP4JjEkdIRne5aUYFa415nHm X-Proofpoint-ORIG-GUID: as2nOVdWPP4JjEkdIRne5aUYFa415nHm 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?1765210551407169251?= 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)))