From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Cc: Aurelien Jarno <aurelien@aurel32.net>
Subject: [Qemu-devel] [PATCH 7/8] tcg/optimize: add constant folding for setcond
Date: Thu, 6 Sep 2012 17:00:56 +0200 [thread overview]
Message-ID: <1346943657-17256-8-git-send-email-aurelien@aurel32.net> (raw)
In-Reply-To: <1346943657-17256-1-git-send-email-aurelien@aurel32.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
tcg/optimize.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 7debc8a..c4af1e8 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -267,6 +267,65 @@ static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y)
return res;
}
+static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
+ TCGArg y, TCGCond c)
+{
+ switch (op_bits(op)) {
+ case 32:
+ switch (c) {
+ case TCG_COND_EQ:
+ return (uint32_t)x == (uint32_t)y;
+ case TCG_COND_NE:
+ return (uint32_t)x != (uint32_t)y;
+ case TCG_COND_LT:
+ return (int32_t)x < (int32_t)y;
+ case TCG_COND_GE:
+ return (int32_t)x >= (int32_t)y;
+ case TCG_COND_LE:
+ return (int32_t)x <= (int32_t)y;
+ case TCG_COND_GT:
+ return (int32_t)x > (int32_t)y;
+ case TCG_COND_LTU:
+ return (uint32_t)x < (uint32_t)y;
+ case TCG_COND_GEU:
+ return (uint32_t)x >= (uint32_t)y;
+ case TCG_COND_LEU:
+ return (uint32_t)x <= (uint32_t)y;
+ case TCG_COND_GTU:
+ return (uint32_t)x > (uint32_t)y;
+ }
+ case 64:
+ switch (c) {
+ case TCG_COND_EQ:
+ return (uint64_t)x == (uint64_t)y;
+ case TCG_COND_NE:
+ return (uint64_t)x != (uint64_t)y;
+ case TCG_COND_LT:
+ return (int64_t)x < (int64_t)y;
+ case TCG_COND_GE:
+ return (int64_t)x >= (int64_t)y;
+ case TCG_COND_LE:
+ return (int64_t)x <= (int64_t)y;
+ case TCG_COND_GT:
+ return (int64_t)x > (int64_t)y;
+ case TCG_COND_LTU:
+ return (uint64_t)x < (uint64_t)y;
+ case TCG_COND_GEU:
+ return (uint64_t)x >= (uint64_t)y;
+ case TCG_COND_LEU:
+ return (uint64_t)x <= (uint64_t)y;
+ case TCG_COND_GTU:
+ return (uint64_t)x > (uint64_t)y;
+ }
+ default:
+ fprintf(stderr,
+ "Unrecognized bitness %d or condition %d in "
+ "do_constant_folding_cond.\n", op_bits(op), c);
+ tcg_abort();
+ }
+}
+
+
/* Propagate constants and copies, fold constant expressions. */
static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
TCGArg *args, TCGOpDef *tcg_op_defs)
@@ -522,6 +581,26 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
args += 3;
break;
}
+ CASE_OP_32_64(setcond):
+ if (temps[args[1]].state == TCG_TEMP_CONST
+ && temps[args[2]].state == TCG_TEMP_CONST) {
+ gen_opc_buf[op_index] = op_to_movi(op);
+ tmp = do_constant_folding_cond(op, temps[args[1]].val,
+ temps[args[2]].val, args[3]);
+ tcg_opt_gen_movi(gen_args, args[0], tmp, nb_temps, nb_globals);
+ gen_args += 2;
+ args += 4;
+ break;
+ } else {
+ reset_temp(args[0], nb_temps, nb_globals);
+ gen_args[0] = args[0];
+ gen_args[1] = args[1];
+ gen_args[2] = args[2];
+ gen_args[3] = args[3];
+ gen_args += 4;
+ args += 4;
+ break;
+ }
case INDEX_op_call:
nb_call_args = (args[0] >> 16) + (args[0] & 0xffff);
if (!(args[nb_call_args + 1] & (TCG_CALL_CONST | TCG_CALL_PURE))) {
--
1.7.10.4
next prev parent reply other threads:[~2012-09-06 15:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-06 15:00 [Qemu-devel] [PATCH 0/8] Improve TCG optimizer Aurelien Jarno
2012-09-06 15:00 ` [Qemu-devel] [PATCH 1/8] tcg: improve profiler Aurelien Jarno
2012-09-06 15:00 ` [Qemu-devel] [PATCH 2/8] tcg/optimize: split expression simplification Aurelien Jarno
2012-09-06 15:00 ` [Qemu-devel] [PATCH 3/8] tcg/optimize: simplify or/xor r, a, 0 cases Aurelien Jarno
2012-09-06 15:00 ` [Qemu-devel] [PATCH 4/8] tcg/optimize: simplify and " Aurelien Jarno
2012-09-06 15:00 ` [Qemu-devel] [PATCH 5/8] tcg/optimize: simplify shift/rot r, 0, a => movi r, " Aurelien Jarno
2012-09-06 15:00 ` [Qemu-devel] [PATCH 6/8] tcg/optimize: swap brcond/setcond arguments when possible Aurelien Jarno
2012-09-06 15:00 ` Aurelien Jarno [this message]
2012-09-06 16:40 ` [Qemu-devel] [PATCH 7/8] tcg/optimize: add constant folding for setcond Richard Henderson
2012-09-07 10:05 ` Aurelien Jarno
2012-09-06 15:00 ` [Qemu-devel] [PATCH 8/8] tcg/optimize: add constant folding for brcond Aurelien Jarno
2012-09-06 16:43 ` [Qemu-devel] [PATCH 0/8] Improve TCG optimizer Richard Henderson
2012-09-07 10:06 ` Aurelien Jarno
2012-09-07 12:34 ` Peter Maydell
2012-09-07 13:00 ` Aurelien Jarno
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=1346943657-17256-8-git-send-email-aurelien@aurel32.net \
--to=aurelien@aurel32.net \
--cc=qemu-devel@nongnu.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).