From patchwork Mon Sep 11 20:39:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:be0d:0:b0:3f2:4152:657d with SMTP id j13csp29317vqz; Mon, 11 Sep 2023 13:40:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlr+B6YaAvqDTwi0XL6DqvfY2livWfiH3Dbf0Ewj6etGJTyU+ikYU+Sw7l3YyE7oYxx8oe X-Received: by 2002:a05:6512:33cf:b0:502:a942:d7a8 with SMTP id d15-20020a05651233cf00b00502a942d7a8mr7597598lfg.69.1694464840785; Mon, 11 Sep 2023 13:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694464840; cv=none; d=google.com; s=arc-20160816; b=afzGCQ15SNd6OA+WdMnRnak+n06fsmPqAFAlcyDjHnVZL50A79gvCiPx/7T/UkgQJy KFxUnL9E9Wnm7Iut/ixJvaRdsNwff5HFqPMmcybRPBLS6Rzztzf9LjRWBRKITooFo4Cx HMjXN8YQda+9zuYzooq59OszpX+S+TaQp3lEh7NbD7g2UcqRkfvF2L+Z3DS5nZ1w/tOD CT5vmR0BoGB4bfRRa/PPH0soMDbB/B9Fs9TGSFKxGlKQArAa9U6j555NqGfD3kqgrZbh Zf/8Uw1C9FSqBH0FDPJCoaJ+5p9NATDYG9tjva0+Ra2cz6v+NzQ1mkNpM4+66mHYwLtG Al/w== 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=/wTtlL0RuaJXHpWZQ6j1YxKxd2vBbQenzS8YYJUH3Ec=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=zkhwVTSByjRARqQCn8HCz0dhycSHqaFKG93iaJxqoAT8Hvn27trztqN7FbnAJ5kWSy RTmICLy8h0/R/0/X8OmcqAxY/55deG183jc20hFm1aYYoxw61/y3IQaHVFKlHt3cMQjl 7cXMyxxNRy0UHSq7wvp1lRjS1tpBeLwm/3euUCQdN90FHbLtemUAC723JTslRuy1EATP NzJe4iDxKp+PxTx5mcHzqA9BCnaEhitoFWPyGvtW6Ek8xJVZKr+2Kbycj2Xu7Bx8bE7/ pF1WUAmvoG12DJGQSKwpQn9LkgjNnDnjRzuEHN5zczuWMTDTqX9xdVn8Gc94f6Pv1evK Pv9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bRazJOIp; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay22-20020a056402203600b005255885cbc7si7083530edb.280.2023.09.11.13.40.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 13:40:40 -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=bRazJOIp; 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 AAB6B3858407 for ; Mon, 11 Sep 2023 20:40:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAB6B3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694464839; bh=/wTtlL0RuaJXHpWZQ6j1YxKxd2vBbQenzS8YYJUH3Ec=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=bRazJOIptoDIglTmJ0gV9dacd8RIGaxWTH96SEeSdyYdExIJWFBgkEeTW7B912c8X EVgFXBODDUcgC6SZXpPkj/FD/wLxlR8zyKTlrHdSDpa/SSrvrUT+rK2DYeMSNuxdTa taCKgb7hnO83ks0guxsETSzZ+X+bePXTBWLgWamk= 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 C901C3858D38 for ; Mon, 11 Sep 2023 20:39:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C901C3858D38 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 38B9A89j007272 for ; Mon, 11 Sep 2023 13:39:54 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3t200qj5kc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 11 Sep 2023 13:39:54 -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; Mon, 11 Sep 2023 13:39:53 -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, 11 Sep 2023 13:39:53 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id D330E6737C; Mon, 11 Sep 2023 13:39:52 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: [PR111348] add missing :c to cmp in the `(a CMP b) ? minmax : minmax` pattern Date: Mon, 11 Sep 2023 13:39:39 -0700 Message-ID: <20230911203939.1394059-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Kz58lRYWWsyiOWKg-l_fOAnvsmGlIACy X-Proofpoint-GUID: Kz58lRYWWsyiOWKg-l_fOAnvsmGlIACy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-11_16,2023-09-05_01,2023-05-22_02 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_PASS, TXREP 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.30 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: INBOX X-GMAIL-THRID: 1776775164844852005 X-GMAIL-MSGID: 1776775164844852005 When I added this pattern in r14-337-gc43819a9b4cd, I had missed the :c on the cmp part of the pattern meaning there might be some missing optimizations happening. The testcase shows an example of the missed optmization. Committed as obvious after a bootstrap/test on x86_64-linux-gnu. PR tree-optimization/111348 gcc/ChangeLog: * match.pd (`(a CMP b) ? minmax : minmax`): Add :c on the cmp part of the pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-26.c: New test. --- gcc/match.pd | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-26.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/minmax-26.c diff --git a/gcc/match.pd b/gcc/match.pd index 209b0599382..e96e385c6fa 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5417,7 +5417,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for minmax (min max) (for cmp (lt le gt ge ne) (simplify - (cond (cmp @1 @3) (minmax:c @1 @4) (minmax:c @2 @4)) + (cond (cmp:c @1 @3) (minmax:c @1 @4) (minmax:c @2 @4)) (with { tree_code code = minmax_from_comparison (cmp, @1, @2, @1, @3); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-26.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-26.c new file mode 100644 index 00000000000..e4b7412e766 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-26.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-original" } */ +/* PR tree-optimization/111348 */ + +int test1(int a, int b, int c) +{ + return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c); +} + + +int test1_(int a, int b, int c) +{ + return (b < a) ? ((a > c) ? a : c) : ((b > c) ? b : c); +} + +/* test1 and test1_ should be able to optimize to `MAX_EXPR , c>;` during fold. */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR , c>" 2 "original" } } */ +/* { dg-final { scan-tree-dump-not "b > a" "original" } } */ +/* { dg-final { scan-tree-dump-not "a > b" "original" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR " 4 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */ +