public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH 1/2] Add gimple_truth_valued_p to match.pd and use it
Date: Fri, 13 Aug 2021 17:19:20 -0700	[thread overview]
Message-ID: <1628900361-27676-1-git-send-email-apinski@marvell.com> (raw)

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


             reply	other threads:[~2021-08-14  0:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-14  0:19 apinski [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1628900361-27676-1-git-send-email-apinski@marvell.com \
    --to=apinski@marvell.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).