From patchwork Tue Sep 12 15:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 138256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp489389vqx; Tue, 12 Sep 2023 08:32:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLmNGUhpj4YOuw6sN9Jzg+gpyf3GGgEzq9mAO9nauBAJ9Eq3PBKHzeVTbFhf2pzc0k+EL2 X-Received: by 2002:aa7:c999:0:b0:529:fa63:ef80 with SMTP id c25-20020aa7c999000000b00529fa63ef80mr10131534edt.28.1694532725035; Tue, 12 Sep 2023 08:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694532725; cv=none; d=google.com; s=arc-20160816; b=Ha1obkCSZC1ZqVR0liLjNZsRJYbgIdvQhfrJWzte4pqR5ZxymMaLvhh8gi+vsVuawp 9xLg8owpTSjfoaCoqNrCiXE77iiRTIuANem79mjsb0FILpC8hhyaMgNotqm7JS4TB9Dx yPEYG2HIIx8D453oBY3NFsO+83A9gJn1fcXNQ6Em9mggGBjPoHw0qMGubHeu4VQcND4Q RqidUUqgCLaURH1eloZbOG0cMvRHuyYCn5c2Y/MOjLvUKAMwiqceUdhsKjvyMKp8XuVI cC0CJzvKlozc9gwtnLcDyBhQW/mZ3UAWdVAz9QK/jE2x1JgEQCOLLaD0S9hEcOoPKKEw f92w== 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=DPlGTXj2ZkFRKTpiwJ93UTMU2UQRictCijx8HnRSC6Q=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=K/nkbFKD6qOF6KyOKttrXuFxpxW/cTp7wXx5nrsqksUhD4BrnXPBCPZvmoRcLwuN8M zTKeANrSgNoRjImRhp83ZJedMtxS+l/J1BZm6wUxLT4h3T8/r4FYbq3JH9bRUDPgt5Gk Al7NuGLdagI+tllkqVEdpHf06Zv6nso3MSsago7ajVNoIxLBRSXmIV8VxY8p/vF3+esC SLkAD5P+WQSJGZkafhpMYQuf4UwszUdBRx5H9avv3tvyQ+/fQkxxnxy9ObQjQwx56XGu MXH28FSfE2w1qW5iLA+V7I4q7ixZ+GslbAxYvCU4FHZX+HpW6UfDJxweHCcRrb1FuYki 1r1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Bn+w+AkA; 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 j19-20020aa7ca53000000b00523b8072776si8686656edt.121.2023.09.12.08.32.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 08:32:05 -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=Bn+w+AkA; 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 A221B38983AA for ; Tue, 12 Sep 2023 15:28:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A221B38983AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694532485; bh=DPlGTXj2ZkFRKTpiwJ93UTMU2UQRictCijx8HnRSC6Q=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Bn+w+AkArRjibNUAHuiS4nyyAycZbPiQIrExkSsLSiJPOu7+KApZo01z2EqPs+qLj yXUCR0BlCK84gi1CTrYXfhyowNmdjLjwltOMQsGkTxIiK+Ao7QtbmdKGTJJarzWB46 jZlQpT19HuXRZfi0+pzdAA8PJjZgWty/3FQncnyg= 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 AB2A538515CC for ; Tue, 12 Sep 2023 15:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB2A538515CC 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 38C7K8ER031999 for ; Tue, 12 Sep 2023 08:25:57 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3t2kgesv4t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 12 Sep 2023 08:25:57 -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; Tue, 12 Sep 2023 08:25:55 -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; Tue, 12 Sep 2023 08:25:55 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 13B753F70E5; Tue, 12 Sep 2023 08:25:54 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/2] MATCH: [PR111364] Add some more minmax cmp operand simplifications Date: Tue, 12 Sep 2023 08:25:41 -0700 Message-ID: <20230912152542.1440800-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: DiMU54tc1FK-ap_nXLN7aPGNiQJokgKI X-Proofpoint-ORIG-GUID: DiMU54tc1FK-ap_nXLN7aPGNiQJokgKI 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-12_14,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: 1776846346684810169 X-GMAIL-MSGID: 1776846346684810169 This adds a few more minmax cmp operand simplifications which were missed before. `MIN(a,b) < a` -> `a > b` `MIN(a,b) >= a` -> `a <= b` `MAX(a,b) > a` -> `a < b` `MAX(a,b) <= a` -> `a >= b` OK? Bootstrapped and tested on x86_64-linux-gnu. Note gcc.dg/pr96708-negative.c needed to updated to remove the check for MIN/MAX as they have been optimized (correctly) away. PR tree-optimization/111364 gcc/ChangeLog: * match.pd (`MIN (X, Y) == X`): Extend to min/lt, min/ge, max/gt, max/le. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/minmaxcmp-1.c: New test. * gcc.dg/tree-ssa/minmaxcmp-2.c: New test. * gcc.dg/pr96708-negative.c: Update testcase. * gcc.dg/pr96708-positive.c: Add comment about `return 0`. --- gcc/match.pd | 8 +-- .../gcc.c-torture/execute/minmaxcmp-1.c | 51 +++++++++++++++++++ gcc/testsuite/gcc.dg/pr96708-negative.c | 4 +- gcc/testsuite/gcc.dg/pr96708-positive.c | 1 + gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-2.c | 30 +++++++++++ 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/minmaxcmp-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-2.c diff --git a/gcc/match.pd b/gcc/match.pd index 51985c1bad4..36e3da4841b 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3902,9 +3902,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (maxmin @0 (bit_not @1)))) /* MIN (X, Y) == X -> X <= Y */ -(for minmax (min min max max) - cmp (eq ne eq ne ) - out (le gt ge lt ) +/* MIN (X, Y) < X -> X > Y */ +/* MIN (X, Y) >= X -> X <= Y */ +(for minmax (min min min min max max max max) + cmp (eq ne lt ge eq ne gt le ) + out (le gt gt le ge lt lt ge ) (simplify (cmp:c (minmax:c @0 @1) @0) (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))) diff --git a/gcc/testsuite/gcc.c-torture/execute/minmaxcmp-1.c b/gcc/testsuite/gcc.c-torture/execute/minmaxcmp-1.c new file mode 100644 index 00000000000..6705a053768 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/minmaxcmp-1.c @@ -0,0 +1,51 @@ +#define func(vol, op1, op2) \ +_Bool op1##_##op2##_##vol (int a, int b) \ +{ \ + vol int x = op_##op1(a, b); \ + return op_##op2(x, a); \ +} + +#define op_lt(a, b) ((a) < (b)) +#define op_le(a, b) ((a) <= (b)) +#define op_eq(a, b) ((a) == (b)) +#define op_ne(a, b) ((a) != (b)) +#define op_gt(a, b) ((a) > (b)) +#define op_ge(a, b) ((a) >= (b)) +#define op_min(a, b) ((a) < (b) ? (a) : (b)) +#define op_max(a, b) ((a) > (b) ? (a) : (b)) + + +#define funcs(a) \ + a(min,lt) \ + a(max,lt) \ + a(min,gt) \ + a(max,gt) \ + a(min,le) \ + a(max,le) \ + a(min,ge) \ + a(max,ge) \ + a(min,ne) \ + a(max,ne) \ + a(min,eq) \ + a(max,eq) + +#define funcs1(a,b) \ +func(,a,b) \ +func(volatile,a,b) + +funcs(funcs1) + +#define test(op1,op2) \ +do { \ + if (op1##_##op2##_(x,y) != op1##_##op2##_volatile(x,y)) \ + __builtin_abort(); \ +} while(0); + +int main() +{ + for(int x = -10; x < 10; x++) + for(int y = -10; y < 10; y++) + { + funcs(test) + } +} diff --git a/gcc/testsuite/gcc.dg/pr96708-negative.c b/gcc/testsuite/gcc.dg/pr96708-negative.c index 91964d3b971..c9c1aa85558 100644 --- a/gcc/testsuite/gcc.dg/pr96708-negative.c +++ b/gcc/testsuite/gcc.dg/pr96708-negative.c @@ -42,7 +42,7 @@ int main() return 0; } -/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "optimized" } } */ -/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */ +/* Even though test[1-4] originally has MIN/MAX, those can be optimized away + into just comparing a and b arguments. */ /* { dg-final { scan-tree-dump-times "return 0;" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-not { "return 1;" } "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96708-positive.c b/gcc/testsuite/gcc.dg/pr96708-positive.c index 65af85344b6..12c5fedfd30 100644 --- a/gcc/testsuite/gcc.dg/pr96708-positive.c +++ b/gcc/testsuite/gcc.dg/pr96708-positive.c @@ -42,6 +42,7 @@ int main() return 0; } +/* Note main has one `return 0`. */ /* { dg-final { scan-tree-dump-times "return 0;" 3 "optimized" } } */ /* { dg-final { scan-tree-dump-times "return 1;" 2 "optimized" } } */ /* { dg-final { scan-tree-dump-not { "MAX_EXPR" } "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-2.c new file mode 100644 index 00000000000..f64a9253cfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmaxcmp-2.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ +/* PR tree-optimization/111364 */ + +#define min1(a, b) ((a) < (b) ? (a) : (b)) +#define max1(a, b) ((a) > (b) ? (a) : (b)) + +int minlt(int a, int b) +{ + return min1(a, b) < a; // b < a or a > b +} +/* { dg-final { scan-tree-dump "return a > b;|return b < a;" "original" } } */ + +int minge(int c, int d) +{ + return min1(c, d) >= c; // d >= c or c <= d +} +/* { dg-final { scan-tree-dump "return c <= d;|return d <= c;" "original" } } */ + +int maxgt(int e, int f) +{ + return max1(e, f) > e; // e > f or f < e +} +/* { dg-final { scan-tree-dump "return e < f;|return f > e;" "original" } } */ + +int maxle(int x, int y) +{ + return max1(x, y) <= x; // y <= x or x >= y +} +/* { dg-final { scan-tree-dump "return x >= y;|return y <= x;" "original" } } */ From patchwork Tue Sep 12 15:25:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 138274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp495516vqx; Tue, 12 Sep 2023 08:41:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXJPoLvc2RXziWcv+z1pkfMMr6Jif16jFELmDLP25U452PmtXTYj4Ulloqb7BeX7BIpWZc X-Received: by 2002:a17:906:31d8:b0:9a5:b814:8254 with SMTP id f24-20020a17090631d800b009a5b8148254mr10140669ejf.24.1694533268476; Tue, 12 Sep 2023 08:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694533268; cv=none; d=google.com; s=arc-20160816; b=A+ifRpBmZrJFc3UvSpe/ogqqYELTeZ0GV/k8/Oi0FG0YbR3P5r6nt8A/pLB7voXcV3 dGUVLlO7z8By/+3uOycCTWjP/Tt8+maRRrUv+HiqSPtxSHc+M3uMIjuh4usxlAeKj4af 5AmxwAjeIx2RuiLPNzXQSFAdL9VQfjznFbqXrcyxoVc8a1sX7WmyDoB85XnP9fb/DKF2 5DAZTcWvVXI0YgvH7RkLL7Qa45YjxiBWjqd2yM4nNlzjchm19WbXi4/VJzNV2IMKPdH5 K40DHni97x8Dw2A2gvishvQOq2L1+wMuNTH/i3CGHUOZZXdZhxPjR2dEeVUwI1UBNYTg 3dfA== 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=ujfIvN7hchX6OYrZV3iVlGisvE1JQxpzZFCd8qAdqHo=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=FWx68/oIPJv4MYT6jSqLi/2PcB9T4MXHBEi11sH2eSSlFKgI4s2M2bYu85zTzJr9xt /3Kc1TazABCCXr+3LRGAx/70GdMRWDij5DHa7+PoklfGfK776I+D0vp4QwZmo1wS99wL tqDUKrXxcHQhiecAZ8pT3UCgCHzepGZnC/5QrdcbnvkSDM6JzGqcv1/4Dg2f6wi7i/R7 +xKR4/tZec+EtMjtl/JK3fJRMZ2PxSDy31ABzspl64D8qPpmXw9FFmRfJ39KJO+4EamY 2m0zfxfUiWi7yrPhWTv4voDAgf9UM02drUeih6wJjxsFsRPKLeC9NP7oh+dLEaWHB7JN eJMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=a2gn4ny3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qu15-20020a170907110f00b0099b56bacec3si9106990ejb.955.2023.09.12.08.41.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 08:41:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=a2gn4ny3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 7D7E43899426 for ; Tue, 12 Sep 2023 15:32:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D7E43899426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694532764; bh=ujfIvN7hchX6OYrZV3iVlGisvE1JQxpzZFCd8qAdqHo=; 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=a2gn4ny3BAdEOeNPY1yqNEOJI/85UexgD5jEULusSKT6zRa95ftApXSVHsU9hE4ab lBXoWwqBsOpoVhQb0UZW6hPj2tCXUOJ/85+qVr2lrvxP/+JnX/AiusJR4jJLNMOdE5 7vtVvtVDrdkKakK/+nrI+2I+i45Np0tMrLCE/SWE= 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 AA6D438515C9 for ; Tue, 12 Sep 2023 15:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA6D438515C9 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 38C7K8ES031999 for ; Tue, 12 Sep 2023 08:25:57 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3t2kgesv4t-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 12 Sep 2023 08:25:57 -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; Tue, 12 Sep 2023 08:25:56 -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; Tue, 12 Sep 2023 08:25:56 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 9C8A63F7045; Tue, 12 Sep 2023 08:25:55 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/2] MATCH: Move `X <= MAX(X, Y)` before `MIN (X, C1) < C2` pattern Date: Tue, 12 Sep 2023 08:25:42 -0700 Message-ID: <20230912152542.1440800-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230912152542.1440800-1-apinski@marvell.com> References: <20230912152542.1440800-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: H0lxwctXnL2OZ8rP5SSCiLvTICjM5xgV X-Proofpoint-ORIG-GUID: H0lxwctXnL2OZ8rP5SSCiLvTICjM5xgV 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-12_14,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: 1776846916496693885 X-GMAIL-MSGID: 1776846916496693885 Since matching C1 as C2 here will decrease how much other simplifications will need to happen to get the final answer. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd (`X <= MAX(X, Y)`): Move before `MIN (X, C1) < C2` pattern. --- gcc/match.pd | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 36e3da4841b..34b67df784e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3931,13 +3931,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (wi::lt_p (wi::to_wide (@1), wi::to_wide (@2), TYPE_SIGN (TREE_TYPE (@0)))) (cmp @0 @2))))) -/* MIN (X, C1) < C2 -> X < C2 || C1 < C2 */ -(for minmax (min min max max min min max max ) - cmp (lt le gt ge gt ge lt le ) - comb (bit_ior bit_ior bit_ior bit_ior bit_and bit_and bit_and bit_and) - (simplify - (cmp (minmax @0 INTEGER_CST@1) INTEGER_CST@2) - (comb (cmp @0 @2) (cmp @1 @2)))) /* X <= MAX(X, Y) -> true X > MAX(X, Y) -> false @@ -3949,6 +3942,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp:c @0 (minmax:c @0 @1)) { constant_boolean_node (cmp == GE_EXPR || cmp == LE_EXPR, type); } )) +/* MIN (X, C1) < C2 -> X < C2 || C1 < C2 */ +(for minmax (min min max max min min max max ) + cmp (lt le gt ge gt ge lt le ) + comb (bit_ior bit_ior bit_ior bit_ior bit_and bit_and bit_and bit_and) + (simplify + (cmp (minmax @0 INTEGER_CST@1) INTEGER_CST@2) + (comb (cmp @0 @2) (cmp @1 @2)))) + /* Undo fancy ways of writing max/min or other ?: expressions, like a - ((a - b) & -(a < b)) and a - (a - b) * (a < b) into (a < b) ? b : a. People normally use ?: and that is what we actually try to optimize. */