public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aldyh at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/107043] range information not used in popcount
Date: Tue, 27 Sep 2022 14:29:01 +0000	[thread overview]
Message-ID: <bug-107043-4-skSq8ApXfg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107043-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107043

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aldyh at gcc dot gnu.org

--- Comment #3 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)

> int g1(int n)
> {
>   int n1 = n & 0x8000;
>   if (n1 == 0)
>     return 1;
>   // n>>15 will be xxxxxx1 here.
>   return (n >> 15) & 0x1;
> }

Interestingly, getting this one requires us to track something completely
different, the bits that are *definitely* set.

[Right now we track the nonzero mask, which is a misnomer because we're not
tracking bits are nonzero but the bits that *may* be nonzero.  Or more
precisely the inverse of the bits that are known to be 0.  For example, a
"nonzero" mask of 0xfffffff0 means the least significant 8 bits are known to be
zero, and the rest of the bits are unknown.  So we're tracking the "and mask"
of a number?  Or the maybe_nonzero bits?  The reason for the name is because
legacy VRP had this name.]

To get the above, we'd need to track the bits that are definitely 1 (the "or
mask" of a number?).  For example, on the 2->4 edge we'd need to know that n_3
has the 0x8000 bit set:

  <bb 2> :
  n1_4 = n_3(D) & 32768;
  if (n1_4 == 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  goto <bb 5>; [INV]

  <bb 4> :
  _1 = n_3(D) >> 15;
  _5 = _1 & 1;

  <bb 5> :
  # _2 = PHI <1(3), _5(4)>
  return _2;

What we're looking for is solving n_3:

[not-zero] = n_3 & 32768

which should give us:

[-INF,-1][32768, +INF] ORMASK [0x8000]

or whatever the hell we want to call it.  I hate these names.  Please someone,
come up with a name that makes sense to us all!

Andrew M and I had a plan for this earlier this cycle, but got sidetracked by
floats.  What we'd need is a way to track or-mask's in addition to and-masks.

There's actual infrastructure missing here, but it should be as easy as what we
did for "nonzero" tracking in commit 4e82205b68024f5c1a9006fe2b62e1a0fa7f1245
(plus supporting patches).  Basically we need to add a slot for the or-mask in
the irange, add union/intersect code, and then add some glue in range-ops to
solve:

1 = x & mask
x = y | mask
etc etc.

Thanks for the testcase, it's quite useful.

  parent reply	other threads:[~2022-09-27 14:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 20:10 [Bug tree-optimization/107043] New: " drepper.fsp+rhbz at gmail dot com
2022-09-26 20:27 ` [Bug tree-optimization/107043] " pinskia at gcc dot gnu.org
2022-09-27 10:19 ` drepper.fsp+rhbz at gmail dot com
2022-09-27 14:29 ` aldyh at gcc dot gnu.org [this message]
2022-09-27 15:22 ` jakub at gcc dot gnu.org
2023-07-12 21:16 ` cvs-commit at gcc dot gnu.org
2023-07-12 21:19 ` aldyh at gcc dot gnu.org

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=bug-107043-4-skSq8ApXfg@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).