public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH 4/7] Simplify fold_single_bit_test slightly
Date: Fri, 19 May 2023 19:14:48 -0700	[thread overview]
Message-ID: <20230520021451.1901275-5-apinski@marvell.com> (raw)
In-Reply-To: <20230520021451.1901275-1-apinski@marvell.com>

Now the only use of fold_single_bit_test is in do_store_flag,
we can change it such that to pass the inner arg and bitnum
instead of building a tree. There is no code generation changes
due to this change, only a decrease in GC memory that is produced
during expansion.

OK? Bootstrapped and tested on x86_64-linux.

gcc/ChangeLog:

	* expr.cc (fold_single_bit_test): Take inner and bitnum
	instead of arg0 and arg1. Update the code.
	(do_store_flag): Don't create a tree when calling
	fold_single_bit_test instead just call it with the bitnum
	and the inner tree.
---
 gcc/expr.cc | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index a61772b6808..67a9f82ca17 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -12899,23 +12899,19 @@ maybe_optimize_sub_cmp_0 (enum tree_code code, tree *arg0, tree *arg1)
 }
 \f
 
-/* If CODE with arguments ARG0 and ARG1 represents a single bit
+/* If CODE with arguments INNER & (1<<BITNUM) and 0 represents a single bit
    equality/inequality test, then return a simplified form of
    the test using shifts and logical operations.  Otherwise return
    NULL.  TYPE is the desired result type.  */
 
 static tree
 fold_single_bit_test (location_t loc, enum tree_code code,
-		      tree arg0, tree arg1, tree result_type)
+		      tree inner, int bitnum,
+		      tree result_type)
 {
-  /* If this is testing a single bit, we can optimize the test.  */
-  if ((code == NE_EXPR || code == EQ_EXPR)
-      && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
-      && integer_pow2p (TREE_OPERAND (arg0, 1)))
+  if ((code == NE_EXPR || code == EQ_EXPR))
     {
-      tree inner = TREE_OPERAND (arg0, 0);
-      tree type = TREE_TYPE (arg0);
-      int bitnum = tree_log2 (TREE_OPERAND (arg0, 1));
+      tree type = TREE_TYPE (inner);
       scalar_int_mode operand_mode = SCALAR_INT_TYPE_MODE (type);
       int ops_unsigned;
       tree signed_type, unsigned_type, intermediate_type;
@@ -13170,12 +13166,14 @@ do_store_flag (sepops ops, rtx target, machine_mode mode)
       if (srcstmt
 	  && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
 	{
+	  tree temp;
 	  enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR;
+	  int bitnum = tree_log2 (gimple_assign_rhs2 (srcstmt));
+
 	  type = lang_hooks.types.type_for_mode (mode, unsignedp);
-	  tree temp = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg1),
+	  temp = fold_single_bit_test (loc, tcode,
 				       gimple_assign_rhs1 (srcstmt),
-				       gimple_assign_rhs2 (srcstmt));
-	  temp = fold_single_bit_test (loc, tcode, temp, arg1, type);
+				       bitnum, type);
 	  if (temp)
 	    return expand_expr (temp, target, VOIDmode, EXPAND_NORMAL);
 	}
-- 
2.17.1


  parent reply	other threads:[~2023-05-20  2:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-20  2:14 [PATCH 0/7] Improve do_store_flag Andrew Pinski
2023-05-20  2:14 ` [PATCH 1/7] Move fold_single_bit_test to expr.cc from fold-const.cc Andrew Pinski
2023-05-20  4:43   ` Jeff Law
2023-05-20  2:14 ` [PATCH 2/7] Inline and simplify fold_single_bit_test_into_sign_test into fold_single_bit_test Andrew Pinski
2023-05-20  4:47   ` Jeff Law
2023-05-20  4:48   ` Jeff Law
2023-05-20  2:14 ` [PATCH 3/7] Use get_def_for_expr in fold_single_bit_test Andrew Pinski
2023-05-20  4:49   ` Jeff Law
2023-05-20  2:14 ` Andrew Pinski [this message]
2023-05-20  4:51   ` [PATCH 4/7] Simplify fold_single_bit_test slightly Jeff Law
2023-05-20  2:14 ` [PATCH 5/7] Simplify fold_single_bit_test with respect to code Andrew Pinski
2023-05-20  4:52   ` Jeff Law
2023-05-20  2:14 ` [PATCH 6/7] Use BIT_FIELD_REF inside fold_single_bit_test Andrew Pinski
2023-05-20  4:54   ` Jeff Law
2023-05-20  2:14 ` [PATCH 7/7] Expand directly for single bit test Andrew Pinski
2023-05-20  4: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=20230520021451.1901275-5-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).