From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 3/4] simplify CGOTO(SEL(x, L1, L2)) into CBR x, L1, L2
Date: Sat, 21 Nov 2020 21:52:59 +0100 [thread overview]
Message-ID: <20201121205300.94642-4-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201121205300.94642-1-luc.vanoostenryck@gmail.com>
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>
---
simplify.c | 22 ++++++++++++++++++++++
validation/optim/cgoto02.c | 1 -
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index 132d408f59f1..24ecf074206e 100644
--- a/simplify.c
+++ b/simplify.c
@@ -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 5869d5b4a24d..932c3164e5ee 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
--
2.29.2
next prev parent reply other threads:[~2020-11-21 20:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-21 20:52 [PATCH 0/4] simplification of computed goto Luc Van Oostenryck
2020-11-21 20:52 ` [PATCH 1/4] add testcases for COMPUTEDGOTO simplification Luc Van Oostenryck
2020-11-21 20:52 ` [PATCH 2/4] simplify OP_COMPUTEDGOTO with unique and known target Luc Van Oostenryck
2020-11-21 20:52 ` Luc Van Oostenryck [this message]
2020-11-21 20:53 ` [PATCH 4/4] add a new instruction for label-as-value Luc Van Oostenryck
2020-11-21 21:09 ` [PATCH 0/4] simplification of computed goto Linus Torvalds
2020-11-21 21:40 ` Luc Van Oostenryck
2020-11-21 22:07 ` Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201121205300.94642-4-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).