[2/3] MATCH: Improve zero_one_valued_p by using ssa_name_has_boolean_range

Message ID 20230902150957.845269-2-apinski@marvell.com
State Unresolved
Headers
Series [1/3] Improve ssa_name_has_boolean_range slightly |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Andrew Pinski Sept. 2, 2023, 3:09 p.m. UTC
  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(+)
  

Comments

Jeff Law Sept. 5, 2023, 6:59 a.m. UTC | #1
On 9/2/23 09:09, Andrew Pinski via Gcc-patches wrote:
> 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.
OK.  Presumably we're confident using a context sensitive range is 
always OK in here.

Jeff
  

Patch

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)