From patchwork Mon Nov 22 06:24:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 47986 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5719D3858430 for ; Mon, 22 Nov 2021 06:25:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5719D3858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637562334; bh=zKJS6ILXfpb0JS996eLBe1608P4W0m9Nn+A6o60VZv8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YlvJXiz49PijCBP4+1K2p44QEh5FUU7bltMRyfTDcxQjDr9MYpHwf03SrH2HGlQP0 JAtoIe1c0RLhN2t9jI4ws9RWDI+3TTWgp0h3Bjwx0J4iJxpPZzDXHBhHsI93d5q/gK fVqXf7TGCjlBpIMk3b02ACrAEXyaOnYgCfXhBWKw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 8D0D43858406 for ; Mon, 22 Nov 2021 06:25:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D0D43858406 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1AM63uT8030441 for ; Sun, 21 Nov 2021 22:25:02 -0800 Received: from dc6wp-exch01.marvell.com ([4.21.29.232]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3cg5m181p1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 21 Nov 2021 22:25:02 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC6WP-EXCH01.marvell.com (10.76.176.21) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 22 Nov 2021 01:24:55 -0500 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.2; Sun, 21 Nov 2021 22:24:53 -0800 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.18 via Frontend Transport; Sun, 21 Nov 2021 22:24:53 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id AE3023F7040; Sun, 21 Nov 2021 22:24:53 -0800 (PST) To: Subject: [PATCH 1/2] Improve/Fix (m1 CMP m2) * d -> (m1 CMP m2) ? d : 0 pattern. Date: Sun, 21 Nov 2021 22:24:49 -0800 Message-ID: <1637562290-15155-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: IKinpn8UvG4HWVjAkTTXP43EjkKZjNas X-Proofpoint-ORIG-GUID: IKinpn8UvG4HWVjAkTTXP43EjkKZjNas X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-22_02,2021-11-22_01,2020-04-07_01 X-Spam-Status: No, score=-14.7 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski The pattern here was not catching all comparisons and the multiply was not commutative when it should have been. This patches fixes that by using tcc_comparison and adding :c to the multiply. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd ((m1 CMP m2) * d -> (m1 CMP m2) ? d : 0): Use tcc_comparison and :c for the multiply. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/multcmp-1.c: New test. * gcc.dg/tree-ssa/multcmp-2.c: New test. --- gcc/match.pd | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c | 12 ++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c diff --git a/gcc/match.pd b/gcc/match.pd index ca6c9eff624..ed43c321cbc 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1791,9 +1791,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (m1 CMP m2) * d -> (m1 CMP m2) ? d : 0 */ (if (!canonicalize_math_p ()) - (for cmp (gt lt ge le) + (for cmp (tcc_comparison) (simplify - (mult (convert (cmp @0 @1)) @2) + (mult:c (convert (cmp @0 @1)) @2) (cond (cmp @0 @1) @2 { build_zero_cst (type); })))) /* For integral types with undefined overflow and C != 0 fold diff --git a/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c new file mode 100644 index 00000000000..fb44cacde77 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int +f (int m1, int m2, int c) +{ + int d = m1 == m2; + int e = d * c; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c new file mode 100644 index 00000000000..be38b2e0044 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int +f (int m1, int m2, int c) +{ + int d = m1 != m2; + int e = c * d; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ From patchwork Mon Nov 22 06:24:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 47987 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B91A73858426 for ; Mon, 22 Nov 2021 06:26:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B91A73858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637562390; bh=PnJQUcQ0Qk7kwWVDmV+rf4+qawn21LsTAotcJXEjAI4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Hx8iPE2khwb0jPFLhdGcRL3x4Os2xhpcKdf+3C7W9dPDyRqWLm8JUsE+iGLBammxC vYmx82cIdI08G6vs6MDEanvEg8/v280qSt/k8OT/OeqcE2Z4cytt82FYYg67KhLYuI gS2zONNnUPgCQohDd1CEV39tihOyFFGePfbgsRbg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 8D2223858411 for ; Mon, 22 Nov 2021 06:25:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D2223858411 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1AM63uT9030441 for ; Sun, 21 Nov 2021 22:25:03 -0800 Received: from dc6wp-exch01.marvell.com ([4.21.29.232]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3cg5m181p1-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 21 Nov 2021 22:25:03 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC6WP-EXCH01.marvell.com (10.76.176.21) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 22 Nov 2021 01:24:55 -0500 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.18; Sun, 21 Nov 2021 22:24:54 -0800 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.18 via Frontend Transport; Sun, 21 Nov 2021 22:24:54 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 097B33F7041; Sun, 21 Nov 2021 22:24:53 -0800 (PST) To: Subject: [PATCH 2/2] tree-optimization: [PR92342] Move b & -(a==c) optimization to the gimple level Date: Sun, 21 Nov 2021 22:24:50 -0800 Message-ID: <1637562290-15155-2-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1637562290-15155-1-git-send-email-apinski@marvell.com> References: <1637562290-15155-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: DZeKEPCApYxImw4CSIlUadTNM798RmMy X-Proofpoint-ORIG-GUID: DZeKEPCApYxImw4CSIlUadTNM798RmMy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-22_02,2021-11-22_01,2020-04-07_01 X-Spam-Status: No, score=-14.7 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski Combine disabled this optimization in r10-254-gddbb5da5199fb42 but it makes sense to do this on the gimple level and then let expand decide which way is better. So this adds the transformation on the gimple level (late like was done for the multiply case). OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/92342 gcc/ChangeLog: * match.pd (b & -(a CMP c) -> (a CMP c)?b:0): New pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/andnegcmp-1.c: New test. * gcc.dg/tree-ssa/andnegcmp-2.c: New test. --- gcc/match.pd | 8 +++++++- gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c | 14 ++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c diff --git a/gcc/match.pd b/gcc/match.pd index ed43c321cbc..b55cbc91b57 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1794,7 +1794,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for cmp (tcc_comparison) (simplify (mult:c (convert (cmp @0 @1)) @2) - (cond (cmp @0 @1) @2 { build_zero_cst (type); })))) + (cond (cmp @0 @1) @2 { build_zero_cst (type); })) +/* (-(m1 CMP m2)) & d -> (m1 CMP m2) ? d : 0 */ + (simplify + (bit_and:c (negate (convert (cmp @0 @1))) @2) + (cond (cmp @0 @1) @2 { build_zero_cst (type); })) + ) +) /* For integral types with undefined overflow and C != 0 fold x * C EQ/NE y * C into x EQ/NE y. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c new file mode 100644 index 00000000000..6f16783f169 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/92342 */ + +int +f (int m1, int m2, int c) +{ + int d = m1 == m2; + d = -d; + int e = d & c; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c new file mode 100644 index 00000000000..0e25c8abc39 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/92342 */ + +int +f (int m1, int m2, int c) +{ + int d = m1 < m2; + d = -d; + int e = c & d; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */