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/107052] Range of __builtin_popcount can be improved with nonzerobits
Date: Tue, 27 Sep 2022 15:33:16 +0000	[thread overview]
Message-ID: <bug-107052-4-llrszZWpCe@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107052-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-09-27
                 CC|                            |amacleod at redhat dot com
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Don't you mean the only values for popcount are 0-2?  I mean, there are only
two bits that could be 1 with a mask of 0x300.  Or am I missing something?

Either way, your check is for b > 3, and we should be able to fold that away.

There are two problems here.  The cast of a_4 to a.0_1 dropped the nonzero
mask.  I would've expected that a cast to a number of the same precision would
keep the 0x300 mask, instead we have:

a.0_1 : [irange] unsigned int [0, 768] NONZERO 0x3ff

If we had the 0x300 mask available in cfn_popcount::fold_range(), then we could
fold it.  The second problem is that cfn_popcont, does not look at the nonzero
bits at all.

=========== BB 2 ============
Imports: a_3(D)  
Exports: a.0_1  a_3(D)  a_4  b_5  
         a.0_1 : a_3(D)(I)  a_4  
         a_4 : a_3(D)(I)  
         b_5 : a.0_1  a_3(D)(I)  a_4  
a_3(D)  [irange] int VARYING
    <bb 2> :
    a_4 = a_3(D) & 768;
    a.0_1 = (unsigned int) a_4;
    b_5 = __builtin_popcount (a.0_1);
    if (b_5 > 3)
      goto <bb 3>; [INV]
    else
      goto <bb 4>; [INV]

a.0_1 : [irange] unsigned int [0, 768] NONZERO 0x3ff
a_4 : [irange] int [0, 768] NONZERO 0x300
b_5 : [irange] int [0, 10] NONZERO 0xf
2->3  (T) a.0_1 :       [irange] unsigned int [0, 768] NONZERO 0x3ff
2->3  (T) a_4 :         [irange] int [0, 768] NONZERO 0x300
2->3  (T) b_5 :         [irange] int [4, 10] NONZERO 0xf
2->4  (F) a.0_1 :       [irange] unsigned int [0, 768] NONZERO 0x3ff
2->4  (F) a_4 :         [irange] int [0, 768] NONZERO 0x300
2->4  (F) b_5 :         [irange] int [0, 3] NONZERO 0x3

  parent reply	other threads:[~2022-09-27 15:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 15:18 [Bug tree-optimization/107052] New: " pinskia at gcc dot gnu.org
2022-09-27 15:18 ` [Bug tree-optimization/107052] " pinskia at gcc dot gnu.org
2022-09-27 15:24 ` pinskia at gcc dot gnu.org
2022-09-27 15:33 ` aldyh at gcc dot gnu.org [this message]
2022-09-27 15:36 ` pinskia at gcc dot gnu.org
2022-09-27 15:54 ` aldyh at gcc dot gnu.org
2022-09-27 16:22 ` aldyh at gcc dot gnu.org
2022-10-05 12:22 ` cvs-commit at gcc dot gnu.org
2022-10-05 12:22 ` cvs-commit at gcc dot gnu.org
2022-10-05 12:23 ` 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-107052-4-llrszZWpCe@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).