From patchwork Mon Sep 4 00:21:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp817923vqo; Sun, 3 Sep 2023 17:22:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoN7m3bQiazh8Sfy++5ZgR+Y3HFlQD/z3FdhAl7jCBAZfS7j0xsoDCYv6KSqEs7/ml1MXb X-Received: by 2002:a05:6402:6cf:b0:52b:db31:3c5c with SMTP id n15-20020a05640206cf00b0052bdb313c5cmr7205540edy.0.1693786959753; Sun, 03 Sep 2023 17:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693786959; cv=none; d=google.com; s=arc-20160816; b=owczktz1cLSl6Fw9DOYFw5p2u6b0s1FFOIzhF5mbhExV0gv7nlgUMoiElHDEw563SK oJoK4LmO0WuT5a47OeebRQVFm4g/t+fJ5Oam2bMg1MYLrfd1CaJ1Zbh3nkcuezUHc+Jh het+KC/5biZpzAfuFFj5p9wRe99ipriysO+WJwlLXXFPK8vOyVPrFkP3wqvcJg2PoQId fatsLgIVGPQRPl5AaorhgjJPgypjuTLhN469JeRYtjuJevwdQbVUYZtn25O3CMyaBXjI Q6pBMSFVJh4WMl+8+oS7QiZb+sLk+hEy19g0a4xa3HgtlHf4/TtH235WfFVXVqpQK3WH SWgA== 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=MF9M+DfPA6xLlff/1qMrX+rOUfIhU2qmjisYL3+5WxU=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=Zw30OFNbF0nnsXp+v1P/6zc+qSJYqyjICD2GWzwHo5+0gd/0F0a3nx0QeF0i30Ps/X xgNqcJZWOMygHG5lSCBVwKNwJLDWmuG7iQ4sgDq4WTKS2Gr23VJ6tFaz9d1XjFU4X0UN 3fK/hQusgwiLBclVMUW3OQb24Ye6R2qEkkQmVppRHliUobmY4EXb17WPzL6OFgBbBAD7 9DT8cpsoLr62cXhXbXXjduYXm5k6Rxf2eiwOuhjJB0+3t7thu6fwuPx3gMvYj7KdGOQg kb4ezk1ci9J8V1jdpGz9xScPdRcisP5blsfIZZRrd5pwy1+hAGqLdSPGxoJcWJKVb6BW iUtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gCukJjsP; 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 u4-20020a05640207c400b00525744fec60si5750741edy.49.2023.09.03.17.22.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 17:22:39 -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=gCukJjsP; 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 AF5C03858C52 for ; Mon, 4 Sep 2023 00:22:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF5C03858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693786958; bh=MF9M+DfPA6xLlff/1qMrX+rOUfIhU2qmjisYL3+5WxU=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gCukJjsP/I9ZnN0t18z7ZOewi6BMwUYFZdz9N2LQLJnJFPNphIoYE60X0COfPt4/I gUglEV17Ger7R3h06vt5mQSQJtKTX8qgaa9hHhIi+nJaXLcWg4xlSWgaUcJ3PhbYyh JKtKYDAyM8xSTsRdN/8fYzYctd09CU2Wc/5r43RY= 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 79415385843E for ; Mon, 4 Sep 2023 00:21:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79415385843E 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 383KqLN5003842 for ; Sun, 3 Sep 2023 17:21:52 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sv2dp3vcx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 03 Sep 2023 17:21:52 -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, 3 Sep 2023 17:21:50 -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, 3 Sep 2023 17:21:50 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 40D483F705F; Sun, 3 Sep 2023 17:21:50 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Add `~MAX(~X, Y)` pattern: [PR96694] Date: Sun, 3 Sep 2023 17:21:35 -0700 Message-ID: <20230904002135.928111-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dALseUJKTlAIH5Kkb0Y5Tc3IyWchsG22 X-Proofpoint-GUID: dALseUJKTlAIH5Kkb0Y5Tc3IyWchsG22 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-03_21,2023-08-31_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: 1776064355133302423 X-GMAIL-MSGID: 1776064355133302423 This adds `~MAX(~X, Y)` and `~MIN(~X, Y)` patterns that are like the `~(~a & b)` and `~(~a | b)` patterns and allows to reduce the number of ~ by 1. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/96694 gcc/ChangeLog: * match.pd (`~MAX(~X, Y)`, `~MIN(~X, Y)`): New patterns. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/minmax-24.c: New test. --- gcc/match.pd | 7 ++++- gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c | 31 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c diff --git a/gcc/match.pd b/gcc/match.pd index e9ce48ea7fa..604c2c2360c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3786,7 +3786,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) maxmin (max min) (simplify (minmax (bit_not:s@2 @0) (bit_not:s@3 @1)) - (bit_not (maxmin @0 @1)))) + (bit_not (maxmin @0 @1))) +/* ~MAX(~X, Y) --> MIN(X, ~Y) */ +/* ~MIN(~X, Y) --> MAX(X, ~Y) */ + (simplify + (bit_not (minmax:cs (bit_not @0) @1)) + (maxmin @0 (bit_not @1)))) /* MIN (X, Y) == X -> X <= Y */ (for minmax (min min max max) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c new file mode 100644 index 00000000000..2b21f94eecf --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/96694 */ + +static inline int min(int a, int b) +{ + return a < b ? a : b; +} + +static inline int max(int a, int b) +{ + return a > b ? a : b; +} + +int max_not(int x, int y) +{ + return ~max(~x, y); // min (x, ~y) +} +/* { dg-final { scan-tree-dump "~y_\[0-9\]+.D.;" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "~x_\[0-9\]+.D.;" "optimized" } } */ +/* { dg-final { scan-tree-dump "MIN_EXPR |MIN_EXPR <_\[0-9\]+, x_\[0-9\]+.D.>" "optimized" } } */ + +int min_not(int c, int d) +{ + return ~min(~c, d); // max (c, ~d) +} +/* { dg-final { scan-tree-dump "~d_\[0-9\]+.D.;" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "~c_\[0-9\]+.D.;" "optimized" } } */ +/* { dg-final { scan-tree-dump "MAX_EXPR |MIN_EXPR <_\[0-9\]+, c_\[0-9\]+.D.>" "optimized" } } */ + +/* { dg-final { scan-tree-dump-times "~" 2 "optimized" } } */