[PATCH 13/16] cmp: canonicalize sext(x) cmpu C (with C >= SMAX)

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

 



A unsigned compare of a sign-extended value against a value
bigger than the original SMAX is equivalent to a signed
compare against 0.

Canonicalize to the signed compare against 0.

Note: ultimately both forms are just a test of the sign bit.

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

diff --git a/simplify.c b/simplify.c
index a59918697762..8a8b39b81e20 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1149,6 +1149,18 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
 			return replace_pseudo(insn, &insn->src1, def->src);
 		}
 		switch (insn->opcode) {
+		case OP_SET_BE:
+			if (value >= sign_bit(osize)) {
+				replace_binop_value(insn, OP_SET_GE, 0);
+				return replace_pseudo(insn, &insn->src1, def->src);
+			}
+			break;
+		case OP_SET_A:
+			if (value >= sign_bit(osize)) {
+				replace_binop_value(insn, OP_SET_LT, 0);
+				return replace_pseudo(insn, &insn->src1, def->src);
+			}
+			break;
 		case OP_SET_LT: case OP_SET_LE:
 			if (value >= sign_bit(osize))
 				return replace_with_value(insn, 1);
diff --git a/validation/optim/cmp-sext-uimm.c b/validation/optim/cmp-sext-uimm.c
index cc89a80694a1..05da042f5030 100644
--- a/validation/optim/cmp-sext-uimm.c
+++ b/validation/optim/cmp-sext-uimm.c
@@ -19,7 +19,6 @@ int sext_gtu_m3(int x) { return (sext(x) > (NEG - 3)) == (x < 0); }
 /*
  * check-name: cmp-sext-uimm
  * 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