From patchwork Mon Sep 11 14:23:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp2113950vqo; Mon, 11 Sep 2023 07:25:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVNbajSlOCe9KrG/E5fsJxOO2oDc1RBW4AWOApcXDyFUVT7JMyNPH/RaDBATuiUyw4hyhl X-Received: by 2002:a17:906:31d8:b0:9a1:d67c:b4eb with SMTP id f24-20020a17090631d800b009a1d67cb4ebmr7001790ejf.48.1694442340813; Mon, 11 Sep 2023 07:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694442340; cv=none; d=google.com; s=arc-20160816; b=hoNepGPO1jDtH6k+c8IVCX9Kd6+a158FEm/IQPCjIVJwxqsBQPzKKoms5yEVSHL/6c GIFUwRemmPAjSUWw+/nN5+SImInmCNVsZOT3BlblX20X37RVXS0JRkp/aoJI7VcD2ZyF oGHXNZs1nRq1MmQ3dsq34wjnJKGhLBMAr82kEegmiVfTduEIiDigiRZwNrl08WNTaDdS qpkk2rzcdn0BYKQ1WKXDamZerGt/PScv3LrEQyRqwRfba6mSS2Kc9zKOIlXVhlUmFoH9 p62+IUDBcg/2f1234RI04pfYJ3dgo0/PeutxgnxXmQdCjUNaSfBddoumd9kfKo5NiqRP vOqQ== 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=9PrU9vUP7DCL4nJHcVBNsVykmhA2YdfFnoZ0d7RRWYc=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=fjbp2mhX4eRyLRu8uR57J56m9jPwLOul2jgwcuy3h3+OS4QZ/u04VSCxmPkPASf1Ru B3YAdn04SpKo2DXEIjQmhtpnMXcURR5BUMOOF+0HNQthOjGwTdas9cneC+0p/Bedszo1 AhGO+OWQMkGaVkqbju5ZZJGWr2Fiqj74LvZPc5Hj0rUdCZX8kEJ4jSORLpE8yZseMhJe 6W4jkgCPPM6bdv4I0Weo440Gt0w9KQudELj+770iNOBaGKPahh+NIqGAL3uPaAauPR2C 5hOHWsZzRJMrR2GxjM2BktI0a9q7J6wv5AhhR0UcsJChL36o2836DMyxqmP//VmNTLZD vY4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hOa7I3tH; 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 a19-20020a170906245300b0099df02668eesi6615590ejb.150.2023.09.11.07.25.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 07:25: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=hOa7I3tH; 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 C6693385773C for ; Mon, 11 Sep 2023 14:25:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6693385773C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694442324; bh=9PrU9vUP7DCL4nJHcVBNsVykmhA2YdfFnoZ0d7RRWYc=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hOa7I3tHf05jxyU7tde98gWwVk9caulauTFRnrxYf1YNAM0ofW/aRm7UuZg08tO3J QiZdIVgKSTjsOoBTuvXUtYEBPn9ggpd4It+u90Pf2R9DQ49byQKZVqcGAfjII5kN7G qvjOknQw7y++fMDJEmUd10cXxVTfLD6VuFuMrb2w= 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 17B793858C62 for ; Mon, 11 Sep 2023 14:23:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17B793858C62 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 38BCV500021660 for ; Mon, 11 Sep 2023 07:23:44 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3t0r7knvg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 11 Sep 2023 07:23:44 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 11 Sep 2023 07:23:42 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Mon, 11 Sep 2023 07:23:42 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id E8AD95C6928; Mon, 11 Sep 2023 07:23:41 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: [PR111349] add missing :c to cmp in the `(a CMP CST1) ? max : a` pattern Date: Mon, 11 Sep 2023 07:23:28 -0700 Message-ID: <20230911142328.1378300-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: 0nwph7w68TtPxx_EV_Jo6MqMTsMW9oQG X-Proofpoint-ORIG-GUID: 0nwph7w68TtPxx_EV_Jo6MqMTsMW9oQG 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_09,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: 1776751571751933067 X-GMAIL-MSGID: 1776751571751933067 When I added this pattern in r14-1411-g17cca3c43e2f49, 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/111349 gcc/ChangeLog: * match.pd (`(a CMP CST1) ? max : a`): Add :c on the cmp part of the pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-25.c: New test. --- gcc/match.pd | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c diff --git a/gcc/match.pd b/gcc/match.pd index a60fe04885e..209b0599382 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5431,7 +5431,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for cmp (gt ge lt le) minmax (min min max max) (simplify - (cond (cmp @0 @1) (minmax:c@2 @0 @3) @4) + (cond (cmp:c @0 @1) (minmax:c@2 @0 @3) @4) (with { tree_code code = minmax_from_comparison (cmp, @0, @1, @0, @4); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c new file mode 100644 index 00000000000..b7a5bfd4c19 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-25.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized -fdump-tree-original" } */ +/* PR tree-optimization/111349 */ + +int f(); +int g(); + +int test1(int a, int b) +{ + return (a > b) ? ((a > b) ? a : b) : a; +} + +int test1_(int a, int b) +{ + return (b < a) ? ((a > b) ? a : b) : a; +} + +/* test1 and test1_ should be able to optimize to `return a;` during fold. */ +/* { dg-final { scan-tree-dump-times "return a;" 2 "original" } } */ +/* { dg-final { scan-tree-dump-not " MAX_EXPR " "original" } } */ +/* { dg-final { scan-tree-dump-times "return a" 2 "optimized" } } */