aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-04-26 18:01:06 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-02-14 12:39:33 +0100
commitf9aa068780dac8a6246c65d95792f4af688bd9c9 (patch)
tree51e70081ec2e7c46eca50410b7b5819bc9c266d1
parentf5a6877758aa1ee86a41bdecaa2747e88d74aaef (diff)
downloadsparse-dev-f9aa068780dac8a6246c65d95792f4af688bd9c9.tar.gz
kill dead loads
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. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c6
-rw-r--r--validation/optim/load-dead.c11
-rw-r--r--validation/optim/load-semi-volatile.c25
3 files changed, 41 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index f0dc69ff..dbea438e 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1195,7 +1195,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 00000000..52538cc2
--- /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\\.
+ */
diff --git a/validation/optim/load-semi-volatile.c b/validation/optim/load-semi-volatile.c
new file mode 100644
index 00000000..0e266e17
--- /dev/null
+++ b/validation/optim/load-semi-volatile.c
@@ -0,0 +1,25 @@
+struct s {
+ volatile int a;
+};
+
+struct s s;
+
+void foo(void)
+{
+ s;
+ s.a;
+}
+
+/*
+ * check-name: load-semi-volatile
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-pattern(1): load
+ *
+ * check-description:
+ * The load at line 9 must be removed.
+ * The load at line 10 is volatile and thus
+ * must not be removed.
+ */