From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id F29A83858C5F for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F29A83858C5F 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 (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33OGXia1028418 for ; Mon, 24 Apr 2023 14:30:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=ec8Qtdi03cJEnO5uQmLPjDwo9NblaKltLkFBkOukIP8=; b=lTvUNG00XBJoZFPtAMDpMl5Mku1qofN5y8h+Xs1O7yy5Q9jxgq/XBfbCvEjWgz5hH23o IQVVWBK5jFMeNsFyef5/9YsdpuR75YE80UCPuyTBJulHK7qLTktPeuB2dOfPKOkfMSqp RDA05Q5fD+r5JAae1Z3kIotl3DVR4U4qSyZalD/CJo/svZF2R4eoL2Yit8arKI+NBHPw 5jN//44xX0lSii1fnuLt6CQPvLTwEUyA6CP5WglKVeD11MkZNGhsO9XQzPhWxw2WTryG ua0z4bZR53C/b47Q44qIQie4oY5WmVTCnkYQua2tEfHTxmnjONR7u8DBJN+DUISX28ka Hg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q5nfb3jvs-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 24 Apr 2023 14:30:23 -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, 24 Apr 2023 14:30:22 -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, 24 Apr 2023 14:30:22 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 0653D3F70A2; Mon, 24 Apr 2023 14:30:21 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 7/7] MATCH: Add patterns from phiopt's minmax_replacement Date: Mon, 24 Apr 2023 14:30:11 -0700 Message-ID: <20230424213011.528181-8-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230424213011.528181-1-apinski@marvell.com> References: <20230424213011.528181-1-apinski@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: P0SAbgIuzRrR-NZGC93vyo5vBfxWYGQx X-Proofpoint-GUID: P0SAbgIuzRrR-NZGC93vyo5vBfxWYGQx 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-04-24_11,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.6 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: This adds a few patterns from phiopt's minmax_replacement for (A CMP B) ? MIN/MAX : MIN/MAX . It is progress to remove minmax_replacement from phiopt. There are still some more cases dealing with constants on the edges (0/INT_MAX) to handle in match. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd: Add patterns for "(A CMP B) ? MIN/MAX : MIN/MAX ". gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-16.c: Update testcase slightly. * gcc.dg/tree-ssa/split-path-1.c: Also disable tree-loop-if-convert as that now does the combining. --- gcc/match.pd | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c | 10 ++++++++-- gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 6d3aaf45a93..5d5aae24509 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4843,6 +4843,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (convert @c0)))))))) #endif +/* These was part of minmax phiopt. */ +/* Optimize (a CMP b) ? minmax : minmax + to minmax, c> */ +(for minmax (min max) + (for cmp (lt le gt ge) + (simplify + (cond (cmp @1 @3) (minmax:c @1 @4) (minmax:c @2 @4)) + (with + { + tree_code code = minmax_from_comparison (cmp, @1, @2, @1, @3); + } + (if (code == MIN_EXPR) + (minmax (min @1 @2) @4) + (if (code == MAX_EXPR) + (minmax (max @1 @2) @4))))))) + /* X != C1 ? -X : C2 simplifies to -X when -C1 == C2. */ (simplify (cond (ne @0 INTEGER_CST@1) (negate@3 @0) INTEGER_CST@2) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c index 4febd092d83..623b12b3f74 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O -fdump-tree-phiopt -g" } */ +/* { dg-options "-O -fdump-tree-phiopt -fdump-tree-optimized -g" } */ #include @@ -25,5 +25,11 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */ +/* After phiopt1, there really should be only 3 MIN_EXPR in the IR (including debug statements). + But the way phiopt does not cleanup the CFG all the time, the PHI might still reference the + alternative bb's moved statement. + Note in the end, we do dce the statement and other debug statements to end up with only 2 MIN_EXPR. + So check that too. */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 4 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */ /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c index 902dde44a50..b670dee8d10 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c @@ -1,5 +1,6 @@ /* { dg-do run } */ -/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt" } */ +/* Note both PHI-OPT and the loop if conversion pass converts the inner if to be branchless using min/max. */ +/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt -fno-tree-loop-if-convert" } */ #include #include -- 2.39.1