diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2022-09-27 08:05:30 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2022-09-27 10:43:11 +0200 |
commit | be4a6551ed37c1e7dbdfb9400fc2e2b5d40c5be2 (patch) | |
tree | a6917d20d2b4d0c3b4a6abbc47c58b7495d48bf0 /gcc/value-range.cc | |
parent | 1db05e1a1c1ee3d8a95826d477173fb7c557c002 (diff) | |
download | gcc-be4a6551ed37c1e7dbdfb9400fc2e2b5d40c5be2.zip gcc-be4a6551ed37c1e7dbdfb9400fc2e2b5d40c5be2.tar.gz gcc-be4a6551ed37c1e7dbdfb9400fc2e2b5d40c5be2.tar.bz2 |
irange: keep better track of powers of 2.
When setting the nonzero bits to a mask containing only one bit, set
the range immediately, as it can be devined from the mask. This helps
us keep better track of powers of two.
For example, with this patch a nonzero mask of 0x8000 is set to a
range of [0,0][0x8000,0x8000] with a nonzero mask of 0x8000.
gcc/ChangeLog:
* value-range.cc (irange::set_nonzero_bits): Set range when known.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/popcount6.c: New test.
Diffstat (limited to 'gcc/value-range.cc')
-rw-r--r-- | gcc/value-range.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 754379a..6154d73 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -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)); } |