All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Dibyendu Majumdar <mobile@majumdar.org.uk>
Cc: linux-sparse@vger.kernel.org,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v2 6/8] transform (A & M) >> S to (A >> S) & (M >> S)
Date: Mon,  7 Aug 2017 21:12:03 +0200	[thread overview]
Message-ID: <20170807191205.86590-7-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170807191205.86590-1-luc.vanoostenryck@gmail.com>

This is especially usefull when simplifying code
accessing bitfields.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                 | 29 ++++++++++++++++++++++++++++-
 validation/bitfield-size.c |  4 +---
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/simplify.c b/simplify.c
index 9893613da..f1a898700 100644
--- a/simplify.c
+++ b/simplify.c
@@ -412,6 +412,32 @@ static int simplify_asr(struct instruction *insn, pseudo_t pseudo, long long val
 	return 0;
 }
 
+static int simplify_lsr(struct instruction *insn, pseudo_t pseudo, long long value)
+{
+	struct instruction *def;
+	unsigned long long mask;
+
+	if (!value)
+		return replace_with_pseudo(insn, pseudo);
+	switch (def_opcode(insn->src1)) {
+	case OP_AND:
+		// replace (A & M) >> S
+		// by      (A >> S) & (M >> S)
+		def = insn->src1->def;
+		if (!constant(def->src2))
+			break;
+		if (nbr_pseudo_users(insn->src1) > 1)
+			break;
+		mask = def->src2->value;
+		def->opcode = OP_LSR;
+		def->src2 = value_pseudo(value);
+		insn->opcode = OP_AND;
+		insn->src2 = value_pseudo(mask >> value);
+		return REPEAT_CSE;
+	}
+	return 0;
+}
+
 static int simplify_mul_div(struct instruction *insn, long long value)
 {
 	unsigned long long sbit = 1ULL << (insn->size - 1);
@@ -562,13 +588,14 @@ static int simplify_constant_rightside(struct instruction *insn)
 	case OP_ADD:
 	case OP_OR: case OP_XOR:
 	case OP_SHL:
-	case OP_LSR:
 	case_neutral_zero:
 		if (!value)
 			return replace_with_pseudo(insn, insn->src1);
 		return 0;
 	case OP_ASR:
 		return simplify_asr(insn, insn->src1, value);
+	case OP_LSR:
+		return simplify_lsr(insn, insn->src1, value);
 
 	case OP_MODU: case OP_MODS:
 		if (value == 1)
diff --git a/validation/bitfield-size.c b/validation/bitfield-size.c
index c8c94bb15..34400479a 100644
--- a/validation/bitfield-size.c
+++ b/validation/bitfield-size.c
@@ -36,8 +36,6 @@ unsigned int get_pbfi_b(struct bfi *bf) { return bf->b; }
  * check-output-ignore
  *
  * check-output-excludes: cast\\.4
- * check-output-pattern-6-times: cast\\.
  * check-output-pattern-6-times: lsr\\..*\\$6
- * check-output-pattern-6-times: and\\..*\\$15
- * check-output-pattern-6-times: and\\..*\\$960
+ * check-output-pattern-12-times: and\\..*\\$15
  */
-- 
2.13.2


  parent reply	other threads:[~2017-08-07 19:12 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28 12:40 Potential incorrect simplification Dibyendu Majumdar
2017-03-28 13:34 ` Luc Van Oostenryck
2017-03-28 13:58   ` Dibyendu Majumdar
2017-03-28 14:11     ` Luc Van Oostenryck
2017-03-28 14:19       ` Dibyendu Majumdar
2017-03-28 16:20         ` Linus Torvalds
2017-03-28 17:00           ` Luc Van Oostenryck
2017-03-28 18:02             ` Linus Torvalds
2017-03-28 20:27               ` Luc Van Oostenryck
2017-03-28 21:57                 ` Linus Torvalds
2017-03-28 22:28                   ` Luc Van Oostenryck
2017-03-28 22:22           ` Dibyendu Majumdar
2017-08-06 12:46           ` Christopher Li
2017-08-06 14:00             ` Luc Van Oostenryck
2017-08-06 14:24               ` Christopher Li
2017-08-06 14:54                 ` Christopher Li
2017-08-06 15:07                 ` Luc Van Oostenryck
2017-08-06 15:51                   ` Christopher Li
2017-08-06 16:51                     ` Luc Van Oostenryck
2017-08-06 18:35                       ` Christopher Li
2017-08-06 19:51                         ` Dibyendu Majumdar
2017-08-06 20:08                           ` Luc Van Oostenryck
2017-08-06 19:52                         ` Luc Van Oostenryck
2017-08-06 23:34                           ` Christopher Li
2017-08-07  0:31                             ` Luc Van Oostenryck
2017-08-07  0:38                               ` Christopher Li
2017-08-06 15:52                 ` Dibyendu Majumdar
2017-08-06 16:56                   ` Luc Van Oostenryck
2017-08-06 17:04                     ` Dibyendu Majumdar
2017-08-06 17:45                       ` Luc Van Oostenryck
2017-08-06 17:58                         ` Dibyendu Majumdar
2017-08-06 18:15                           ` Luc Van Oostenryck
2017-08-06 18:18                             ` Dibyendu Majumdar
2017-08-06 18:31                               ` Luc Van Oostenryck
2017-08-07 19:11                   ` [PATCH v2 0/8] fix loading of partially defined bitfield Luc Van Oostenryck
2017-08-07 19:11                     ` [PATCH v2 1/8] Remove single-store shortcut Luc Van Oostenryck
2017-08-07 21:42                       ` Linus Torvalds
2017-08-10  0:29                         ` Christopher Li
2017-08-10  0:41                           ` Luc Van Oostenryck
2017-08-10  0:53                             ` Christopher Li
2017-08-10 11:01                       ` Christopher Li
2017-08-10 12:26                         ` Luc Van Oostenryck
2017-08-10 13:25                           ` Christopher Li
2017-08-07 19:11                     ` [PATCH v2 2/8] new helper: def_opcode() Luc Van Oostenryck
2017-08-07 19:12                     ` [PATCH v2 3/8] reuse nbr_pseudo_users() Luc Van Oostenryck
2017-08-07 19:12                     ` [PATCH v2 4/8] change the masking when loading bitfields Luc Van Oostenryck
2017-08-07 19:12                     ` [PATCH v2 5/8] simplify ((A & M') | B ) & M when M' & M == 0 Luc Van Oostenryck
2017-08-07 19:12                     ` Luc Van Oostenryck [this message]
2017-08-08  0:22                       ` [PATCH v2 6/8] transform (A & M) >> S to (A >> S) & (M >> S) Christopher Li
2017-08-08  0:29                         ` Luc Van Oostenryck
2017-08-08  1:48                           ` Christopher Li
2017-08-08  1:00                         ` Linus Torvalds
2017-08-08  1:38                           ` Luc Van Oostenryck
2017-08-08  1:50                           ` Christopher Li
2017-08-07 19:12                     ` [PATCH v2 7/8] transform (A << S) >> S into A & (-1 " Luc Van Oostenryck
2017-08-07 21:54                       ` Linus Torvalds
2017-08-07 22:08                         ` Luc Van Oostenryck
2017-08-07 22:27                           ` Luc Van Oostenryck
2017-08-07 19:12                     ` [PATCH v2 8/8] fix: cast of OP_AND only valid if it's an OP_CAST Luc Van Oostenryck

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=20170807191205.86590-7-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=mobile@majumdar.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.