new file mode 100644
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-evrp" }
+
+int g(int n)
+{
+ n &= 0x8000;
+ if (n == 0)
+ return 1;
+ return __builtin_popcount(n);
+}
+
+// { dg-final { scan-tree-dump "return 1;" "evrp" } }
@@ -2930,6 +2930,19 @@ irange::set_nonzero_bits (const wide_int_ref &bits)
set_nonzero_bits (NULL);
return;
}
+ // If we have only one bit set in the mask, we can figure out the
+ // range immediately.
+ if (wi::popcount (bits) == 1)
+ {
+ bool has_zero = contains_p (build_zero_cst (type ()));
+ set (type (), bits, bits);
+ if (has_zero)
+ {
+ int_range<2> zero;
+ zero.set_zero (type ());
+ union_ (zero);
+ }
+ }
set_nonzero_bits (wide_int_to_tree (type (), bits));
}