public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Jeff Law <jlaw@ventanamicro.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [committed] [v2] More logical op simplifications in simplify-rtx.cc
Date: Tue, 11 Jun 2024 15:38:29 -0700	[thread overview]
Message-ID: <CA+=Sn1mK44xfKYgpsVcg-47QsFk+xBy=5bX9oY=9UKK=T3j4eQ@mail.gmail.com> (raw)
In-Reply-To: <d94eba4d-11bc-4502-8048-b5e571df0268@ventanamicro.com>

On Sat, May 25, 2024 at 11:42 AM Jeff Law <jlaw@ventanamicro.com> wrote:
>
> This is a revamp of what started as a target specific patch.
>
> Basically xalan (corrected, I originally thought it was perlbench) has a
> bitset implementation with a bit of an oddity.  Specifically setBit will
> clear the bit before it is set:
>
> >             if (bitToSet < 32)
> >             {
> >                 fBits1 &= ~mask;
> >                 fBits1 |= mask;
> >             }
> >              else
> >             {
> >                 fBits2 &= ~mask;
> >                 fBits2 |= mask;
> >             }
>
> We can clean this up pretty easily in RTL with a small bit of code in
> simplify-rtx.  While xalan doesn't have other cases, we can synthesize
> tests pretty easily and handle them as well.
>
>
> It turns out we don't actually have to recognize this stuff at the bit
> level, just standard logical identities are sufficient.  For example
>
> (X | Y) & ~Y -> X & ~Y
>
>
>
> Andrew P. might poke at this at the gimple level.  The type changes
> kindof get in the way in gimple but he's much better at match.pd than I
> am, so if he wants to chase it from the gimple side, I'll fully support
> that.

So we already have this pattern (without the type change) in gimple:
 /* (~x | y) & x -> x & y */
 /* (~x & y) | x -> x | y */
 (simplify
  (bitop:c (rbitop:c @2 @1) @0)
  (with { bool wascmp; }
   (if (bitwise_inverted_equal_p (@0, @2, wascmp)
        && (!wascmp || element_precision (type) == 1))
    (bitop @0 @1))))

The problem is bitwise_inverted_equal_p does not see that:
  c.0_4 = (signed char) _1;
  _5 = ~c.0_4;
  _16 = (charD.11) _5;

and
  c_11 = (charD.11) _1;

are bitwise inversions of each other.

I filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115449 to keep
track of this.

Thanks,
Andrew Pinski




>
> Bootstrapped and regression tested on x86.  Also run through my tester
> on its embedded targets.
>
> Pushing to the trunk.
>
> jeff
>

      reply	other threads:[~2024-06-11 22:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-25 18:42 Jeff Law
2024-06-11 22:38 ` Andrew Pinski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+=Sn1mK44xfKYgpsVcg-47QsFk+xBy=5bX9oY=9UKK=T3j4eQ@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jlaw@ventanamicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).