diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-03-11 16:47:18 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-03-17 18:21:21 +0100 |
| commit | 5953ebb1f87141a268fc9a214b982079d1138410 (patch) | |
| tree | 8616b5792cbb76b4ee80ce8930c1232a6694cc46 | |
| parent | 4a036fd55cb47e88119c792018904511401ddd79 (diff) | |
| download | sparse-dev-5953ebb1f87141a268fc9a214b982079d1138410.tar.gz | |
optim: simplify null select
A select instruction like:
select r <- x, 0, x
always gives zero as result but the optimizer doesn't this.
Change this by teaching the optimizer about it.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 6 | ||||
| -rw-r--r-- | validation/optim/select-zero.c | 16 |
2 files changed, 22 insertions, 0 deletions
@@ -1019,6 +1019,12 @@ static int simplify_select(struct instruction *insn) return REPEAT_CSE; } } + if (cond == src2 && is_zero(src1)) { + kill_use(&insn->src1); + kill_use(&insn->src3); + replace_with_pseudo(insn, value_pseudo(0)); + return REPEAT_CSE; + } return 0; } diff --git a/validation/optim/select-zero.c b/validation/optim/select-zero.c new file mode 100644 index 00000000..ed737bff --- /dev/null +++ b/validation/optim/select-zero.c @@ -0,0 +1,16 @@ +static int sel0(int a) +{ + if (a) + return 0; + else + return a; +} + +/* + * check-name: select-zero + * check-command: test-linearize $file + * + * check-output-ignore + * check-output-contains: ret.32 *\\$0 + * check-output-excludes: select\\. + */ |
