public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Add gimple_truth_valued_p to match.pd and use it
@ 2021-08-14  0:19 apinski
  2021-08-14  0:19 ` [PATCH 2/2] Fix 101805: Simplify min/max of boolean arguments apinski
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: apinski @ 2021-08-14  0:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

From: Andrew Pinski <apinski@marvell.com>

While working on some more boolean optimizations, I noticed
that there are places which does SSA_NAME@0 and then look
at then either use get_nonzero_bits or ssa_name_has_boolean_range
to see if the ssa name had a boolean range. This cleans this
up slightly by have a simple match pattern call gimple_truth_valued_p
which matches on SSA_NAME and checks ssa_name_has_boolean_range.
This is the first of the few cleanups I am going to do for
match and simplify and boolean related changes.

gcc/ChangeLog:

	* match.pd: New match, gimple_truth_valued_p.
	Use it for "{ 0 or 1 } * { 0 or 1 }",
	"X / bool_range_Y", and "-(type)!A" simplifcations.
---
 gcc/match.pd | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 5cc6a9fd41c..b1f2aaaac02 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -98,6 +98,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (define_operator_list COND_TERNARY
   IFN_COND_FMA IFN_COND_FMS IFN_COND_FNMA IFN_COND_FNMS)
 
+/* Match for a SSA_NAME which has a range of [0,1] */
+(match gimple_truth_valued_p
+ SSA_NAME@0
+ (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@0))))
+
 /* With nop_convert? combine convert? and view_convert? in one pattern
    plus conditionalize on tree_nop_conversion_p conversions.  */
 (match (nop_convert @0)
@@ -230,11 +235,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 } */
 (simplify
- (mult SSA_NAME@1 SSA_NAME@2)
-  (if (INTEGRAL_TYPE_P (type)
-       && get_nonzero_bits (@1) == 1
-       && get_nonzero_bits (@2) == 1)
-   (bit_and @1 @2)))
+ (mult gimple_truth_valued_p@1 gimple_truth_valued_p@2)
+  (bit_and @1 @2))
 
 /* Transform x * { 0 or 1, 0 or 1, ... } into x & { 0 or -1, 0 or -1, ...},
    unless the target has native support for the former but not the latter.  */
@@ -347,9 +349,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (negate @0)))
  /* X / bool_range_Y is X.  */ 
  (simplify
-  (div @0 SSA_NAME@1)
-  (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@1))
-   @0))
+  (div @0 gimple_truth_valued_p@1)
+   @0)
  /* X / X is one.  */
  (simplify
   (div @0 @0)
@@ -4207,12 +4208,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* -(type)!A -> (type)A - 1.  */
 (simplify
- (negate (convert?:s (logical_inverted_value:s @0)))
+ (negate (convert?:s (logical_inverted_value:s gimple_truth_valued_p@0)))
  (if (INTEGRAL_TYPE_P (type)
       && TREE_CODE (type) != BOOLEAN_TYPE
-      && TYPE_PRECISION (type) > 1
-      && TREE_CODE (@0) == SSA_NAME
-      && ssa_name_has_boolean_range (@0))
+      && TYPE_PRECISION (type) > 1)
   (plus (convert:type @0) { build_all_ones_cst (type); })))
 
 /* A + (B vcmp C ? 1 : 0) -> A - (B vcmp C ? -1 : 0), since vector comparisons
-- 
2.27.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-19  5:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14  0:19 [PATCH 1/2] Add gimple_truth_valued_p to match.pd and use it apinski
2021-08-14  0:19 ` [PATCH 2/2] Fix 101805: Simplify min/max of boolean arguments apinski
2021-08-16  6:29   ` Richard Biener
2021-09-19  5:56   ` Jeff Law
2021-08-16  6:22 ` [PATCH 1/2] Add gimple_truth_valued_p to match.pd and use it Richard Biener
2021-09-19  5:55 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).