Currently zero_one_valued_p uses tree_nonzero_bits which uses
the global ranges of the SSA Names. We can improve this via using
ssa_name_has_boolean_range which uses the local ranges
which are used while handling folding during VRP and other passes.

OK? Bootstrapped and tested on x86_64 with no regressions.

gcc/ChangeLog:

        * match.pd (zero_one_valued_p): Match SSA_NAMES where
        ssa_name_has_boolean_range returns true.
---
 gcc/match.pd | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index b94d71d2376..04033546fc1 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2063,6 +2063,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* zero_one_valued_p will match when a value is known to be either
    0 or 1 including constants 0 or 1.
    Signed 1-bits includes -1 so they cannot match here. */
+/* Note ssa_name_has_boolean_range uses
+   the current ranger while tree_nonzero_bits uses only
+   the global one. */
+(match zero_one_valued_p
+ SSA_NAME@0
+ (if (ssa_name_has_boolean_range (@0))))
 (match zero_one_valued_p
  @0
  (if (INTEGRAL_TYPE_P (type)
-- 
2.31.1

Reply via email to