[PATCH 14/16] cmp: simplify zext(x) cmps C

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

 



A signed compare of a zero-extended value against a constant
outside of the original range is statically known.

Simplify to the corresponding 0/1.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                       | 14 ++++++++++++++
 validation/optim/cmp-zext-simm.c |  1 -
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/simplify.c b/simplify.c
index 8a8b39b81e20..83ae763eac72 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1185,6 +1185,20 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
 			insn->itype = def->orig_type;
 			return replace_pseudo(insn, &insn->src1, def->src);
 		}
+		switch (insn->opcode) {
+		case OP_SET_LT: case OP_SET_LE:
+			if (sign_extend(value, def->size) > (long long)bits)
+				return replace_with_value(insn, 1);
+			else
+				return replace_with_value(insn, 0);
+			break;
+		case OP_SET_GE: case OP_SET_GT:
+			if (sign_extend(value, def->size) > (long long)bits)
+				return replace_with_value(insn, 0);
+			else
+				return replace_with_value(insn, 1);
+			break;
+		}
 		break;
 	}
 	return changed;
diff --git a/validation/optim/cmp-zext-simm.c b/validation/optim/cmp-zext-simm.c
index f89f8f8baa62..dda237d7257f 100644
--- a/validation/optim/cmp-zext-simm.c
+++ b/validation/optim/cmp-zext-simm.c
@@ -17,7 +17,6 @@ int zext_lgt(unsigned int x) { return (ZEXT(x) >  -1) == 1; }
 /*
  * check-name: cmp-zext-simm
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-returns: 1
-- 
2.29.2




[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