diff mbox

[3/3] kill dead loads

Message ID 20170608073927.55218-4-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Luc Van Oostenryck June 8, 2017, 7:39 a.m. UTC
Like others instructions producing a value, OP_LOADs can be dead.

But currently, dead OP_LOAD are not removed, as dead_insn() do for
others instructions.

Fix this by checking at simplification time if OP_LOADs are dead
and call kill_instruction() if it is the case.

NOTE: the fix is the exact same logic than dead_insn() but dead_insn()
      kill without discrimination. In our case we want to keep volatiles
      OP_LOADs which kill_instruction() does and dead_insn() does not.
      Ideally, dead_insn() should use kill_instruction() but this is
      a bigger change which will part of another series.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                   |  6 +++++-
 validation/optim/load-dead.c | 11 +++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 validation/optim/load-dead.c
diff mbox

Patch

diff --git a/simplify.c b/simplify.c
index d5e219200..2c95d8b86 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1189,7 +1189,11 @@  int simplify_instruction(struct instruction *insn)
 
 	case OP_NOT: case OP_NEG:
 		return simplify_unop(insn);
-	case OP_LOAD: case OP_STORE:
+	case OP_LOAD:
+		if (!has_users(insn->target))
+			return kill_instruction(insn);
+		/* fall-through */
+	case OP_STORE:
 		return simplify_memop(insn);
 	case OP_SYMADDR:
 		if (dead_insn(insn, NULL, NULL, NULL))
diff --git a/validation/optim/load-dead.c b/validation/optim/load-dead.c
new file mode 100644
index 000000000..52538cc2d
--- /dev/null
+++ b/validation/optim/load-dead.c
@@ -0,0 +1,11 @@ 
+void foo(int *p) { *p; }
+
+int *p;
+void bar(void) { *p; }
+
+/*
+ * check-name: load-dead
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ * check-output-excludes: load\\.
+ */