* [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp
@ 2016-09-15 13:16 Paolo Bonzini
2016-09-20 20:41 ` Richard Henderson
2016-09-22 21:09 ` Richard Henderson
0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-09-15 13:16 UTC (permalink / raw)
To: qemu-devel; +Cc: rth
This comes from free from unifying tcg_reg_alloc_mov and
tcg_reg_alloc_movi's handling of TEMP_VAL_CONST. It triggers
often on moves to cc_dst, such as the following translation
of "sub $0x3c,%esp":
before: after:
subl $0x3c,%ebp subl $0x3c,%ebp
movl %ebp,0x10(%r14) movl %ebp,0x10(%r14)
movl $0x3c,%ebx movl $0x3c,0x2c(%r14)
movl %ebx,0x2c(%r14)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
tcg/tcg.c | 56 +++++++++++++++++++++++++++-----------------------------
1 file changed, 27 insertions(+), 29 deletions(-)
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 42417bd..77a19b6 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -2099,15 +2099,9 @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs)
save_globals(s, allocated_regs);
}
-static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args,
- TCGLifeData arg_life)
+static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots,
+ tcg_target_ulong val, TCGLifeData arg_life)
{
- TCGTemp *ots;
- tcg_target_ulong val;
-
- ots = &s->temps[args[0]];
- val = args[1];
-
if (ots->fixed_reg) {
/* For fixed registers, we do not do any constant propagation. */
tcg_out_movi(s, ots->type, ots->reg, val);
@@ -2128,6 +2122,15 @@ static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args,
}
}
+static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args,
+ TCGLifeData arg_life)
+{
+ TCGTemp *ots = &s->temps[args[0]];
+ tcg_target_ulong val = args[1];
+
+ tcg_reg_alloc_do_movi(s, ots, val, arg_life);
+}
+
static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
const TCGArg *args, TCGLifeData arg_life)
{
@@ -2143,21 +2146,29 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
otype = ots->type;
itype = ts->type;
- /* If the source value is not in a register, and we're going to be
- forced to have it in a register in order to perform the copy,
- then copy the SOURCE value into its own register first. That way
- we don't have to reload SOURCE the next time it is used. */
- if (((NEED_SYNC_ARG(0) || ots->fixed_reg) && ts->val_type != TEMP_VAL_REG)
- || ts->val_type == TEMP_VAL_MEM) {
+ if (ts->val_type == TEMP_VAL_CONST) {
+ /* propagate constant or generate sti */
+ tcg_target_ulong val = ts->val;
+ if (IS_DEAD_ARG(1)) {
+ temp_dead(s, ts);
+ }
+ tcg_reg_alloc_do_movi(s, ots, val, arg_life);
+ return;
+ }
+
+ /* If the source value is in memory we're going to be forced
+ to have it in a register in order to perform the copy. Copy
+ the SOURCE value into its own register first, that way we
+ don't have to reload SOURCE the next time it is used. */
+ if (ts->val_type == TEMP_VAL_MEM) {
temp_load(s, ts, tcg_target_available_regs[itype], allocated_regs);
}
+ tcg_debug_assert(ts->val_type == TEMP_VAL_REG);
if (IS_DEAD_ARG(0) && !ots->fixed_reg) {
/* mov to a non-saved dead register makes no sense (even with
liveness analysis disabled). */
tcg_debug_assert(NEED_SYNC_ARG(0));
- /* The code above should have moved the temp to a register. */
- tcg_debug_assert(ts->val_type == TEMP_VAL_REG);
if (!ots->mem_allocated) {
temp_allocate_frame(s, args[0]);
}
@@ -2166,20 +2177,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
temp_dead(s, ts);
}
temp_dead(s, ots);
- } else if (ts->val_type == TEMP_VAL_CONST) {
- /* propagate constant */
- if (ots->val_type == TEMP_VAL_REG) {
- s->reg_to_temp[ots->reg] = NULL;
- }
- ots->val_type = TEMP_VAL_CONST;
- ots->val = ts->val;
- if (IS_DEAD_ARG(1)) {
- temp_dead(s, ts);
- }
} else {
- /* The code in the first if block should have moved the
- temp to a register. */
- tcg_debug_assert(ts->val_type == TEMP_VAL_REG);
if (IS_DEAD_ARG(1) && !ts->fixed_reg && !ots->fixed_reg) {
/* the mov can be suppressed */
if (ots->val_type == TEMP_VAL_REG) {
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp
2016-09-15 13:16 [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp Paolo Bonzini
@ 2016-09-20 20:41 ` Richard Henderson
2016-09-21 13:37 ` Paolo Bonzini
2016-09-22 21:09 ` Richard Henderson
1 sibling, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2016-09-20 20:41 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel
On 09/15/2016 06:16 AM, Paolo Bonzini wrote:
> This comes from free from unifying tcg_reg_alloc_mov and
> tcg_reg_alloc_movi's handling of TEMP_VAL_CONST. It triggers
> often on moves to cc_dst, such as the following translation
> of "sub $0x3c,%esp":
>
> before: after:
> subl $0x3c,%ebp subl $0x3c,%ebp
> movl %ebp,0x10(%r14) movl %ebp,0x10(%r14)
> movl $0x3c,%ebx movl $0x3c,0x2c(%r14)
> movl %ebx,0x2c(%r14)
What's the input here? From just this snippet it looks as if we should have
converted both of them to an immediate store.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp
2016-09-20 20:41 ` Richard Henderson
@ 2016-09-21 13:37 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-09-21 13:37 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
On 20/09/2016 22:41, Richard Henderson wrote:
> On 09/15/2016 06:16 AM, Paolo Bonzini wrote:
>> This comes from free from unifying tcg_reg_alloc_mov and
>> tcg_reg_alloc_movi's handling of TEMP_VAL_CONST. It triggers
>> often on moves to cc_dst, such as the following translation
>> of "sub $0x3c,%esp":
>>
>> before: after:
>> subl $0x3c,%ebp subl $0x3c,%ebp
>> movl %ebp,0x10(%r14) movl %ebp,0x10(%r14)
>> movl $0x3c,%ebx movl $0x3c,0x2c(%r14)
>> movl %ebx,0x2c(%r14)
>
> What's the input here? From just this snippet it looks as if we should have
> converted both of them to an immediate store.
I don't have the exact binary but this is what I get from qemu
movi_i32 tmp1,$0x20
sub_i32 tmp0,esp,tmp1 dead: 1
mov_i32 esp,tmp0 sync: 0 dead: 1
mov_i32 cc_src,tmp1 sync: 0 dead: 0 1
mov_i32 cc_dst,esp sync: 0 dead: 0
discard cc_src2
discard cc_op
which is compiled to
0x7f98ed3ff761: mov %ebx,(%rsi) ; load esp
0x7f98ed3ff763: sub $0x20,%ebp ; sub_i32 tmp0,esp,tmp1
0x7f98ed3ff766: mov %ebp,0x10(%r14)
0x7f98ed3ff76a: mov $0x20,%ebx ; mov_i32 cc_src,tmp1
0x7f98ed3ff76f: mov %ebx,0x2c(%r14)
0x7f98ed3ff773: mov %ebp,0x28(%r14) ; mov_i32 cc_dst,esp
TCG doesn't convert the "mov_i32 cc_src,tmp1" to movi, instead it tracks
the register as a TEMP_VAL_CONST.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp
2016-09-15 13:16 [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp Paolo Bonzini
2016-09-20 20:41 ` Richard Henderson
@ 2016-09-22 21:09 ` Richard Henderson
1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2016-09-22 21:09 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel
On 09/15/2016 06:16 AM, Paolo Bonzini wrote:
> This comes from free from unifying tcg_reg_alloc_mov and
> tcg_reg_alloc_movi's handling of TEMP_VAL_CONST. It triggers
> often on moves to cc_dst, such as the following translation
> of "sub $0x3c,%esp":
>
> before: after:
> subl $0x3c,%ebp subl $0x3c,%ebp
> movl %ebp,0x10(%r14) movl %ebp,0x10(%r14)
> movl $0x3c,%ebx movl $0x3c,0x2c(%r14)
> movl %ebx,0x2c(%r14)
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tcg/tcg.c | 56 +++++++++++++++++++++++++++-----------------------------
> 1 file changed, 27 insertions(+), 29 deletions(-)
Queued. Thanks,
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-22 21:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-15 13:16 [Qemu-devel] [PATCH] tcg: try sti when moving a constant into a dead memory temp Paolo Bonzini
2016-09-20 20:41 ` Richard Henderson
2016-09-21 13:37 ` Paolo Bonzini
2016-09-22 21:09 ` Richard Henderson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.