From patchwork Mon Sep 11 02:18: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: 137868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1834094vqo; Sun, 10 Sep 2023 19:19:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEttvH5a/5j7H2uUredZVonk81Wd4is4gSrT3Tz5w4XlyUCOFAOggm3yO7reyPqEfZo7eDO X-Received: by 2002:a5d:4c51:0:b0:319:785a:fce5 with SMTP id n17-20020a5d4c51000000b00319785afce5mr6065540wrt.38.1694398755254; Sun, 10 Sep 2023 19:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694398755; cv=none; d=google.com; s=arc-20160816; b=WMedeWFZL1nch1oyqLjeljY/IyBELslgwjeRH3LdaSgRJcpRRmimSnI3I9LEy0il3E +2a4i1SKMJ8zkAGjhGXucJBcp1nFf2/ahBByFaEKfyG831fAB+kJ5YpzOIW4mfyhxClP GvbXmATofrJruJkhQCVoyIghuLHPqmK41p8hVBX4goaIbhCML4F87jMYtasMk9gX1clm IDLgtmUMqaTk7rEW1KAGSxK22MluORQNXEb+LWmpUsmouR3WQji8u2Se77V9kow6qlCu 19XbX2U5UG8gPoc1ojdi0yjK4CAj5oH6gkODhLSkegBDG/lbPOlfCBxlwyi8N03fCdQn fkFQ== 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=ZnKiXiz1sms4TYq+uChgXSlX/u0wv2gqN4/lJbQQFx4=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=i+G2E2D3RjlTPk0LYYyXrs8VJy8C+/hhOqJd3t7exf4E8ljTa+AYMi+d2hWGvNbirJ IYF4PUciieS5yeoxBcrFUl51dsPx4N+ZcZGn6sQ/0WS+77T6sfZX3gIcsJ+X4G2f8/VO T0prscDG1K2JmI9ClW3hQd8fzeyF8sRVBHyb+a1xgquaACqQnk5BjIsEYsdd9f43mRJu gyF7SUmiW6hpESRsmjEXxN8EPt/f12llrUGOSmWmW3OQ7ElRdp/s5FOLT2MyE4Ki3YhH nOr3JfSPKqEdBtOfXWRmT600bq7kZb+7mbU0iKAIDyndtOK2AaGdWHyRftKKo3eSOjm6 Wsdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KVsTylUE; 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 c13-20020aa7c98d000000b0052c98ac3c73si6095502edt.193.2023.09.10.19.19.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Sep 2023 19:19:15 -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=KVsTylUE; 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 2D43A3858296 for ; Mon, 11 Sep 2023 02:19:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D43A3858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694398754; bh=ZnKiXiz1sms4TYq+uChgXSlX/u0wv2gqN4/lJbQQFx4=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=KVsTylUECxMkT6WSkHCTqUPPaTUm0GPFzOt3i0B3/TpWlA7CZ8lWwD5tdF63jjdax uLtMjeRFjSB1El2ww6ugXKHyVrJ0kzig1AS3I+fUAFvZU8s/O4Hd3tP8bHW3twoXaA S3e4lN9VA5cxyzV+6bLqXpq96Fe6xoJRemTlHH3A= 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 0F4F63858D3C for ; Mon, 11 Sep 2023 02:18:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F4F63858D3C 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 38AMwdf7014597 for ; Sun, 10 Sep 2023 19:18:28 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3t0p2q48xw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 10 Sep 2023 19:18:27 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 10 Sep 2023 19:18:26 -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; Sun, 10 Sep 2023 19:18:26 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 194A23F7050; Sun, 10 Sep 2023 19:18:26 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: [PR111346] `X CMP MINMAX` pattern missing :c on CMP Date: Sun, 10 Sep 2023 19:18:11 -0700 Message-ID: <20230911021811.1347413-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: TMXKJGCoCF6GHdhl5c_PNjpF21F8fU-h X-Proofpoint-GUID: TMXKJGCoCF6GHdhl5c_PNjpF21F8fU-h 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-10_18,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: 1776705868748522913 X-GMAIL-MSGID: 1776705868748522913 I noticed this while working on other MINMAX optimizations. It was hard to find a simplified testcase though because it was dependent on the ssa name versions. Adding the `:c` to cmp allows the pattern to be match for the case where minmax as the first operand of the comparison rather than the second. Committed as obvious after a bootstrap/test on x86_64-linux-gnu. PR tree-optimization/111346 gcc/ChangeLog: * match.pd (`X CMP MINMAX`): Add `:c` on the cmp part of the pattern gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmaxcmp-1.c: New test. --- gcc/match.pd | 2 +- gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-1.c | 39 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-1.c diff --git a/gcc/match.pd b/gcc/match.pd index c7b6db4b543..a60fe04885e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3942,7 +3942,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for minmax (min min max max ) cmp (ge lt le gt ) (simplify - (cmp @0 (minmax:c @0 @1)) + (cmp:c @0 (minmax:c @0 @1)) { constant_boolean_node (cmp == GE_EXPR || cmp == LE_EXPR, type); } )) /* Undo fancy ways of writing max/min or other ?: expressions, like diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-1.c new file mode 100644 index 00000000000..0706c026076 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-1.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-original" } */ +/* PR tree-optimization/111346 */ + +int f(); +int g(); + +_Bool test1(int a, int b) +{ + return ((a > b) ? a : b) >= a; // return 1; +} +_Bool test1_(int a, int b) +{ + return a <= ((a > b) ? a : b); // return 1; +} +/* test1 and test1_ should be able to optimize to `return 1;` during fold. */ +/* { dg-final { scan-tree-dump-times "return 1;" 2 "original" } } */ +/* { dg-final { scan-tree-dump-not " MAX_EXPR " "original" } } */ + +_Bool test2(int a, int b) +{ + a = f(); + a = g(); + int t = a; + if (t < b) t = b; + return t >= a; // return 1; +} + +_Bool test2_(int a, int b) +{ + a = g(); + int t = a; + if (t < b) t = b; + return t >= a; // return 1; +} + +/* All of these should be optimized to just be the function calls and `return 1;` */ +/* { dg-final { scan-tree-dump-times "return 1;" 4 "optimized" } } */ +/* { dg-final { scan-tree-dump-not " MAX_EXPR " "optimized" } } */