diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-17 07:10:45 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-21 18:22:11 +0100 |
commit | 1221dc1c8c4299c57bb53a7b0b8a8e4e8729f9d6 (patch) | |
tree | 63c7ac33601a28e94c722d3a62762e103afe56a2 | |
parent | 7943063c5206e28f00d6f4c5117de034c369cd92 (diff) | |
download | sparse-1221dc1c8c4299c57bb53a7b0b8a8e4e8729f9d6.tar.gz |
simplify CGOTO(SEL(x, L1, L2)) into CBR x, L1, L2
A computed goto having as operand a select of 2 statically known addresses
(OP_SETVAL/EXPR_LABEL) is equivalent to a simple conditional branch.
Simplify such computed goto into the corresponding OP_CBR
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 22 | ||||
-rw-r--r-- | validation/optim/cgoto02.c | 1 |
2 files changed, 22 insertions, 1 deletions
@@ -2112,13 +2112,35 @@ found: return REPEAT_CSE; } +static struct basic_block *is_label(pseudo_t pseudo) +{ + struct expression *expr; + struct instruction *def; + + if (DEF_OPCODE(def, pseudo) != OP_SETVAL) + return NULL; + expr = def->val; + if (expr->type != EXPR_LABEL) + return NULL; + return expr->symbol->bb_target; +} + static int simplify_cgoto(struct instruction *insn) { struct basic_block *target, *bb = insn->bb; + struct basic_block *bbt, *bbf; struct instruction *def; struct multijmp *jmp; switch (DEF_OPCODE(def, insn->src)) { + case OP_SEL: // CGOTO(SEL(x, L1, L2)) --> CBR x, L1, L2 + if ((bbt = is_label(def->src2)) && (bbf = is_label(def->src3))) { + insn->opcode = OP_CBR; + insn->bb_true = bbt; + insn->bb_false = bbf; + return replace_pseudo(insn, &insn->src1, def->cond); + } + break; case OP_SETVAL: if (def->val->type != EXPR_LABEL) break; diff --git a/validation/optim/cgoto02.c b/validation/optim/cgoto02.c index 5869d5b4..932c3164 100644 --- a/validation/optim/cgoto02.c +++ b/validation/optim/cgoto02.c @@ -11,7 +11,6 @@ l2: /* * check-name: cgoto02 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: %arg1 |