[PATCH 5/5] simplify '(x % 1)' into '0'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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

diff --git a/simplify.c b/simplify.c
index e3e5ff6e..9a6222c9 100644
--- a/simplify.c
+++ b/simplify.c
@@ -365,6 +365,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 f6dd7cb2..5d9b458e 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.10.2

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux