[COMMITTED] range-ops: Calculate the popcount of a singleton.
Commit Message
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
@@ -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.
new file mode 100644
@@ -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" } }