From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id CC38E385840A for ; Tue, 29 Aug 2023 07:34:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC38E385840A 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-x233.google.com with SMTP id 38308e7fff4ca-2b9f0b7af65so59825541fa.1 for ; Tue, 29 Aug 2023 00:34:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693294471; x=1693899271; 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=A/b+SrM08A8fUu87JaKJXg3uCtuW68WNo+VdDStecWk=; b=gPXap0PKwf9bBx/lAcks+Y4UzJJYPphbmDSnnl/VNarApTrbpXHKGFrOkt5w3HvMhp v1UQgCbWk3MUXkrjz4G+RNHjez5CcgLXFB9bO1PEqjqSRSDxgV9RiBNHFUs3eQ5kLNET u8p4jLKqjKTRurEGoQDqEUhI6GWJVhdIr75X1z8uAepv7Jz+l1dTzMstnx29kR+FyK3l RIVLOiN5DOocjJjNuomU1rtvZneOoW0QvMIEcvbs5p29MK30ol5f89CQJPz7KPaLTtbj Fg4h6Hx7DNEKOUlVnQ3Me2PWTZ+VFWPbKi5/JUZhO72PGy1ee32hv9vnJQJjvLdbE0LH Pw/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693294471; x=1693899271; 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=A/b+SrM08A8fUu87JaKJXg3uCtuW68WNo+VdDStecWk=; b=LKiaAW9J3RCAHgxm+2ZYDu07HpfpYGhLkwntrHBovDg76O0HmT7jrvrMuUbf3tgwHn adBlmmWbn70UfVGQUE8Vk8DdSoiXaST1ffuvaBxPaRXowa3U7q9jM0hXYilevXopmR4U jc4TA3nkgOp8EU184diig/emPznZpChlxgn8+RI55RAaxuZigw1q/EEr8XPOziAOhko7 b3E5MLl6Pga6JeV7eiq/uSwtfsVYTZrT4UlmNGjKuyHR7Iv1b4g9jTyZCqyX342WN4hE cq+1FwFfOhVUv+WjuLWfc7/Yf/W/vfIHRKuBOf4y1gfkkoJX/yBgPBmBCb+cTebM46IM M0rg== X-Gm-Message-State: AOJu0YwUi90DR459vtgXQNazH8YXwkqtdJb+pTkR05GRpKtgESz1ZqcP Pc8ZfOSM9OrcUqcuRghv4CXSUrZY4D5fOZ4A/8w= X-Google-Smtp-Source: AGHT+IEU8IsV2xirPuLvfSLeIc8NTZipWyOLPpKTNuV8EP9i4k/qRCWkIyX8tSbwfUoErxF7GHroI7lT1M9fv29+ySM= X-Received: by 2002:a2e:8747:0:b0:2bc:f118:7821 with SMTP id q7-20020a2e8747000000b002bcf1187821mr9332893ljj.29.1693294470812; Tue, 29 Aug 2023 00:34:30 -0700 (PDT) MIME-Version: 1.0 References: <20230828201402.3786409-1-apinski@marvell.com> In-Reply-To: <20230828201402.3786409-1-apinski@marvell.com> From: Richard Biener Date: Tue, 29 Aug 2023 09:32:51 +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.6 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 Mon, Aug 28, 2023 at 10:15=E2=80=AFPM Andrew Pinski via Gcc-patches wrote: > > This moves the match pattern `(x | y) & (~x ^ y)` over to use bitwise_inv= erted_equal_p. > This now also allows to optmize comparisons and also catches the missed `= (~x | y) & (x ^ y)` > transformation into `~x & y`. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK > gcc/ChangeLog: > > PR tree-optmization/111147 > * match.pd (`(x | y) & (~x ^ y)`) Use bitwise_inverted_equal_p > instead of matching bit_not. > > gcc/testsuite/ChangeLog: > > PR tree-optmization/111147 > * gcc.dg/tree-ssa/cmpbit-4.c: New test. > --- > gcc/match.pd | 7 +++- > gcc/testsuite/gcc.dg/tree-ssa/cmpbit-4.c | 47 ++++++++++++++++++++++++ > 2 files changed, 52 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cmpbit-4.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index e6bdc3149b6..47d2733211a 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1616,8 +1616,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > /* (x | y) & (~x ^ y) -> x & y */ > (simplify > - (bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0))) > - (bit_and @0 @1)) > + (bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 @2)) > + (with { bool wascmp; } > + (if (bitwise_inverted_equal_p (@0, @2, wascmp) > + && (!wascmp || element_precision (type) =3D=3D 1)) > + (bit_and @0 @1)))) > > /* (~x | y) & (x | ~y) -> ~(x ^ y) */ > (simplify > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-4.c b/gcc/testsuite/gcc= .dg/tree-ssa/cmpbit-4.c > new file mode 100644 > index 00000000000..cdba5d623af > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpbit-4.c > @@ -0,0 +1,47 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ > + > +int g(int x, int y) > +{ > + int xp =3D ~x; > + return (x | y) & (xp ^ y); // x & y > +} > +int g0(int x, int y) > +{ > + int xp =3D ~x; > + return (xp | y) & (x ^ y); // ~x & y > +} > + > +_Bool gb(_Bool x, _Bool y) > +{ > + _Bool xp =3D !x; > + return (x | y) & (xp ^ y); // x & y > +} > +_Bool gb0(_Bool x, _Bool y) > +{ > + _Bool xp =3D !x; > + return (xp | y) & (x ^ y); // !x & y > +} > + > + > +_Bool gbi(int a, int b) > +{ > + _Bool x =3D a < 2; > + _Bool y =3D b < 3; > + _Bool xp =3D !x; > + return (x | y) & (xp ^ y); // x & y > +} > +_Bool gbi0(int a, int b) > +{ > + _Bool x =3D a < 2; > + _Bool y =3D b < 3; > + _Bool xp =3D !x; > + return (xp | y) & (x ^ y); // !x & y > +} > + > +/* All of these should be optimized to `x & y` or `~x & y` */ > +/* { dg-final { scan-tree-dump-times "le_expr, " 3 "optimized" } } */ > +/* { dg-final { scan-tree-dump-times "gt_expr, " 1 "optimized" } } */ > +/* { dg-final { scan-tree-dump-not "bit_xor_expr, " "optimized" } } */ > +/* { dg-final { scan-tree-dump-times "bit_and_expr, " 6 "optimized" } } = */ > +/* { dg-final { scan-tree-dump-times "bit_not_expr, " 2 "optimized" } } = */ > -- > 2.31.1 >