[PATCH 3/9] simplify (x & M) cmps C

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

 



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

diff --git a/simplify.c b/simplify.c
index 207af8edf28f..90b0c5ba0127 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1258,6 +1258,31 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
 	src2 = insn->src2;
 	value = src2->value;
 	switch (DEF_OPCODE(def, src1)) {
+	case OP_AND:
+		if (!constant(def->src2))
+			break;
+		bits = def->src2->value;
+		switch (insn->opcode) {
+		case OP_SET_LE:
+			value = sign_extend(value, def->size);
+			if (bits & sign_bit(def->size))
+				break;
+			if (value < 0)
+				return replace_with_value(insn, 0);
+			if (value >= (long long)bits)
+				return replace_with_value(insn, 1);
+			break;
+		case OP_SET_GT:
+			value = sign_extend(value, def->size);
+			if (bits & sign_bit(def->size))
+				break;
+			if (value < 0)
+				return replace_with_value(insn, 1);
+			if (value >= (long long)bits)
+				return replace_with_value(insn, 0);
+			break;
+		}
+		break;
 	case OP_SEXT:				// sext(x) cmp C --> x cmp trunc(C)
 		osize = def->orig_type->bit_size;
 		if (is_signed_constant(value, osize, size)) {
diff --git a/validation/optim/cmps-and0.c b/validation/optim/cmps-and0.c
index 097ec2f9f16c..962fbd2d29f8 100644
--- a/validation/optim/cmps-and0.c
+++ b/validation/optim/cmps-and0.c
@@ -15,7 +15,6 @@ int cmps_and_ge_gtm(int a) { return ((a & MASK) >= (MASK + 1)) + 1; }
 /*
  * check-name: cmps-and0
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-returns: 1
-- 
2.30.0




[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