aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-01-06 01:01:18 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-29 23:06:59 +0100
commit701ce0cadbd5eb0655ab0c33de5c8a337a498a34 (patch)
tree5e398f1e90946d6fd85c6dd8dc52587dd897df4a
parent540c2c4bf47f0c517c042ff689679b2900bb36a5 (diff)
downloadsparse-701ce0cadbd5eb0655ab0c33de5c8a337a498a34.tar.gz
memops: kill dead loads before phi-node conversion
During load simplification it may happen that a load is unused but if this fact is ignored and the usual conversion to a phi-node is made, then this value may seem to be needed and can't anymore be simplified away. Fix this by removing dead loads during load simplification. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--memops.c5
-rw-r--r--validation/memops/kill-dead-loads00.c22
2 files changed, 27 insertions, 0 deletions
diff --git a/memops.c b/memops.c
index badcdbbb..6baf4d16 100644
--- a/memops.c
+++ b/memops.c
@@ -111,6 +111,11 @@ static void simplify_loads(struct basic_block *bb)
if (insn->is_volatile)
continue;
+ if (!has_users(insn->target)) {
+ kill_instruction(insn);
+ continue;
+ }
+
RECURSE_PTR_REVERSE(insn, dom) {
int dominance;
if (!dom->bb)
diff --git a/validation/memops/kill-dead-loads00.c b/validation/memops/kill-dead-loads00.c
new file mode 100644
index 00000000..df7ec037
--- /dev/null
+++ b/validation/memops/kill-dead-loads00.c
@@ -0,0 +1,22 @@
+void fun(void);
+
+void foo(int *p)
+{
+ for (*p; *p; *p) {
+l:
+ fun();
+ }
+
+ if (0)
+ goto l;
+}
+
+/*
+ * check-name: kill-dead-loads00
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-excludes: phi\\.
+ * check-output-pattern(1): load\\.
+ * check-output-end
+ */