From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=TuZLrK28IvFOuVxzORB2xwMwZRV3WoiHIGw9b6HAtlk=; b=kQnh0zDTOVuZPYlNN00KZZUAL0GQD//D4Hg2Dc+Gx2pKWso/mDKlPHRqA2ldnDIniYPc c/ESds5ZHdRE9gBIQX24rpACNRuR/t/CqrUgX5kXTdLXHgaFUCroclGQLxdMmsjl+J9Q 35O+A571WuA/oeP1RAq4lCPDneJIpclJ3/rmE5sbig0LJHA5CMEtVOFqepOMM/CdoN6W mDcWj/76eszGFaDZdhy5gNfmQ7w46ejwcXZB+l92tjmp0FjRWhptwk1uSHITazirTSTL AhNJHt/BCLC2w4sGqDzIT6pJWbav4CvFDrkXR7/ntzFJd0wQVlkIP2JMIo++tsBMKpxx 5g== 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) From: Andrew Pinski 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 List-Id: 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))) -- 2.31.1