Right now ssa_name_has_boolean_range compares the range to
range_true_and_false but instead we would get the nonzero bits and
compare that to 1 instead (<=u 1).
The nonzerobits comparison can be done in similar fashion.
Note I think get_nonzero_bits is redundant as the range queury will
return a more accurate version or the same value.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

        * tree-ssanames.cc (ssa_name_has_boolean_range): Improve
        using range's get_nonzero_bits and use `<=u 1`.
---
 gcc/tree-ssanames.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 6c362995c1a..7940d9954d8 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -535,10 +535,11 @@ ssa_name_has_boolean_range (tree op)
     {
       int_range<2> r;
       if (get_range_query (cfun)->range_of_expr (r, op)
-         && r == range_true_and_false (TREE_TYPE (op)))
+         && !r.undefined_p ()
+         && wi::leu_p (r.get_nonzero_bits (), 1))
        return true;
 
-      if (wi::eq_p (get_nonzero_bits (op), 1))
+      if (wi::leu_p (get_nonzero_bits (op), 1))
        return true;
     }
 
-- 
2.31.1

Reply via email to