OP_LOADs were ignored by kill_instruction() but there are two cases were something can or must be done: 1) if the is not a volatile one, it is free of side-effects and can thus be optimized away like others instructions. 2) if force-killed then we need to adjust the usage of its operand. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 6 ++++++ validation/kill-load.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 validation/kill-load.c diff --git a/simplify.c b/simplify.c index b80d05b87..a27f6a33a 100644 --- a/simplify.c +++ b/simplify.c @@ -249,6 +249,12 @@ void kill_insn(struct instruction *insn, int force) kill_use(&insn->func); break; + case OP_LOAD: + if (!force && insn->type->ctype.modifiers & MOD_VOLATILE) + return; + kill_use(&insn->src); + break; + case OP_ENTRY: /* ignore */ return; diff --git a/validation/kill-load.c b/validation/kill-load.c new file mode 100644 index 000000000..45fb83e4b --- /dev/null +++ b/validation/kill-load.c @@ -0,0 +1,17 @@ +int keep(volatile int *p) { return *p && 0; } +int kill(int *p, int i) { return *p && 0; } +void ind(volatile int *p,int i) { int v = i++; if (i && 0) p[v]; } + + +/* + * check-name: kill-load + * check-command: test-linearize -Wno-decl $file + * check-description: + * Check that loads are optimized away but only + * when needed: + * - non-volatile + * - bb unreachable. + * + * check-output-ignore + * check-output-pattern-1-times: load\\. + */ -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html