* [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2
@ 2025-04-22 14:37 Richard Henderson
2025-04-22 14:37 ` [PATCH 1/2] tcg/optimize: Introduce opt_insert_{before,after} Richard Henderson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Richard Henderson @ 2025-04-22 14:37 UTC (permalink / raw)
To: qemu-devel; +Cc: npiggin
This is a refresh of
20250415192515.232910-154-richard.henderson@linaro.org
[PATCH v4 153/163] tcg: Assign TCGOP_TYPE in liveness_pass_2
without re-posting the other 162 patches. :-)
Adjusted as suggested by Nicholas.
r~
Richard Henderson (2):
tcg/optimize: Introduce opt_insert_{before,after}
tcg: Add TCGType to tcg_op_insert_{after,before}
tcg/tcg-internal.h | 4 ++--
tcg/optimize.c | 30 +++++++++++++++++++++---------
tcg/tcg.c | 17 ++++++++++-------
3 files changed, 33 insertions(+), 18 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] tcg/optimize: Introduce opt_insert_{before,after}
2025-04-22 14:37 [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2 Richard Henderson
@ 2025-04-22 14:37 ` Richard Henderson
2025-04-22 14:37 ` [PATCH 2/2] tcg: Add TCGType to tcg_op_insert_{after,before} Richard Henderson
2025-04-22 15:17 ` [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2 Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2025-04-22 14:37 UTC (permalink / raw)
To: qemu-devel; +Cc: npiggin
Consolidate the places we call tcg_op_insert_{before,after}
within the optimization pass.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/optimize.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index f922f86a1d..a4d4ad3005 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -344,6 +344,18 @@ static TCGArg arg_new_temp(OptContext *ctx)
return temp_arg(ts);
}
+static TCGOp *opt_insert_after(OptContext *ctx, TCGOp *op,
+ TCGOpcode opc, unsigned narg)
+{
+ return tcg_op_insert_after(ctx->tcg, op, opc, narg);
+}
+
+static TCGOp *opt_insert_before(OptContext *ctx, TCGOp *op,
+ TCGOpcode opc, unsigned narg)
+{
+ return tcg_op_insert_before(ctx->tcg, op, opc, narg);
+}
+
static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src)
{
TCGTemp *dst_ts = arg_temp(dst);
@@ -808,7 +820,7 @@ static int do_constant_folding_cond1(OptContext *ctx, TCGOp *op, TCGArg dest,
if (!TCG_TARGET_HAS_tst) {
TCGOpcode and_opc = (ctx->type == TCG_TYPE_I32
? INDEX_op_and_i32 : INDEX_op_and_i64);
- TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, and_opc, 3);
+ TCGOp *op2 = opt_insert_before(ctx, op, and_opc, 3);
TCGArg tmp = arg_new_temp(ctx);
op2->args[0] = tmp;
@@ -901,8 +913,8 @@ static int do_constant_folding_cond2(OptContext *ctx, TCGOp *op, TCGArg *args)
/* Expand to AND with a temporary if no backend support. */
if (!TCG_TARGET_HAS_tst && is_tst_cond(c)) {
- TCGOp *op1 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_and_i32, 3);
- TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_and_i32, 3);
+ TCGOp *op1 = opt_insert_before(ctx, op, INDEX_op_and_i32, 3);
+ TCGOp *op2 = opt_insert_before(ctx, op, INDEX_op_and_i32, 3);
TCGArg t1 = arg_new_temp(ctx);
TCGArg t2 = arg_new_temp(ctx);
@@ -1263,7 +1275,7 @@ static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add)
rh = op->args[1];
/* The proper opcode is supplied by tcg_opt_gen_mov. */
- op2 = tcg_op_insert_before(ctx->tcg, op, 0, 2);
+ op2 = opt_insert_before(ctx, op, 0, 2);
tcg_opt_gen_movi(ctx, op, rl, al);
tcg_opt_gen_movi(ctx, op2, rh, ah);
@@ -2096,7 +2108,7 @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op)
rh = op->args[1];
/* The proper opcode is supplied by tcg_opt_gen_mov. */
- op2 = tcg_op_insert_before(ctx->tcg, op, 0, 2);
+ op2 = opt_insert_before(ctx, op, 0, 2);
tcg_opt_gen_movi(ctx, op, rl, l);
tcg_opt_gen_movi(ctx, op2, rh, h);
@@ -2406,7 +2418,7 @@ static void fold_setcond_tst_pow2(OptContext *ctx, TCGOp *op, bool neg)
op->args[3] = 1;
} else {
if (sh) {
- op2 = tcg_op_insert_before(ctx->tcg, op, shr_opc, 3);
+ op2 = opt_insert_before(ctx, op, shr_opc, 3);
op2->args[0] = ret;
op2->args[1] = src1;
op2->args[2] = arg_new_constant(ctx, sh);
@@ -2418,17 +2430,17 @@ static void fold_setcond_tst_pow2(OptContext *ctx, TCGOp *op, bool neg)
}
if (neg && inv) {
- op2 = tcg_op_insert_after(ctx->tcg, op, sub_opc, 3);
+ op2 = opt_insert_after(ctx, op, sub_opc, 3);
op2->args[0] = ret;
op2->args[1] = ret;
op2->args[2] = arg_new_constant(ctx, 1);
} else if (inv) {
- op2 = tcg_op_insert_after(ctx->tcg, op, xor_opc, 3);
+ op2 = opt_insert_after(ctx, op, xor_opc, 3);
op2->args[0] = ret;
op2->args[1] = ret;
op2->args[2] = arg_new_constant(ctx, 1);
} else if (neg) {
- op2 = tcg_op_insert_after(ctx->tcg, op, neg_opc, 2);
+ op2 = opt_insert_after(ctx, op, neg_opc, 2);
op2->args[0] = ret;
op2->args[1] = ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] tcg: Add TCGType to tcg_op_insert_{after,before}
2025-04-22 14:37 [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2 Richard Henderson
2025-04-22 14:37 ` [PATCH 1/2] tcg/optimize: Introduce opt_insert_{before,after} Richard Henderson
@ 2025-04-22 14:37 ` Richard Henderson
2025-04-22 15:17 ` [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2 Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2025-04-22 14:37 UTC (permalink / raw)
To: qemu-devel; +Cc: npiggin
We cannot rely on the value copied from TCGOP_TYPE(op), because
the relevant op could be typeless, such as INDEX_op_call.
Fixes: fb744ece3a78 ("tcg: Copy TCGOP_TYPE in tcg_op_insert_{after,before}")
Suggested-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-internal.h | 4 ++--
tcg/optimize.c | 4 ++--
tcg/tcg.c | 17 ++++++++++-------
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index a648ee7a0e..56c90fdb7a 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -107,8 +107,8 @@ void vec_gen_6(TCGOpcode opc, TCGType type, unsigned vece, TCGArg r,
TCGArg a, TCGArg b, TCGArg c, TCGArg d, TCGArg e);
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
- TCGOpcode opc, unsigned nargs);
+ TCGOpcode, TCGType, unsigned nargs);
TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op,
- TCGOpcode opc, unsigned nargs);
+ TCGOpcode, TCGType, unsigned nargs);
#endif /* TCG_INTERNAL_H */
diff --git a/tcg/optimize.c b/tcg/optimize.c
index a4d4ad3005..3bd4ee4d58 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -347,13 +347,13 @@ static TCGArg arg_new_temp(OptContext *ctx)
static TCGOp *opt_insert_after(OptContext *ctx, TCGOp *op,
TCGOpcode opc, unsigned narg)
{
- return tcg_op_insert_after(ctx->tcg, op, opc, narg);
+ return tcg_op_insert_after(ctx->tcg, op, opc, ctx->type, narg);
}
static TCGOp *opt_insert_before(OptContext *ctx, TCGOp *op,
TCGOpcode opc, unsigned narg)
{
- return tcg_op_insert_before(ctx->tcg, op, opc, narg);
+ return tcg_op_insert_before(ctx->tcg, op, opc, ctx->type, narg);
}
static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src)
diff --git a/tcg/tcg.c b/tcg/tcg.c
index dfd48b8264..3d2f924881 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -3449,21 +3449,21 @@ TCGOp *tcg_emit_op(TCGOpcode opc, unsigned nargs)
}
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *old_op,
- TCGOpcode opc, unsigned nargs)
+ TCGOpcode opc, TCGType type, unsigned nargs)
{
TCGOp *new_op = tcg_op_alloc(opc, nargs);
- TCGOP_TYPE(new_op) = TCGOP_TYPE(old_op);
+ TCGOP_TYPE(new_op) = type;
QTAILQ_INSERT_BEFORE(old_op, new_op, link);
return new_op;
}
TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old_op,
- TCGOpcode opc, unsigned nargs)
+ TCGOpcode opc, TCGType type, unsigned nargs)
{
TCGOp *new_op = tcg_op_alloc(opc, nargs);
- TCGOP_TYPE(new_op) = TCGOP_TYPE(old_op);
+ TCGOP_TYPE(new_op) = type;
QTAILQ_INSERT_AFTER(&s->ops, old_op, new_op, link);
return new_op;
}
@@ -4214,7 +4214,8 @@ liveness_pass_2(TCGContext *s)
TCGOpcode lopc = (arg_ts->type == TCG_TYPE_I32
? INDEX_op_ld_i32
: INDEX_op_ld_i64);
- TCGOp *lop = tcg_op_insert_before(s, op, lopc, 3);
+ TCGOp *lop = tcg_op_insert_before(s, op, lopc,
+ arg_ts->type, 3);
lop->args[0] = temp_arg(dir_ts);
lop->args[1] = temp_arg(arg_ts->mem_base);
@@ -4277,7 +4278,8 @@ liveness_pass_2(TCGContext *s)
TCGOpcode sopc = (arg_ts->type == TCG_TYPE_I32
? INDEX_op_st_i32
: INDEX_op_st_i64);
- TCGOp *sop = tcg_op_insert_after(s, op, sopc, 3);
+ TCGOp *sop = tcg_op_insert_after(s, op, sopc,
+ arg_ts->type, 3);
TCGTemp *out_ts = dir_ts;
if (IS_DEAD_ARG(0)) {
@@ -4313,7 +4315,8 @@ liveness_pass_2(TCGContext *s)
TCGOpcode sopc = (arg_ts->type == TCG_TYPE_I32
? INDEX_op_st_i32
: INDEX_op_st_i64);
- TCGOp *sop = tcg_op_insert_after(s, op, sopc, 3);
+ TCGOp *sop = tcg_op_insert_after(s, op, sopc,
+ arg_ts->type, 3);
sop->args[0] = temp_arg(dir_ts);
sop->args[1] = temp_arg(arg_ts->mem_base);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2
2025-04-22 14:37 [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2 Richard Henderson
2025-04-22 14:37 ` [PATCH 1/2] tcg/optimize: Introduce opt_insert_{before,after} Richard Henderson
2025-04-22 14:37 ` [PATCH 2/2] tcg: Add TCGType to tcg_op_insert_{after,before} Richard Henderson
@ 2025-04-22 15:17 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-22 15:17 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: npiggin
On 22/4/25 16:37, Richard Henderson wrote:
> Richard Henderson (2):
> tcg/optimize: Introduce opt_insert_{before,after}
> tcg: Add TCGType to tcg_op_insert_{after,before}
Series:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-22 15:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-22 14:37 [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2 Richard Henderson
2025-04-22 14:37 ` [PATCH 1/2] tcg/optimize: Introduce opt_insert_{before,after} Richard Henderson
2025-04-22 14:37 ` [PATCH 2/2] tcg: Add TCGType to tcg_op_insert_{after,before} Richard Henderson
2025-04-22 15:17 ` [PATCH v4.5 0/2] tcg: Fix TCGOP_TYPE in liveness_pass_2 Philippe Mathieu-Daudé
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).