aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-range-op.cc8
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c6
2 files changed, 14 insertions, 0 deletions
diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc
index d7c6dfa..3f5e585 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 0000000..90336ec
--- /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" } }