[PATCH 2/2] optim: simplify null select

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

 



A select instruction like:
	select	r <- x, 0, x
always gives zero as result but the optimizer doesn't this.

Change this by teaching the optimizer about it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                     |  6 ++++++
 validation/optim/select-zero.c | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 validation/optim/select-zero.c

diff --git a/simplify.c b/simplify.c
index 0a3207404..e5e555c18 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1019,6 +1019,12 @@ static int simplify_select(struct instruction *insn)
 			return REPEAT_CSE;
 		}
 	}
+	if (cond == src2 && is_zero(src1)) {
+		kill_use(&insn->src1);
+		kill_use(&insn->src3);
+		replace_with_pseudo(insn, value_pseudo(0));
+		return REPEAT_CSE;
+	}
 	return 0;
 }
 
diff --git a/validation/optim/select-zero.c b/validation/optim/select-zero.c
new file mode 100644
index 000000000..ed737bffc
--- /dev/null
+++ b/validation/optim/select-zero.c
@@ -0,0 +1,16 @@
+static int sel0(int a)
+{
+	if (a)
+		return 0;
+	else
+		return a;
+}
+
+/*
+ * check-name: select-zero
+ * check-command: test-linearize $file
+ *
+ * check-output-ignore
+ * check-output-contains: ret.32 *\\$0
+ * check-output-excludes: select\\.
+ */
-- 
2.16.2

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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