Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH] TRUNC(x) {==,!=} C --> AND(x,M) {==,!=} C
Date: Sun, 18 Apr 2021 21:41:35 +0200	[thread overview]
Message-ID: <20210418194135.56287-1-luc.vanoostenryck@gmail.com> (raw)

It's not 100% clear than this is indeed a simplification but:
1) from a pure instruction count point of view, it doesn't make
   things worst
2) in most place where it applies, the masking is made redundant
   and is thus eliminated

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/simplify.c b/simplify.c
index 9e3514d838a9..faf769b2f3cf 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1392,6 +1392,19 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
 			break;
 		}
 		break;
+	case OP_TRUNC:
+		osize = def->orig_type->bit_size;
+		switch (insn->opcode) {
+		case OP_SET_EQ: case OP_SET_NE:
+			if (one_use(def->target)) {
+				def->type = def->orig_type;
+				def->size = osize;
+				def->src2 = value_pseudo(bits);
+				return replace_opcode(def, OP_AND);
+			}
+			break;
+		}
+		break;
 	case OP_ZEXT:
 		osize = def->orig_type->bit_size;
 		bits = bits_mask(osize);
-- 
2.31.1


                 reply	other threads:[~2021-04-18 19:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210418194135.56287-1-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.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).