From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 1FFFC3858408 for ; Mon, 17 Jul 2023 06:40:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FFFC3858408 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-pg1-x532.google.com with SMTP id 41be03b00d2f7-55c85b5321dso2328942a12.3 for ; Sun, 16 Jul 2023 23:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689576008; x=1692168008; 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=EUlKvFyIBRPx/uFbunoAV1i5xuEU++AnYW4iFt1uY1Y=; b=QbVcAVQhQ6/GyV6nDXv8Jd0+8Ujvx6aPqrHVe278T1UpJmjyEMylPfuLSoOpdy8Fsj dffwps/hxw7S1zU1pXvoSuYk3UXBHcpO5PkbBzh2QIlJV4ShHdVEwkruZUlg1067p1fO 0y8lYj2ZekkW1b5xdQpbn4FiTaioV/C+zcdr3buEnHQAZ+tiWwLp6GIKPddl+qha8WST x1lDmPYK4/ow+9s0fJimU7TeKvXE2XcQqrhsCBB/Cq+NTTv+h4H6f/2n17eGc2jDOv/L 9UUU5MMJEhKm1r/u6k7+ogNrsQBMemHADKIpJBsb1GHhhXrCmuLq6bFVeTSwgwuR01pY Hpvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689576008; x=1692168008; 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=EUlKvFyIBRPx/uFbunoAV1i5xuEU++AnYW4iFt1uY1Y=; b=gECshKfdaOIsxB8PyibA+h3+Rbq0gUlD66tavUZhtR6u2xxraoNDyq9u1Rl8owzWte SovsNZ9GwT5StEc4Ngjw1tM86YMCblrSFMh2aGUWxui5cbkr7PIB/cLsXkGwsfoxa69p 1g6ZcI0kIPB2K0tavs4L/p2trNiy+LhlJGbJo31a4YtfBkL9ugQ83PtEZmGyeqrNWap5 PKYC5Dts3J8yDzu6DSQl3QxDLrzitetTnpOJThFQd0QDs+xc5Kz7PeAYb5qlSK+epvVs 22ISxniB4DmqM3XuCmgSdS9QJnuFRrs55RBSMgBnkOwGoigOCp1qn5FRQ4h24LPHOSev 29Vw== X-Gm-Message-State: ABy/qLZ5S3LqXCAK/2AYxQc0Vm4EkSygo6uiqZmz6R+DON7Xn+ud9lUl 3x4pFZ7A5eRXFIK2GjjsOcq1dVBOPcKrbnsceC0= X-Google-Smtp-Source: APBJJlHXUnckRjusLQW/okD7BGVIQQi+nC1WDpV/xg2Qpe6lrFSHyHw0DrI52ASBsZRIFC6Ulb9gudSxny3udwEUx1Y= X-Received: by 2002:a17:90b:2284:b0:263:661e:e0dc with SMTP id kx4-20020a17090b228400b00263661ee0dcmr9601284pjb.25.1689576008013; Sun, 16 Jul 2023 23:40:08 -0700 (PDT) MIME-Version: 1.0 References: <20230717024247.1263484-1-apinski@marvell.com> In-Reply-To: <20230717024247.1263484-1-apinski@marvell.com> From: Richard Biener Date: Mon, 17 Jul 2023 08:39:36 +0200 Message-ID: Subject: Re: [PATCH] PR 95923: More (boolean) bitop simplifications in match.pd 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=-8.2 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,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: On Mon, Jul 17, 2023 at 4:43=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > This adds the boolean version of some of the simplifications > that were added with r8-4395-ge268a77b59cb78. > > That are the following: > (a | b) & (a =3D=3D b) --> a & b > a | (a =3D=3D b) --> a | (b ^ 1) > (a & b) | (a =3D=3D b) --> a =3D=3D b > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. Richard. > gcc/ChangeLog: > > PR tree-optimization/95923 > * match.pd ((a|b)&(a=3D=3Db),a|(a=3D=3Db),(a&b)|(a=3D=3Db)): New = transformation. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/95923 > * gcc.dg/tree-ssa/bitops-2.c: New test. > * gcc.dg/tree-ssa/bool-checks-1.c: New test. > --- > gcc/match.pd | 15 +++++++ > gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c | 41 +++++++++++++++++++ > gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c | 22 ++++++++++ > 3 files changed, 78 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index 351d9285e92..5e812d804d0 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1226,11 +1226,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1))) > (bit_and @0 @1)) > > +/* (a | b) & (a =3D=3D b) --> a & b (boolean version of the above). *= / > +(simplify > + (bit_and:c (bit_ior @0 @1) (nop_convert? (eq:c @0 @1))) > + (bit_and @0 @1)) > + > /* a | ~(a ^ b) --> a | ~b */ > (simplify > (bit_ior:c @0 (bit_not:s (bit_xor:c @0 @1))) > (bit_ior @0 (bit_not @1))) > > +/* a | (a =3D=3D b) --> a | (b^1) (boolean version of the above). */ > +(simplify > + (bit_ior:c @0 (nop_convert? (eq:c @0 @1))) > + (bit_ior @0 (bit_xor @1 { build_one_cst (type); }))) > + > /* (a | b) | (a &^ b) --> a | b */ > (for op (bit_and bit_xor) > (simplify > @@ -1242,6 +1252,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (bit_ior:c (bit_and:c @0 @1) (bit_not@2 (bit_xor @0 @1))) > @2) > > +/* (a & b) | (a =3D=3D b) --> a =3D=3D b */ > +(simplify > + (bit_ior:c (bit_and:c @0 @1) (nop_convert?@2 (eq @0 @1))) > + @2) > + > /* ~(~a & b) --> a | ~b */ > (simplify > (bit_not (bit_and:cs (bit_not @0) @1)) > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c b/gcc/testsuite/gcc= .dg/tree-ssa/bitops-2.c > new file mode 100644 > index 00000000000..d8128f3ca53 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c > @@ -0,0 +1,41 @@ > +/* { dg-do run } */ > +/* { dg-options "-O -fdump-tree-optimized-raw" } */ > + > +#define DECLS(n,VOL) \ > +__attribute__((noinline,noclone)) \ > +_Bool h##n(_Bool A,_Bool B){ \ > + VOL _Bool C =3D A | B; \ > + VOL _Bool D =3D A =3D=3D B; \ > + return C & D; \ > +} \ > +__attribute__((noinline,noclone)) \ > +_Bool i##n(_Bool A,_Bool B){ \ > + VOL _Bool C =3D A =3D=3D B; \ > + return A | C; \ > +} \ > +__attribute__((noinline,noclone)) \ > +_Bool k##n(_Bool A,_Bool B){ \ > + VOL _Bool C =3D A & B; \ > + VOL _Bool D =3D A =3D=3D B; \ > + return C | D; \ > +} \ > + > +DECLS(0,) > +DECLS(1,volatile) > + > +int main(){ > + for(int A =3D 0; A <=3D 1; ++A) > + for(int B =3D 0; B <=3D 1; ++B) > + { > + if (h0 (A, B) !=3D h1 (A, B)) __builtin_abort(); > + if (i0 (A, B) !=3D i1 (A, B)) __builtin_abort(); > + if (k0 (A, B) !=3D k1 (A, B)) __builtin_abort(); > + } > +} > + > +/* { dg-final { scan-tree-dump-times "bit_not_expr," 1 "optimized"} } */ > +/* { dg-final { scan-tree-dump-times "bit_and_expr," 3 "optimized"} } */ > +/* { dg-final { scan-tree-dump-times "bit_ior_expr," 4 "optimized"} } */ > +/* { dg-final { scan-tree-dump-times "eq_expr," 4 "optimized"} } */ > +/* { dg-final { scan-tree-dump-times "ne_expr," 7 "optimized"} } */ > +/* { dg-final { scan-tree-dump-not "bit_xor_expr," "optimized"} } */ > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c b/gcc/testsuit= e/gcc.dg/tree-ssa/bool-checks-1.c > new file mode 100644 > index 00000000000..370a23aad3e > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c > @@ -0,0 +1,22 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -fdump-tree-optimized-raw" } */ > +/* PR tree-optimization/95923 */ > + > +_Bool f(_Bool a, _Bool b) > +{ > + if (!a && !b) > + return 0; > + if (!a && b) > + return 0; > + if (a && !b) > + return 0; > + return 1; > +} > + > +/* { dg-final { scan-tree-dump-times "bit_and_expr," 1 "optimized"} } */ > +/* { dg-final { scan-tree-dump-not "bit_not_expr," "optimized"} } */ > +/* { dg-final { scan-tree-dump-not "bit_ior_expr," "optimized"} } */ > +/* { dg-final { scan-tree-dump-not "bit_xor_expr," "optimized"} } */ > +/* { dg-final { scan-tree-dump-not "eq_expr," "optimized"} } */ > +/* { dg-final { scan-tree-dump-not "ne_expr," "optimized"} } */ > +/* { dg-final { scan-tree-dump-not "gimple_cond" "optimized"} } */ > -- > 2.31.1 >