Currently kill_instruction() doesn't do anything with the operands of select instructions (OP_SELECT). But when these instructions are removed we must also remove the operands 'usage'. Without this the instructions which provides the select's operands are not optimized away as expected. This patch fixes this by doing for OP_SELECTs the basic kill_instruction() for ternary instruction, like OP_RANGE. As an example, when looking at the output of test-linearize, the following code: void foo(int x) { unsigned int ui; ui = x + 1; ui = ui ? 0 : 1; } gives this output: foo: add.32 %r2 <- %arg1, $1 ret Since the result of the ?: is never used, the whole code should be optimized away. The 'select' instruction itself is indeed discarded but the 'add' is not. With the patch, the output is much closer to what's expected: foo: ret Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 1 + validation/kill-select.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 validation/kill-select.c diff --git a/simplify.c b/simplify.c index 939ba6af..1dd1bda6 100644 --- a/simplify.c +++ b/simplify.c @@ -217,6 +217,7 @@ void kill_instruction(struct instruction *insn) repeat_phase |= REPEAT_CSE | REPEAT_SYMBOL_CLEANUP; return; + case OP_SEL: case OP_RANGE: insn->bb = NULL; repeat_phase |= REPEAT_CSE; diff --git a/validation/kill-select.c b/validation/kill-select.c new file mode 100644 index 00000000..445472be --- /dev/null +++ b/validation/kill-select.c @@ -0,0 +1,16 @@ +void foo(int x); +void foo(int x) +{ + unsigned int ui; + + ui = x + 1; + ui = ui ? 0 : 1; +} + +/* + * check-name: kill-select + * check-command: test-linearize $file + * + * check-output-ignore + * check-output-excludes: add\\. + */ -- 2.10.2 -- 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