From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v2 10/10] kill dead loads
Date: Tue, 13 Feb 2018 22:58:12 +0100 [thread overview]
Message-ID: <20180213215812.18735-11-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20180213215812.18735-1-luc.vanoostenryck@gmail.com>
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>
---
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 --git a/simplify.c b/simplify.c
index f0dc69ff9..dbea438e7 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 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\\.
+ */
--
2.16.0
prev parent reply other threads:[~2018-02-13 22:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-13 21:58 [PATCH v2 00/10] fix usage when killing loads & stores Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 01/10] add testcase for bad killing of dominated stores Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 02/10] add testcases for converted loads Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 03/10] fix killing of " Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 04/10] kill dead stores when simplifying symbols Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 05/10] fix usage of deadborn loads Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 06/10] add helper for pseudo's user-list's size Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 07/10] add helper: has_users() Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 08/10] use has_users() in dead_insn() too Luc Van Oostenryck
2018-02-13 21:58 ` [PATCH v2 09/10] let kill_instruction() report if changes were made Luc Van Oostenryck
2018-02-13 21:58 ` Luc Van Oostenryck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180213215812.18735-11-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).