From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PATCH 2/3] tcg: Fold deposit with zero to and
Date: Wed, 16 Aug 2023 07:55:46 -0700 [thread overview]
Message-ID: <20230816145547.477974-3-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230816145547.477974-1-richard.henderson@linaro.org>
Inserting a zero into a value, or inserting a value
into zero at offset 0 my be implemented with AND.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/optimize.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index d2156367a3..956114b631 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1279,6 +1279,8 @@ static bool fold_ctpop(OptContext *ctx, TCGOp *op)
static bool fold_deposit(OptContext *ctx, TCGOp *op)
{
+ TCGOpcode and_opc;
+
if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) {
uint64_t t1 = arg_info(op->args[1])->val;
uint64_t t2 = arg_info(op->args[2])->val;
@@ -1287,6 +1289,39 @@ static bool fold_deposit(OptContext *ctx, TCGOp *op)
return tcg_opt_gen_movi(ctx, op, op->args[0], t1);
}
+ switch (ctx->type) {
+ case TCG_TYPE_I32:
+ and_opc = INDEX_op_and_i32;
+ break;
+ case TCG_TYPE_I64:
+ and_opc = INDEX_op_and_i64;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ if (arg_is_const(op->args[1])
+ && arg_info(op->args[1])->val == 0
+ && op->args[3] == 0) {
+ uint64_t mask = MAKE_64BIT_MASK(0, op->args[4]);
+
+ op->opc = and_opc;
+ op->args[1] = op->args[2];
+ op->args[2] = temp_arg(tcg_constant_internal(ctx->type, mask));
+ ctx->z_mask = mask & arg_info(op->args[1])->z_mask;
+ return false;
+ }
+
+ if (arg_is_const(op->args[2])
+ && arg_info(op->args[2])->val == 0) {
+ uint64_t mask = deposit64(-1, op->args[3], op->args[4], 0);
+
+ op->opc = and_opc;
+ op->args[2] = temp_arg(tcg_constant_internal(ctx->type, mask));
+ ctx->z_mask = mask & arg_info(op->args[1])->z_mask;
+ return false;
+ }
+
ctx->z_mask = deposit64(arg_info(op->args[1])->z_mask,
op->args[3], op->args[4],
arg_info(op->args[2])->z_mask);
--
2.34.1
next prev parent reply other threads:[~2023-08-16 14:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 14:55 [PATCH 0/3] tcg/i386: Improvements to deposit Richard Henderson
2023-08-16 14:55 ` [PATCH 1/3] tcg/i386: Drop BYTEH deposits for 64-bit Richard Henderson
2023-08-17 15:44 ` Peter Maydell
2023-08-17 22:04 ` Richard Henderson
2023-08-16 14:55 ` Richard Henderson [this message]
2023-08-17 15:50 ` [PATCH 2/3] tcg: Fold deposit with zero to and Peter Maydell
2023-08-17 22:07 ` Richard Henderson
2023-08-18 8:51 ` Peter Maydell
2023-08-21 12:05 ` Philippe Mathieu-Daudé
2023-08-16 14:55 ` [PATCH 3/3] tcg/i386: Allow immediate as input to deposit_* Richard Henderson
2023-08-17 15:55 ` Peter Maydell
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=20230816145547.477974-3-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--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).