From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id CCAB43858D1E for ; Tue, 3 Jan 2023 13:17:04 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=p32GStGXlM6sE5WMoIg7PkL7MIpo+NTDI5FOctddCUk=; b=LZNsCzYXjHJ+/khDoVikn2SPKx so2xlUTQDTi87664BqX0rlRtSxLepzvQcc7Uv3jlKRjMOIxWJ3/HOG+Ol/cBHAJvyxQlLKu4ZuUK+ 2C8v3Gf5WdMPLRULIwcLlKvCUzLeBrydDZR2SdfFcnYr2FkImURjbusDo99gkY4NXKv6rWpYHpsrl Up/LxSMrMEZSqfokVAOZaAqkfdDoHsou7Q7hXjwj1Anc+YjD02ML/9t6vUSvfOnFxbdBsyCG8pWzO PhUIbB/RPVDmNEhgK2MJ99jSrZpXYJgBGPmIucOeWS0WZnYJgkYt/e+y3BnPVLBgzwyJ+ZKCJvJ5T oxQ2r+8g==; Received: from [185.62.158.67] (port=63948 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pChA8-0002j0-24; Tue, 03 Jan 2023 08:17:04 -0500 From: "Roger Sayle" To: "'GCC Patches'" , "'Andrew Pinski'" Cc: "'Richard Biener'" Subject: [PATCH] PR tree-optimization/92342: Optimize b & -(a==c) in match.pd Date: Tue, 3 Jan 2023 13:17:02 -0000 Message-ID: <009101d91f75$ac187920$04496b60$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0092_01D91F75.AC187920" X-Mailer: Microsoft Outlook 16.0 Content-Language: en-gb Thread-Index: AdkfdOGNFPhRdOOjSBC+iQd8M4hkcA== X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 List-Id: This is a multipart message in MIME format. ------=_NextPart_000_0092_01D91F75.AC187920 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch is an update/tweak of Andrew Pinski's two patches for PR tree-optimization/92342, that were originally posted back in November: https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585111.html https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585112.html Technically, the first of those was approved by Richard Biener, though never committed, and my first thought was to simply push it for Andrew, but the review of the second piece expressed concerns over comparisons in non-integral modes, where the result may not be zero-one valued. Indeed both transformations misbehave in the presence of vector mode comparisons (these transformations are already implemented for vec_cond elsewhere in match.pd), so my minor contribution is to limit these new transformations to scalars, by testing that both the operands and results are INTEGRAL_TYPE_P. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32}, with no new failures. Ok for mainline? 2023-01-03 Andrew Pinski Roger Sayle gcc/ChangeLog: PR tree-optimization/92342 * match.pd ((m1 CMP m2) * d -> (m1 CMP m2) ? d : 0): Use tcc_comparison and :c for the multiply. (b & -(a CMP c) -> (a CMP c)?b:0): New pattern. gcc/testsuite/ChangeLog: PR tree-optimization/92342 * gcc.dg/tree-ssa/andnegcmp-1.c: New test. * gcc.dg/tree-ssa/andnegcmp-2.c: New test. * gcc.dg/tree-ssa/multcmp-1.c: New test. * gcc.dg/tree-ssa/multcmp-1.c: New test. Thanks in advance (and thanks to Andrew). Roger -- ------=_NextPart_000_0092_01D91F75.AC187920 Content-Type: text/plain; name="patchap2.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchap2.txt" diff --git a/gcc/match.pd b/gcc/match.pd=0A= index 697d8de..2e1f113 100644=0A= --- a/gcc/match.pd=0A= +++ b/gcc/match.pd=0A= @@ -2076,10 +2076,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)=0A= =0A= /* (m1 CMP m2) * d -> (m1 CMP m2) ? d : 0 */=0A= (if (!canonicalize_math_p ())=0A= - (for cmp (gt lt ge le)=0A= + (for cmp (tcc_comparison)=0A= (simplify=0A= - (mult (convert (cmp @0 @1)) @2)=0A= - (cond (cmp @0 @1) @2 { build_zero_cst (type); }))))=0A= + (mult:c (convert (cmp@0 @1 @2)) @3)=0A= + (if (INTEGRAL_TYPE_P (type)=0A= + && INTEGRAL_TYPE_P (TREE_TYPE (@0)))=0A= + (cond @0 @3 { build_zero_cst (type); })))=0A= +/* (-(m1 CMP m2)) & d -> (m1 CMP m2) ? d : 0 */=0A= + (simplify=0A= + (bit_and:c (negate (convert (cmp@0 @1 @2))) @3)=0A= + (if (INTEGRAL_TYPE_P (type)=0A= + && INTEGRAL_TYPE_P (TREE_TYPE (@0)))=0A= + (cond @0 @3 { build_zero_cst (type); })))=0A= + )=0A= +)=0A= =0A= /* For integral types with undefined overflow and C !=3D 0 fold=0A= x * C EQ/NE y * C into x EQ/NE y. */=0A= diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c = b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c=0A= new file mode 100644=0A= index 0000000..6f16783=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c=0A= @@ -0,0 +1,14 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2 -fdump-tree-optimized" } */=0A= +/* PR tree-optimization/92342 */=0A= +=0A= +int=0A= +f (int m1, int m2, int c)=0A= +{=0A= + int d =3D m1 =3D=3D m2;=0A= + d =3D -d;=0A= + int e =3D d & c;=0A= + return e;=0A= +}=0A= +=0A= +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 = "optimized" } } */=0A= diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c = b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c=0A= new file mode 100644=0A= index 0000000..0e25c8a=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c=0A= @@ -0,0 +1,14 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2 -fdump-tree-optimized" } */=0A= +/* PR tree-optimization/92342 */=0A= +=0A= +int=0A= +f (int m1, int m2, int c)=0A= +{=0A= + int d =3D m1 < m2;=0A= + d =3D -d;=0A= + int e =3D c & d;=0A= + return e;=0A= +}=0A= +=0A= +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 = "optimized" } } */=0A= diff --git a/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c = b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c=0A= new file mode 100644=0A= index 0000000..fb44cac=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c=0A= @@ -0,0 +1,12 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2 -fdump-tree-optimized" } */=0A= +=0A= +int=0A= +f (int m1, int m2, int c)=0A= +{=0A= + int d =3D m1 =3D=3D m2;=0A= + int e =3D d * c;=0A= + return e;=0A= +}=0A= +=0A= +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 = "optimized" } } */=0A= diff --git a/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c = b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c=0A= new file mode 100644=0A= index 0000000..be38b2e=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c=0A= @@ -0,0 +1,12 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2 -fdump-tree-optimized" } */=0A= +=0A= +int=0A= +f (int m1, int m2, int c)=0A= +{=0A= + int d =3D m1 !=3D m2;=0A= + int e =3D c * d;=0A= + return e;=0A= +}=0A= +=0A= +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 = "optimized" } } */=0A= ------=_NextPart_000_0092_01D91F75.AC187920--