From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Dibyendu Majumdar <mobile@majumdar.org.uk>
Cc: linux-sparse@vger.kernel.org,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v2 1/8] Remove single-store shortcut
Date: Mon, 7 Aug 2017 21:11:58 +0200 [thread overview]
Message-ID: <20170807191205.86590-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170807191205.86590-1-luc.vanoostenryck@gmail.com>
Current sparse code doesn't handle very gracefully
code with undefined pseudos. These can occurs,
of course because the dev has forgot (or choose) to
initialize them but they can also occurs when they
are only set (and used) in a single path and not others
or even worse when initilaizing a bitfield.
The origin of the problme is the single store shortcut
in simplify_one_symbol() which doesn't take in account
the (absence of) dominance when loads exist without
stores.
Fix this by removing this single-store shortcut and leave
all the work for the general case which handle this
situation quite well (and/but set those variables to 0).
Warning: this change impact the performance.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
flow.c | 39 ++-------------------------------------
1 file changed, 2 insertions(+), 37 deletions(-)
diff --git a/flow.c b/flow.c
index 6cac21b24..6b2c879a8 100644
--- a/flow.c
+++ b/flow.c
@@ -650,11 +650,10 @@ void check_access(struct instruction *insn)
static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym)
{
- pseudo_t pseudo, src;
+ pseudo_t pseudo;
struct pseudo_user *pu;
- struct instruction *def;
unsigned long mod;
- int all, stores, complex;
+ int all;
/* Never used as a symbol? */
pseudo = sym->pseudo;
@@ -670,17 +669,12 @@ static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym)
if (mod)
goto external_visibility;
- def = NULL;
- stores = 0;
- complex = 0;
FOR_EACH_PTR(pseudo->users, pu) {
/* We know that the symbol-pseudo use is the "src" in the instruction */
struct instruction *insn = pu->insn;
switch (insn->opcode) {
case OP_STORE:
- stores++;
- def = insn;
break;
case OP_LOAD:
break;
@@ -697,37 +691,8 @@ static void simplify_one_symbol(struct entrypoint *ep, struct symbol *sym)
default:
warning(sym->pos, "symbol '%s' pseudo used in unexpected way", show_ident(sym->ident));
}
- complex |= insn->offset;
} END_FOR_EACH_PTR(pu);
- if (complex)
- goto complex_def;
- if (stores > 1)
- goto multi_def;
-
- /*
- * Goodie, we have a single store (if even that) in the whole
- * thing. Replace all loads with moves from the pseudo,
- * replace the store with a def.
- */
- src = VOID;
- if (def)
- src = def->target;
-
- FOR_EACH_PTR(pseudo->users, pu) {
- struct instruction *insn = pu->insn;
- if (insn->opcode == OP_LOAD) {
- check_access(insn);
- convert_load_instruction(insn, src);
- }
- } END_FOR_EACH_PTR(pu);
-
- /* Turn the store into a no-op */
- kill_store(def);
- return;
next prev parent reply other threads:[~2017-08-07 19:12 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-28 12:40 Potential incorrect simplification Dibyendu Majumdar
2017-03-28 13:34 ` Luc Van Oostenryck
2017-03-28 13:58 ` Dibyendu Majumdar
2017-03-28 14:11 ` Luc Van Oostenryck
2017-03-28 14:19 ` Dibyendu Majumdar
2017-03-28 16:20 ` Linus Torvalds
2017-03-28 17:00 ` Luc Van Oostenryck
2017-03-28 18:02 ` Linus Torvalds
2017-03-28 20:27 ` Luc Van Oostenryck
2017-03-28 21:57 ` Linus Torvalds
2017-03-28 22:28 ` Luc Van Oostenryck
2017-03-28 22:22 ` Dibyendu Majumdar
2017-08-06 12:46 ` Christopher Li
2017-08-06 14:00 ` Luc Van Oostenryck
2017-08-06 14:24 ` Christopher Li
2017-08-06 14:54 ` Christopher Li
2017-08-06 15:07 ` Luc Van Oostenryck
2017-08-06 15:51 ` Christopher Li
2017-08-06 16:51 ` Luc Van Oostenryck
2017-08-06 18:35 ` Christopher Li
2017-08-06 19:51 ` Dibyendu Majumdar
2017-08-06 20:08 ` Luc Van Oostenryck
2017-08-06 19:52 ` Luc Van Oostenryck
2017-08-06 23:34 ` Christopher Li
2017-08-07 0:31 ` Luc Van Oostenryck
2017-08-07 0:38 ` Christopher Li
2017-08-06 15:52 ` Dibyendu Majumdar
2017-08-06 16:56 ` Luc Van Oostenryck
2017-08-06 17:04 ` Dibyendu Majumdar
2017-08-06 17:45 ` Luc Van Oostenryck
2017-08-06 17:58 ` Dibyendu Majumdar
2017-08-06 18:15 ` Luc Van Oostenryck
2017-08-06 18:18 ` Dibyendu Majumdar
2017-08-06 18:31 ` Luc Van Oostenryck
2017-08-07 19:11 ` [PATCH v2 0/8] fix loading of partially defined bitfield Luc Van Oostenryck
2017-08-07 19:11 ` Luc Van Oostenryck [this message]
2017-08-07 21:42 ` [PATCH v2 1/8] Remove single-store shortcut Linus Torvalds
2017-08-10 0:29 ` Christopher Li
2017-08-10 0:41 ` Luc Van Oostenryck
2017-08-10 0:53 ` Christopher Li
2017-08-10 11:01 ` Christopher Li
2017-08-10 12:26 ` Luc Van Oostenryck
2017-08-10 13:25 ` Christopher Li
2017-08-07 19:11 ` [PATCH v2 2/8] new helper: def_opcode() Luc Van Oostenryck
2017-08-07 19:12 ` [PATCH v2 3/8] reuse nbr_pseudo_users() Luc Van Oostenryck
2017-08-07 19:12 ` [PATCH v2 4/8] change the masking when loading bitfields Luc Van Oostenryck
2017-08-07 19:12 ` [PATCH v2 5/8] simplify ((A & M') | B ) & M when M' & M == 0 Luc Van Oostenryck
2017-08-07 19:12 ` [PATCH v2 6/8] transform (A & M) >> S to (A >> S) & (M >> S) Luc Van Oostenryck
2017-08-08 0:22 ` Christopher Li
2017-08-08 0:29 ` Luc Van Oostenryck
2017-08-08 1:48 ` Christopher Li
2017-08-08 1:00 ` Linus Torvalds
2017-08-08 1:38 ` Luc Van Oostenryck
2017-08-08 1:50 ` Christopher Li
2017-08-07 19:12 ` [PATCH v2 7/8] transform (A << S) >> S into A & (-1 " Luc Van Oostenryck
2017-08-07 21:54 ` Linus Torvalds
2017-08-07 22:08 ` Luc Van Oostenryck
2017-08-07 22:27 ` Luc Van Oostenryck
2017-08-07 19:12 ` [PATCH v2 8/8] fix: cast of OP_AND only valid if it's an OP_CAST Luc Van Oostenryck
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=20170807191205.86590-2-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=mobile@majumdar.org.uk \
/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).