[1/3] Improve ssa_name_has_boolean_range slightly

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

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

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

Comments

Jeff Law Sept. 5, 2023, 6:58 a.m. UTC | #1
On 9/2/23 09:09, Andrew Pinski via Gcc-patches wrote:
> 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`.
OK
jeff
  

Patch

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;
     }