From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 3D0983858D38 for ; Tue, 6 Jun 2023 21:07:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D0983858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 356K43OP024709 for ; Tue, 6 Jun 2023 14:07:44 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=nO5UYDrtrFTnyYfUjzPpKxuzhwV12CRm2/fWxmMLK7U=; b=Y0LoRcFteqp78DxVG7T3G84VMUITHuzpT1ME9EjdHb5REZ8U8yCvFioz14fZZZbp53Iv +ZTpugxCviGcwk5Ifp/inT0J3FO5pj9JwZFF7IWL/8yepZSGpHGXmsApwUC/aq9+FaEY PZ9k/bYns8r1pax7asr9o8y7hMzGgIFvYnPWduoeUnLaWEF/tXnMdoDI5j62P9acXe/w VrE/ORRHryXbANwDAOq2dbux554Xe8jOApZwlS+SwGbNTeMJr9zBIzuIZeTW8MZXxCrP TnXEL1fYBM2+PBLZdkC+Mv3ZXdE19SM3cUO5vqrHu4mYLHFU5kLgcoFCDgcr1Ir1Q15n wg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3r2a7brgqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 06 Jun 2023 14:07:43 -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, 6 Jun 2023 14:07: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; Tue, 6 Jun 2023 14:07:42 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id C1A7E3F705A; Tue, 6 Jun 2023 14:07:41 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] For the `-A CMP -B -> B CMP A` pattern allow EQ/NE for all integer types Date: Tue, 6 Jun 2023 14:07:10 -0700 Message-ID: <20230606210710.2992237-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: unAdcwAUbyzib2BNiBL_NOMxUaojSlE5 X-Proofpoint-GUID: unAdcwAUbyzib2BNiBL_NOMxUaojSlE5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-06_16,2023-06-06_02,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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: I noticed while looking at some code generation issue, that forwprop was not handling `-a == 0` for unsigned types and I was confused why it was not. r6-1814-g66e1cacf608045 removed these from fold because they were supposed to be already handled by the match.pd patterns but it was missed that the match.pd patterns checked TYPE_OVERFLOW_UNDEFINED while fold didn't do that for NE/EQ. This patch removes the restriction on NE/EQ on TYPE_OVERFLOW_UNDEFINED. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: PR tree-optimization/110134 * match.pd (-A CMP -B -> B CMP A): Allow EQ/NE for all integer types. (-A CMP CST -> B CMP (-CST)): Likewise. gcc/testsuite/ChangeLog: PR tree-optimization/110134 * gcc.dg/tree-ssa/negneq-1.c: New test. * gcc.dg/tree-ssa/negneq-2.c: New test. * gcc.dg/tree-ssa/negneq-3.c: New test. * gcc.dg/tree-ssa/negneq-4.c: New test. --- gcc/match.pd | 8 ++++++-- gcc/testsuite/gcc.dg/tree-ssa/negneq-1.c | 17 +++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/negneq-2.c | 17 +++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/negneq-3.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/negneq-4.c | 20 ++++++++++++++++++++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/negneq-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/negneq-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/negneq-3.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/negneq-4.c diff --git a/gcc/match.pd b/gcc/match.pd index 16482b741ea..f9cbd757752 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5896,13 +5896,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp (negate @0) (negate @1)) (if (FLOAT_TYPE_P (TREE_TYPE (@0)) || (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))) + && (cmp == EQ_EXPR + || cmp == NE_EXPR + || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))))) (scmp @0 @1))) (simplify (cmp (negate @0) CONSTANT_CLASS_P@1) (if (FLOAT_TYPE_P (TREE_TYPE (@0)) || (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))) + && (cmp == EQ_EXPR + || cmp == NE_EXPR + || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))))) (with { tree tem = const_unop (NEGATE_EXPR, TREE_TYPE (@0), @1); } (if (tem && !TREE_OVERFLOW (tem)) (scmp @0 { tem; })))))) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/negneq-1.c b/gcc/testsuite/gcc.dg/tree-ssa/negneq-1.c new file mode 100644 index 00000000000..94ff57d511b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/negneq-1.c @@ -0,0 +1,17 @@ +/* PR tree-optimization/110134 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +int fu(unsigned a) +{ + a = -a; + return a != 0; +} +int fs(signed a) +{ + a = -a; + return a != 0; +} + +/* We should have optimized out the a = -a; statements. */ +/* { dg-final { scan-tree-dump-not "= -a" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/negneq-2.c b/gcc/testsuite/gcc.dg/tree-ssa/negneq-2.c new file mode 100644 index 00000000000..9a3bb481ce4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/negneq-2.c @@ -0,0 +1,17 @@ +/* PR tree-optimization/110134 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +int fu(unsigned a) +{ + a = -a; + return a == 1; +} +int fs(signed a) +{ + a = -a; + return a == 1; +} + +/* We should have optimized out the a = -a; statements. */ +/* { dg-final { scan-tree-dump-not "= -a" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/negneq-3.c b/gcc/testsuite/gcc.dg/tree-ssa/negneq-3.c new file mode 100644 index 00000000000..14546a606c3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/negneq-3.c @@ -0,0 +1,20 @@ +/* PR tree-optimization/110134 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +int fu(unsigned a, unsigned b) +{ + a = -a; + b = -b; + return a == b; +} +int fs(signed a, signed b) +{ + a = -a; + b = -b; + return a == b; +} + +/* We should have optimized out the a = -; statements. */ +/* { dg-final { scan-tree-dump-not "= -a" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "= -b" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/negneq-4.c b/gcc/testsuite/gcc.dg/tree-ssa/negneq-4.c new file mode 100644 index 00000000000..1b66854acae --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/negneq-4.c @@ -0,0 +1,20 @@ +/* PR tree-optimization/110134 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ + +int fu(unsigned a, unsigned b) +{ + a = -a; + b = -b; + return a != b; +} +int fs(signed a, signed b) +{ + a = -a; + b = -b; + return a != b; +} + +/* We should have optimized out the a = -; statements. */ +/* { dg-final { scan-tree-dump-not "= -a" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "= -b" "optimized" } } */ -- 2.31.1