From patchwork Sat Aug 5 20:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 131546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp627436vqr; Sat, 5 Aug 2023 13:44:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpdP5xfPcFfZOUPlYiZMzkqqFrhloZgDcQSKSEGsGXQaeriU+Cl4ewcvoTdoytNqEA+BmR X-Received: by 2002:a2e:82c5:0:b0:2b9:f007:9910 with SMTP id n5-20020a2e82c5000000b002b9f0079910mr3715623ljh.53.1691268260702; Sat, 05 Aug 2023 13:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691268260; cv=none; d=google.com; s=arc-20160816; b=aT+y6qWLBhknB7tNtRxE0oQmtVjUSGDW5p2lBP9dSQ0c4wpp3p6mYFO/BYT52IiJYC By8JWoxFpqpbvSPfo8LQ9boYCsMOvduuv+UQs8BQSFx6DHhlsKDafvE/vI7XjGDdOyK5 VqCMSaS2vDzS2REn9kmw2SPQ6YtHgLv+aPAKPYMF/7ed8R99ToAjOOnBqA5+5Jt3uNP8 tMGI7LWlY53b8iy4yDKvE5j8aExezQBA0C3/sf9mOCP1vQrSYcy4kiF4U6F7FvU+GUtT nXvnexiKXPsnmyCsE/ZE2SJIGuUvT/Kwbi/cug4odUMp4ERVrsmbkpJUkJGER7ua9J6z JASQ== 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=xljNPM4I6rkf4yewy0JHfNC84xAvJph6FLrXhKCTeKQ=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=t7U8AP34i0BKA4xhZ8G7dK6GvC0UJHP6Uop+TR2McarxW8JRoN0Pi/4VX6zaEgL+aC 3RCbbUzuB8DfWh23lxOjkL8pe8INIhqKR5PNRfy/R9xjeif2V8D3Z+Utay37yDQBjwXa zSLyx0Z6ku8OBZfpqnT1TZbvBu11xkfSV69eZwtp3gBYXOX1hduCthQZYMlsDTwuB3UY 6Dhip/7L5ErZK0+C2x5OEFd0zir4vwOK8nwzkbhTZeDCI0CiJtaxbUBjwz5JpsVgGbe5 9y+WuOvt7H0tLkGl/JEWkri4LTS/ZvwTMvIiu0gvQ+OrT0Bz+k63N9NRNrwbdcoNKiO9 2amQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NCl32Nd9; 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 x20-20020a170906805400b00992c30f5887si3722553ejw.474.2023.08.05.13.44.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 13:44:20 -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=NCl32Nd9; 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 723943858C3A for ; Sat, 5 Aug 2023 20:44:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 723943858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691268259; bh=xljNPM4I6rkf4yewy0JHfNC84xAvJph6FLrXhKCTeKQ=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=NCl32Nd9QVumC5UEL8eOl8Ezenxsqt56FCJB4d2QLEEoFbWRDa1ETKlZGFeaKNmvq gCF/B993IgW5/KKc+XDmTSrl8lCMJuhLHlM23HRIRt9hYKM864rMybWmtcF6uWZYUa wqGxL+zCI4qJ2IY/prVmzhC9GKRthHlFEbPNiUUo= 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 DB8DF3858D1E for ; Sat, 5 Aug 2023 20:43:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB8DF3858D1E 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 375K0G6C010999 for ; Sat, 5 Aug 2023 13:43:35 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3s9kss8xct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 05 Aug 2023 13:43:35 -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; Sat, 5 Aug 2023 13:43:33 -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; Sat, 5 Aug 2023 13:43:33 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 875163F7050; Sat, 5 Aug 2023 13:43:33 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Extend min_value/max_value to pointer types Date: Sat, 5 Aug 2023 13:43:24 -0700 Message-ID: <20230805204324.2434846-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: lkmgaGKHb3WOEY5E-rFq6DZVOwbTJBZ8 X-Proofpoint-ORIG-GUID: lkmgaGKHb3WOEY5E-rFq6DZVOwbTJBZ8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-05_21,2023-08-03_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.29 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: 1773423307404583491 X-GMAIL-MSGID: 1773423307404583491 Since we already had the infrastructure to optimize `(x == 0) && (x > y)` to false for integer types, this extends the same to pointer types as indirectly requested by PR 96695. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/96695 * match.pd (min_value, max_value): Extend to pointer types too. gcc/testsuite/ChangeLog: PR tree-optimization/96695 * gcc.dg/pr96695-1.c: New test. * gcc.dg/pr96695-10.c: New test. * gcc.dg/pr96695-11.c: New test. * gcc.dg/pr96695-12.c: New test. * gcc.dg/pr96695-2.c: New test. * gcc.dg/pr96695-3.c: New test. * gcc.dg/pr96695-4.c: New test. * gcc.dg/pr96695-5.c: New test. * gcc.dg/pr96695-6.c: New test. * gcc.dg/pr96695-7.c: New test. * gcc.dg/pr96695-8.c: New test. * gcc.dg/pr96695-9.c: New test. --- gcc/match.pd | 6 ++++-- gcc/testsuite/gcc.dg/pr96695-1.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-10.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-11.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-12.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-2.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-3.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-4.c | 21 +++++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-5.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-6.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-7.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-8.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/pr96695-9.c | 20 ++++++++++++++++++++ 13 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr96695-1.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-10.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-11.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-12.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-2.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-3.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-4.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-5.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-6.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-7.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-8.c create mode 100644 gcc/testsuite/gcc.dg/pr96695-9.c diff --git a/gcc/match.pd b/gcc/match.pd index 2278029d608..de54b17abba 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2733,12 +2733,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (match min_value INTEGER_CST - (if (INTEGRAL_TYPE_P (type) + (if ((INTEGRAL_TYPE_P (type) + || POINTER_TYPE_P(type)) && wi::eq_p (wi::to_wide (t), wi::min_value (type))))) (match max_value INTEGER_CST - (if (INTEGRAL_TYPE_P (type) + (if ((INTEGRAL_TYPE_P (type) + || POINTER_TYPE_P(type)) && wi::eq_p (wi::to_wide (t), wi::max_value (type))))) /* x > y && x != XXX_MIN --> x > y diff --git a/gcc/testsuite/gcc.dg/pr96695-1.c b/gcc/testsuite/gcc.dg/pr96695-1.c new file mode 100644 index 00000000000..d4287ab4c8c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ + +#include + +_Bool and1(unsigned *x, unsigned *y) +{ + /* x > y && x != 0 --> x > y */ + return x > y && x != 0; +} + +_Bool and2(unsigned *x, unsigned *y) +{ + /* x < y && x != -1 --> x < y */ + return x < y && x != (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-10.c b/gcc/testsuite/gcc.dg/pr96695-10.c new file mode 100644 index 00000000000..dfe752526f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-10.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#include + +_Bool or1(unsigned *x, unsigned *y) +{ + /* x <= y || x != 0 --> true */ + return x <= y || x != 0; +} + +_Bool or2(unsigned *x, unsigned *y) +{ + /* x >= y || x != -1 --> true */ + return x >= y || x != (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " != " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " <= " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " >= " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-11.c b/gcc/testsuite/gcc.dg/pr96695-11.c new file mode 100644 index 00000000000..d3c36168b98 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-11.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ + +#include + +_Bool or1(unsigned *x, unsigned *y) +{ + /* x <= y || x == 0 --> x <= y */ + return x <= y || x == 0; +} + +_Bool or2(unsigned *x, unsigned *y) +{ + /* x >= y || x == -1 --> x >= y */ + return x >= y || x == (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " == " "ifcombine" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-12.c b/gcc/testsuite/gcc.dg/pr96695-12.c new file mode 100644 index 00000000000..9ce2ddf8a44 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-12.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-dce3" } */ + +#include + +_Bool or1(unsigned *x, unsigned *y) +{ + /* x <= y || x == 0 --> x <= y */ + return x <= y || x == 0; +} + +_Bool or2(unsigned *x, unsigned *y) +{ + /* x >= y || x == -1 --> x >= y */ + return x >= y || x == (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " == " "dce3" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-2.c b/gcc/testsuite/gcc.dg/pr96695-2.c new file mode 100644 index 00000000000..6d347c3b264 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-2.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#include + +_Bool and1(unsigned *x, unsigned *y) +{ + /* x > y && x != 0 --> x > y */ + return x > y && x != 0; +} + +_Bool and2(unsigned *x, unsigned *y) +{ + /* x < y && x != -1 --> x < y */ + return x < y && x != (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " != " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-3.c b/gcc/testsuite/gcc.dg/pr96695-3.c new file mode 100644 index 00000000000..b205b27dc8a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-3.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ + +#include + +_Bool and1(unsigned *x, unsigned *y) +{ + /* x > y && x == 0 --> false */ + return x > y && x == 0; +} + +_Bool and2(unsigned *x, unsigned *y) +{ + /* x < y && x == -1 --> false */ + return x < y && x == (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " == " "ifcombine" } } */ +/* { dg-final { scan-tree-dump-not " > " "ifcombine" } } */ +/* { dg-final { scan-tree-dump-not " < " "ifcombine" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-4.c b/gcc/testsuite/gcc.dg/pr96695-4.c new file mode 100644 index 00000000000..a5aa8de8dd0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-4.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#include + +_Bool and1(unsigned *x, unsigned *y) +{ + /* x > y && x == 0 --> false */ + return x > y && x == 0; +} + +_Bool and2(unsigned *x, unsigned *y) +{ + /* x < y && x == -1 --> false */ + return x < y && x == (unsigned*)-1; +} + + +/* { dg-final { scan-tree-dump-not " == " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " > " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " < " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-5.c b/gcc/testsuite/gcc.dg/pr96695-5.c new file mode 100644 index 00000000000..54d8f1a3a7e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-5.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ + +#include + +_Bool and1(unsigned *x, unsigned *y) +{ + /* x <= y && x == 0 --> x == 0 */ + return x <= y && x == 0; +} + +_Bool and2(unsigned *x, unsigned *y) +{ + /* x >= y && x == -1 --> x == -1 */ + return x >= y && x == (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */ +/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-6.c b/gcc/testsuite/gcc.dg/pr96695-6.c new file mode 100644 index 00000000000..15745246a89 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-6.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#include + +_Bool and1(unsigned *x, unsigned *y) +{ + /* x <= y && x == 0 --> x == 0 */ + return x <= y && x == 0; +} + +_Bool and2(unsigned *x, unsigned *y) +{ + /* x >= y && x == -1 --> x == -1 */ + return x >= y && x == (unsigned*)-1; +} + + +/* { dg-final { scan-tree-dump-not " <= " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " >= " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-7.c b/gcc/testsuite/gcc.dg/pr96695-7.c new file mode 100644 index 00000000000..7977ae12f81 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-7.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ + +#include + +_Bool or1(unsigned *x, unsigned *y) +{ + /* x > y || x != 0 --> x != 0 */ + return x > y || x != 0; +} + +_Bool or2(unsigned *x, unsigned *y) +{ + /* x < y || x != -1 --> x != -1 */ + return x < y || x != (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " > " "ifcombine" } } */ +/* { dg-final { scan-tree-dump-not " < " "ifcombine" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-8.c b/gcc/testsuite/gcc.dg/pr96695-8.c new file mode 100644 index 00000000000..ecda865f79f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-8.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#include + +_Bool or1(unsigned *x, unsigned *y) +{ + /* x > y || x != 0 --> x != 0 */ + return x > y || x != 0; +} + +_Bool or2(unsigned *x, unsigned *y) +{ + /* x < y || x != -1 --> x != -1 */ + return x < y || x != (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " > " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " < " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/pr96695-9.c b/gcc/testsuite/gcc.dg/pr96695-9.c new file mode 100644 index 00000000000..b87522c4635 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96695-9.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ifcombine" } */ + +#include + +_Bool or1(unsigned *x, unsigned *y) +{ + /* x <= y || x != 0 --> true */ + return x <= y || x != 0; +} + +_Bool or2(unsigned *x, unsigned *y) +{ + /* x >= y || x != -1 --> true */ + return x >= y || x != (unsigned*)-1; +} + +/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */ +/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */ +/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */