From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>,
drepper@redhat.com, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] range-ops: Calculate the popcount of a singleton.
Date: Tue, 27 Sep 2022 17:01:31 +0200 [thread overview]
Message-ID: <20220927150131.3487543-1-aldyh@redhat.com> (raw)
The legacy popcount folding didn't actually fold singleton ranges.
I don't think anyone noticed because there are match.pd patterns that
pick up the slack using the global nonzero bits set by CCP.
It's good form to handle this, even without CCP's help.
Tested on x86-64 Linux.
p.s. This doesn't fix anything else in PR107043, except at
the first two testcases at -fno-tree-ccp, so nothing new.
gcc/ChangeLog:
* gimple-range-op.cc (cfn_popcount): Calculate the popcount of a
singleton.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/popcount6b.c: New test.
---
gcc/gimple-range-op.cc | 8 ++++++++
gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c | 6 ++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c
diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc
index d7c6dfa933d..3f5e5852e5a 100644
--- a/gcc/gimple-range-op.cc
+++ b/gcc/gimple-range-op.cc
@@ -397,6 +397,14 @@ public:
{
if (lh.undefined_p ())
return false;
+ // Calculating the popcount of a singleton is trivial.
+ if (lh.singleton_p ())
+ {
+ wide_int nz = lh.get_nonzero_bits ();
+ wide_int pop = wi::shwi (wi::popcount (nz), TYPE_PRECISION (type));
+ r.set (type, pop, pop);
+ return true;
+ }
// __builtin_ffs* and __builtin_popcount* return [0, prec].
int prec = TYPE_PRECISION (lh.type ());
// If arg is non-zero, then ffs or popcount are non-zero.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c
new file mode 100644
index 00000000000..90336ecb070
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c
@@ -0,0 +1,6 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-evrp -fno-tree-ccp" }
+
+#include "popcount6.c"
+
+// { dg-final { scan-tree-dump "return 1;" "evrp" } }
--
2.37.1
reply other threads:[~2022-09-27 15:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220927150131.3487543-1-aldyh@redhat.com \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=drepper@redhat.com \
--cc=gcc-patches@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).