[PATCH 07/16] cmp: simplify unsigned (x {<=,>} UMAX) into {1,0}

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

 



These compares are always true or false, so simplify them.

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

diff --git a/simplify.c b/simplify.c
index b8dfbad1f077..160a6ab15e7f 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1081,6 +1081,7 @@ static int simplify_seteq_setne(struct instruction *insn, long long value)
 
 static int simplify_compare_constant(struct instruction *insn, long long value)
 {
+	unsigned long long bits = bits_mask(insn->itype->bit_size);
 	int changed = 0;
 
 	switch (insn->opcode) {
@@ -1103,10 +1104,14 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
 	case OP_SET_BE:
 		if (!value)			// (x <= 0) --> (x == 0)
 			return replace_opcode(insn, OP_SET_EQ);
+		if (value == bits)		// (x <= ~0) --> 1
+			return replace_with_pseudo(insn, value_pseudo(1));
 		break;
 	case OP_SET_A:
 		if (!value)			// (x > 0) --> (x != 0)
 			return replace_opcode(insn, OP_SET_NE);
+		if (value == bits)		// (x > ~0) --> 0
+			return replace_with_pseudo(insn, value_pseudo(0));
 		break;
 	}
 	return changed;
diff --git a/validation/optim/set-uimm1.c b/validation/optim/set-uimm1.c
index d6928f59d044..aa9f54c3ff82 100644
--- a/validation/optim/set-uimm1.c
+++ b/validation/optim/set-uimm1.c
@@ -4,7 +4,6 @@ static _Bool setgt_umax(unsigned int a) { return (a >  ~0) == 0; }
 /*
  * check-name: set-uimm1
  * check-command: test-linearize $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