diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-01-29 11:48:05 +0100 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2017-02-13 09:34:45 +0800 |
| commit | 61c406241c5d1a8da3f829e51e18f20b77f25926 (patch) | |
| tree | c69f2e20467a13172850168c830219dd77106a49 | |
| parent | a903d3a56a9e0d51f2603815e5d2394b1c94c57a (diff) | |
| download | sparse-dev-61c406241c5d1a8da3f829e51e18f20b77f25926.tar.gz | |
fix killing OP_SELECT
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@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
| -rw-r--r-- | simplify.c | 1 | ||||
| -rw-r--r-- | validation/kill-select.c | 16 |
2 files changed, 17 insertions, 0 deletions
@@ -216,6 +216,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\\. + */ |
