From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id E14493858D28 for ; Mon, 28 Aug 2023 07:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E14493858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b9f0b7af65so42078141fa.1 for ; Mon, 28 Aug 2023 00:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693206379; x=1693811179; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WSDQpnc/MOdyj/pGAxc2kmPX+t19nIThV9bQOGsG90I=; b=bZm9oE3QcXgQa+Rx3KnqNkU6hj80djdcWr8tjC4sG83BvDM8UjkhDvuKf/OeWybFow 01CTynGWpQzAK/oMmECDtq14+NDu557xGK/baLVMqrNl26tfye7wO0w367B3KP6AXzkx 6TYe6t0MCF4u6m+w591NncaIjGMnx6mr8Lz7Vwy1IhfkZW/tT18pRks7RTR1PwBtrS0/ QXZCBlCG7dRQdwFPEjzf0bLxVesJi1y9k9uBNQFEp5SjuzNyCwPVwdLRMfSnWrvP3xtp KYU18s8gyqiKgn2+60gjIzfyw4vKRC/Kko6QgYRW0p8BS0hRzRQtLLNHxMlZb5mYv2pM o60w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693206379; x=1693811179; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WSDQpnc/MOdyj/pGAxc2kmPX+t19nIThV9bQOGsG90I=; b=WV8BeULDJRCknHJCOX5OP5j80iW6lM8UThfxTvjAAV0zC9T6m6480KLeeOMtO7GCe+ RyLZlCx9jAbFzimVsfk8AidTZ/tabP4egpaWpq90/P2SbPwdIIGZHRVc777qhR9YwP+a l8eg08obF9QDad9Cb+3sH6a5ilNei699KsHlDpJl7px6A2/5SaVE874sf5DdGV9Bh1c0 xMvijIjQsqPL5ajl+D3u+9cybglFJWL9iyK4lh6LZU+nHgiprwUQ/V/gTofgQcqnLMkK 5sAVUFSKYNGjvQyT1lG5zGakaFQZOqiJOp2RFH1eAVHsBnDMGr2Jp8md5vqsZoFC9C7L ZbKg== X-Gm-Message-State: AOJu0YzLaXaw/LWwxW5GAs+ShmSB4Hr++yCP7GHvsh1j1CBtbHn5ZdXj 5dJewdZV/QzZOsvjgEJpJmTcVQh0hiG/9YAak8FKFJnS X-Google-Smtp-Source: AGHT+IHT2BRm7zQWUEBRsZacZQikK1BqxXYa2wrCpoo57KC/zsnlyozRcgGZ2vVMgBN20PI+B2y/pY8CqOuwkWmJbsg= X-Received: by 2002:a2e:3016:0:b0:2b6:dc55:c3c7 with SMTP id w22-20020a2e3016000000b002b6dc55c3c7mr19455894ljw.20.1693206378659; Mon, 28 Aug 2023 00:06:18 -0700 (PDT) MIME-Version: 1.0 References: <20230825162122.3599370-1-apinski@marvell.com> In-Reply-To: <20230825162122.3599370-1-apinski@marvell.com> From: Richard Biener Date: Mon, 28 Aug 2023 09:04:38 +0200 Message-ID: Subject: Re: [PATCH] MATCH: Move `(X & ~Y) | (~X & Y)` over to use bitwise_inverted_equal_p To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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: On Fri, Aug 25, 2023 at 6:22=E2=80=AFPM Andrew Pinski via Gcc-patches wrote: > > This moves the pattern `(X & ~Y) | (~X & Y)` to use bitwise_inverted_equa= l_p > so we can simplify earlier the case where X and Y are defined by comparis= ons. > We were able to optimize to (!X)^(!Y) in the end due to the pattern added= in > r14-3110-g7fb65f102851248bafa0815 and the older pattern r13-4620-g4d9db4b= dd458 . > But folding it earlier is better. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. > Note pr87009.c now gets `return x ^ s; in one case where the test had bee= n expecting > `return s ^ x;` both are valid and would be expectly the same; just we no= w chose a slightly > different order of simplification which causes the order of the operands = to be different. > > gcc/ChangeLog: > > * match.pd (`(X & ~Y) | (~X & Y)`): Use bitwise_inverted_equal_p > instead of specifically checking for ~X. > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/cmpbit-3.c: New test. > * gcc.dg/pr87009.c: Update test. > --- > gcc/match.pd | 13 +++++----- > gcc/testsuite/gcc.dg/pr87009.c | 2 +- > gcc/testsuite/gcc.dg/tree-ssa/cmpbit-3.c | 33 ++++++++++++++++++++++++ > 3 files changed, 41 insertions(+), 7 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cmpbit-3.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index 70884bd48eb..e41403664d0 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1228,12 +1228,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > /* Simplify (X & ~Y) |^+ (~X & Y) -> X ^ Y. */ > (for op (bit_ior bit_xor plus) > (simplify > - (op (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1)) > - (bit_xor @0 @1)) > - (simplify > - (op:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1)) > - (if (~wi::to_wide (@2) =3D=3D wi::to_wide (@1)) > - (bit_xor @0 @1)))) > + (op (bit_and:c @0 @2) (bit_and:c @3 @1)) > + (with { bool wascmp0, wascmp1; } > + (if (bitwise_inverted_equal_p (@2, @1, wascmp0) > + && bitwise_inverted_equal_p (@0, @3, wascmp1) > + && ((!wascmp0 && !wascmp1) > + || element_precision (type) =3D=3D 1)) > + (bit_xor @0 @1))))) > > /* PR53979: Transform ((a ^ b) | a) -> (a | b) */ > (simplify > diff --git a/gcc/testsuite/gcc.dg/pr87009.c b/gcc/testsuite/gcc.dg/pr8700= 9.c > index eb8a4ecd920..6f0341d17cc 100644 > --- a/gcc/testsuite/gcc.dg/pr87009.c > +++ b/gcc/testsuite/gcc.dg/pr87009.c > @@ -1,6 +1,6 @@ > /* { dg-do compile } */ > /* { dg-options "-O -fdump-tree-original" } */ > -/* { dg-final { scan-tree-dump-times "return s \\^ x;" 4 "original" } } = */ > +/* { dg-final { scan-tree-dump-times "return s \\^ x;|return x \\^ s;" 4= "original" } } */ > > int f1 (int x, int s) > { > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-3.c b/gcc/testsuite/gcc= .dg/tree-ssa/cmpbit-3.c > new file mode 100644 > index 00000000000..936c0934a10 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-3.c > @@ -0,0 +1,33 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized-raw -fdump-tree-dse1-raw -fdu= mp-tree-forwprop1" } */ > + > +_Bool f(int a, int b) > +{ > + _Bool X =3D a=3D=3D1, Y =3D b =3D=3D 2; > +return (X & !Y) | (!X & Y); > +} > + > + > +_Bool f1(int a, int b) > +{ > + _Bool X =3D a=3D=3D1, Y =3D b =3D=3D 2; > + _Bool c =3D (X & !Y); > + _Bool d =3D (!X & Y); > + return c | d; > +} > + > +/* Both of these should be optimized to (a=3D=3D1) ^ (b=3D=3D2) or (a != =3D 1) ^ (b !=3D 2) */ > +/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */ > +/* { dg-final { scan-tree-dump-not "gimple_phi " "optimized" } } */ > +/* { dg-final { scan-tree-dump-times "ne_expr|eq_expr, " 4 "optimized" }= } */ > +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 2 "optimized" } } = */ > +/* { dg-final { scan-tree-dump-times "gimple_assign " 6 "optimized" } } = */ > + > +/* Both of these should be optimized early in the pipeline after forwpro= p1 */ > +/* { dg-final { scan-tree-dump-times "ne_expr|eq_expr, " 4 "forwprop1" {= xfail *-*-* } } } */ > +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 2 "forwprop1" { xf= ail *-*-* } } } */ > +/* { dg-final { scan-tree-dump-times "gimple_assign " 6 "forwprop1" { xf= ail *-*-* } } } */ > +/* Note forwprop1 does not remove all unused statements sometimes so tes= t dse1 also. */ > +/* { dg-final { scan-tree-dump-times "ne_expr|eq_expr, " 4 "dse1" } } */ > +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 2 "dse1" } } */ > +/* { dg-final { scan-tree-dump-times "gimple_assign " 6 "dse1" } } */ > -- > 2.31.1 >