linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v3 5/5] simplify '(x % 1)' into '0'
Date: Tue,  7 Feb 2017 21:50:28 +0100	[thread overview]
Message-ID: <20170207205028.35869-6-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170207205028.35869-1-luc.vanoostenryck@gmail.com>

For completeness, add the dual simplification 'x * 1 => x'
for modulo: 'x % 1 => 0'.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                       | 5 +++++
 validation/optim/muldiv-by-one.c | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/simplify.c b/simplify.c
index 86d2f5da9..b0d229a92 100644
--- a/simplify.c
+++ b/simplify.c
@@ -361,6 +361,11 @@ static int simplify_constant_rightside(struct instruction *insn)
 	case OP_ASR:
 		return simplify_asr(insn, insn->src1, value);
 
+	case OP_MODU: case OP_MODS:
+		if (value == 1)
+			return replace_with_pseudo(insn, value_pseudo(0));
+		return 0;
+
 	case OP_DIVU: case OP_DIVS:
 	case OP_MULU: case OP_MULS:
 		return simplify_mul_div(insn, value);
diff --git a/validation/optim/muldiv-by-one.c b/validation/optim/muldiv-by-one.c
index f6dd7cb2c..5d9b458e0 100644
--- a/validation/optim/muldiv-by-one.c
+++ b/validation/optim/muldiv-by-one.c
@@ -5,6 +5,8 @@ si smul1(si a) {  return a * 1; }
 ui umul1(ui a) {  return a * 1; }
 si sdiv1(si a) {  return a / 1; }
 ui udiv1(ui a) {  return a / 1; }
+si smod1(si a) {  return a % 1; }
+ui umod1(ui a) {  return a % 1; }
 
 /*
  * check-name: muldiv-by-one
@@ -13,4 +15,5 @@ ui udiv1(ui a) {  return a / 1; }
  *
  * check-output-excludes: mul[us]\\.
  * check-output-excludes: div[us]\\.
+ * check-output-excludes: mod[us]\\.
  */
-- 
2.11.0


  parent reply	other threads:[~2017-02-07 20:53 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 15:46 [PATCH 0/5] more simplification of constant multiplicative ops Luc Van Oostenryck
2016-12-07 15:46 ` [PATCH 1/5] move OP_MUL simplification in a separate function Luc Van Oostenryck
2016-12-07 15:46 ` [PATCH 2/5] simplify '(x / 1)' to 'x' Luc Van Oostenryck
2017-02-07  2:53   ` Christopher Li
2017-02-07 14:52     ` Luc Van Oostenryck
2017-02-07 18:29       ` Christopher Li
2017-02-07 19:00         ` [PATCH v2 0/5] more simplification of constant multiplicative ops Luc Van Oostenryck
2017-02-07 19:00           ` [PATCH v2 1/5] move OP_MUL simplification in a separate function Luc Van Oostenryck
2017-02-07 19:00           ` [PATCH v2 2/5] simplify '(x / 1)' to 'x' Luc Van Oostenryck
2017-02-07 19:00           ` [PATCH v2 3/5] simplify '(x * -1)' to '-x' Luc Van Oostenryck
2017-02-07 19:00           ` [PATCH v2 4/5] simplify '(x / -1)' to '-x' (but only for signed division) Luc Van Oostenryck
2017-02-07 19:39             ` Rasmus Villemoes
2017-02-07 20:28               ` Luc Van Oostenryck
2017-02-07 20:33                 ` Christopher Li
2017-02-07 20:50                   ` [PATCH v3 0/5] more simplification of constant multiplicative ops Luc Van Oostenryck
2017-02-07 20:50                     ` [PATCH v3 1/5] move OP_MUL simplification in a separate function Luc Van Oostenryck
2017-02-07 20:50                     ` [PATCH v3 2/5] simplify '(x / 1)' to 'x' Luc Van Oostenryck
2017-02-07 20:50                     ` [PATCH v3 3/5] simplify '(x * -1)' to '-x' Luc Van Oostenryck
2017-02-07 20:50                     ` [PATCH v3 4/5] simplify '(x / -1)' to '-x' (but only for signed division) Luc Van Oostenryck
2017-02-07 20:50                     ` Luc Van Oostenryck [this message]
2017-02-07 19:00           ` [PATCH v2 5/5] simplify '(x % 1)' into '0' Luc Van Oostenryck
2017-02-07 19:18           ` [PATCH v2 0/5] more simplification of constant multiplicative ops Christopher Li
2016-12-07 15:46 ` [PATCH 3/5] simplify '(x * -1)' to '-x' Luc Van Oostenryck
2016-12-07 15:46 ` [PATCH 4/5] simplify '(x / -1)' to '-x' (but only for signed division) Luc Van Oostenryck
2016-12-07 15:46 ` [PATCH 5/5] simplify '(x % 1)' into '0' 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=20170207205028.35869-6-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=sparse@chrisli.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 NNTP newsgroup(s).