All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tcg: fix dead computation for repeated input arguments
@ 2015-05-19 10:26 Aurelien Jarno
  2015-05-19 14:46 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Aurelien Jarno @ 2015-05-19 10:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Aurelien Jarno, Richard Henderson

When the same temp is used twice or more as an input argument to a TCG
instruction, the dead computation code doesn't recognize the second use
as a dead temp. This is because the temp is marked as live in the same
loop where dead inputs are checked.

The fix is to split the loop in two parts. This avoid emitting a move
and using a register for the movcond instruction when used as "move if
true" on x86-64. This might bring more improvements on RISC TCG targets
which don't have outputs aliased to inputs.

Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 tcg/tcg.c | 3 +++
 1 file changed, 3 insertions(+)

NB: The dead computation loop for call has the same problem, but it will
not improve the generated code as anyway the value has to be copied to
a register or memory. I am therefore not sure it is worth fixing it as
it might bring some performance penalty.

diff --git a/tcg/tcg.c b/tcg/tcg.c
index f1558b7..58ca693 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -1522,6 +1522,9 @@ static void tcg_liveness_analysis(TCGContext *s)
                     if (dead_temps[arg]) {
                         dead_args |= (1 << i);
                     }
+                }
+                for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
+                    arg = args[i];
                     dead_temps[arg] = 0;
                 }
                 s->op_dead_args[oi] = dead_args;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] tcg: fix dead computation for repeated input arguments
  2015-05-19 10:26 [Qemu-devel] [PATCH] tcg: fix dead computation for repeated input arguments Aurelien Jarno
@ 2015-05-19 14:46 ` Richard Henderson
  2015-05-21 18:35   ` Aurelien Jarno
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2015-05-19 14:46 UTC (permalink / raw)
  To: Aurelien Jarno, qemu-devel

On 05/19/2015 03:26 AM, Aurelien Jarno wrote:
> @@ -1522,6 +1522,9 @@ static void tcg_liveness_analysis(TCGContext *s)
>                      if (dead_temps[arg]) {
>                          dead_args |= (1 << i);
>                      }
> +                }
> +                for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
> +                    arg = args[i];
>                      dead_temps[arg] = 0;
>                  }
>                  s->op_dead_args[oi] = dead_args;

How about another line of commentary for each loop?

Something like

  /* Record arguments that die in this opcode.  */

for the first and

  /* Input arguments are live for preceeding opcodes.  */

for the second.

As for the same loop for calls, you're right that it may well cause us to do a
tiny bit of redundant work, but nothing else bad will happen.  We'll enter
temp_dead more times than necessary.  I'm always skeptical about knowingly
giving a compiler bad information though.  You tend to not know how data is
going to be used in future, and *then* get bad results.


r~

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] tcg: fix dead computation for repeated input arguments
  2015-05-19 14:46 ` Richard Henderson
@ 2015-05-21 18:35   ` Aurelien Jarno
  0 siblings, 0 replies; 3+ messages in thread
From: Aurelien Jarno @ 2015-05-21 18:35 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On 2015-05-19 07:46, Richard Henderson wrote:
> On 05/19/2015 03:26 AM, Aurelien Jarno wrote:
> > @@ -1522,6 +1522,9 @@ static void tcg_liveness_analysis(TCGContext *s)
> >                      if (dead_temps[arg]) {
> >                          dead_args |= (1 << i);
> >                      }
> > +                }
> > +                for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
> > +                    arg = args[i];
> >                      dead_temps[arg] = 0;
> >                  }
> >                  s->op_dead_args[oi] = dead_args;
> 
> How about another line of commentary for each loop?
> 
> Something like
> 
>   /* Record arguments that die in this opcode.  */
> 
> for the first and
> 
>   /* Input arguments are live for preceeding opcodes.  */
> 
> for the second.

Good point.

> As for the same loop for calls, you're right that it may well cause us to do a
> tiny bit of redundant work, but nothing else bad will happen.  We'll enter
> temp_dead more times than necessary.  I'm always skeptical about knowingly
> giving a compiler bad information though.  You tend to not know how data is
> going to be used in future, and *then* get bad results.

You are correct. Anyway I don't think it'll make a big difference in
performance.

I'll send a new version of the patch.

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-21 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-19 10:26 [Qemu-devel] [PATCH] tcg: fix dead computation for repeated input arguments Aurelien Jarno
2015-05-19 14:46 ` Richard Henderson
2015-05-21 18:35   ` Aurelien Jarno

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.