[PATCH 1/2] simplify unsigned compares against 0

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

 



Some unsigned compares against 0 are always true or always false
(x < 0 or x >= 0). Simplify them.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                   | 10 ++++++++++
 validation/optim/set-uimm0.c | 10 ++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 validation/optim/set-uimm0.c

diff --git a/simplify.c b/simplify.c
index 6caf6cbcf918..4441b27c7546 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1173,6 +1173,16 @@ static int simplify_constant_rightside(struct instruction *insn)
 	case OP_SET_NE:
 	case OP_SET_EQ:
 		return simplify_seteq_setne(insn, value);
+	case OP_SET_B:
+		if (!value) {			// (x < 0) --> 0
+			return replace_with_pseudo(insn, value_pseudo(0));
+		}
+		break;
+	case OP_SET_AE:
+		if (!value) {			// (x >= 0) --> 1
+			return replace_with_pseudo(insn, value_pseudo(1));
+		}
+		break;
 	}
 	return 0;
 }
diff --git a/validation/optim/set-uimm0.c b/validation/optim/set-uimm0.c
new file mode 100644
index 000000000000..1f62358ff0fb
--- /dev/null
+++ b/validation/optim/set-uimm0.c
@@ -0,0 +1,10 @@
+static _Bool setlt0(unsigned int a) { return (a <   0u) == 0; }
+static _Bool setge0(unsigned int a) { return (a >=  0u) == 1; }
+
+/*
+ * check-name: set-uimm0
+ * check-command: test-linearize $file
+ *
+ * check-output-ignore
+ * check-output-pattern(2): ret\\.1 *\\$1
+ */
-- 
2.28.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