From patchwork Mon Apr 24 21:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 87170 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3016701vqo; Mon, 24 Apr 2023 14:33:53 -0700 (PDT) X-Google-Smtp-Source: AKy350b+MeASnIX/1kUgyEV0hckCeertj0wVIOYTZmrLwRM+oS8DazcxeGUZzxn/FCqcJ6GQKE3d X-Received: by 2002:a05:6402:6c7:b0:504:9345:ffa4 with SMTP id n7-20020a05640206c700b005049345ffa4mr15961879edy.21.1682372033658; Mon, 24 Apr 2023 14:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682372033; cv=none; d=google.com; s=arc-20160816; b=KUJpZRp7ksRT5D4ykGEahEMolOPyOjBXwOu//FQatXqX4O9502LEdlOyyw2B/BdUqF fLcfS7SToSz/xDSlleiBGQNDvbh8qYVKmhA+BybcWvhFoljgDtBO+VWeszsM6YBLW/aL eK6AuMTxkKw0aT7YtMPXbDBiBgVfu9VNFu4rrKMb2lNh0vhcxhOl7GjVzbDsNJDlAJRB M0v5Bxp/Yekq5otJkmWx3Td8TG6xvj42JIAfsdthylv0RLJ6a16ZxWlz4iVhnTLmIHkr vmYRFClvZSDxzE/jdPvAhEnFP9aoWPVgPE/CIHDzWwfVLdE+2/WeG9TdyontMt/Kr1j2 RxnQ== 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=ec8Qtdi03cJEnO5uQmLPjDwo9NblaKltLkFBkOukIP8=; b=0cGm5tfANa6FQUhJQUjLT4VUGIVYKhqPvumVNsLEkLBR6lFyuJg0lPegx75PG6eVTz PnEpKkNFDVDWkC6g3J3GeG8Bu22bbGbhtOAyGE99/SLzdbYHrDQqULUZeoQdDxOWRONI HzFj1D6qa/sRKZ1HbLbrWI7ZN0zcpNrrZF1T9gAA1J2YUkY+k6keq33q1T1R/yWIcdE6 dB0SHVUmyKLMBKxCN/gJs9XEdtX5Bp1nk37vYUCZ03Ttvty6tkJipB1DBe0qjYMOlXby xJARuVs6P8RkURRw5/MT4t/2h2Jitrf0n54SdppvLLycZc1eGpIa8lpsIeoXXaCSXkc6 9ZVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EgkNCRON; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k14-20020aa7c38e000000b00506921654eesi8786668edq.368.2023.04.24.14.33.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 14:33:53 -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=EgkNCRON; 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 422C33853549 for ; Mon, 24 Apr 2023 21:32:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 422C33853549 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682371930; bh=ec8Qtdi03cJEnO5uQmLPjDwo9NblaKltLkFBkOukIP8=; 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=EgkNCRONHrSyEsj0f/68JMgDCtf34N6HaChhP2l8VgLBFPnqHG8BJblmJvWCOoS0s SJ4u32JtLiadFPddDWav1JlT5Vo/7P7zuFlp4p8GLYwrDtDpg+jloh+TK0w1h1lFuC nFTqryjlwcPG9Ax96qYS76sA0lirDilBfjoyPhHY= 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 F29A83858C5F for ; Mon, 24 Apr 2023 21:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F29A83858C5F 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 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) 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 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 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?1764094937890563280?= X-GMAIL-MSGID: =?utf-8?q?1764094937890563280?= 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