From c3420f1e8ad7af77c03c2946e826b5ad4692601e Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Thu, 16 Feb 2017 05:57:03 +0100 Subject: [PATCH] add killing of non-volatile loads 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 Signed-off-by: Christopher Li --- 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 b80d05b8..a27f6a33 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 00000000..45fb83e4 --- /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.4.GIT