@@ -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))
new file mode 100644
@@ -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\\.
+ */
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