Skip to contentSkip to conversation

tcg: fix dead computation for repeated input arguments

PATCH Superseded Aurelien Jarno 2 participants 3 messages May 19, 2015 – May 21, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg: fix dead computation for repeated input arguments

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 <[email protected]>
---
 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.

tcg/tcg.c +3 -0
index f1558b7..58ca693 100644
@@ -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;
Signature · 1 line
2.1.4
#1 lore raw

tcg/tcg.c static void tcg_liveness_analysis(TCGContext *s) · line 1530

Quoted 10 lines · Aurelien Jarno
tcg/tcg.c +3 -0
@@ -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~

#2 lore raw
Quoted 16 lines · Richard Henderson

tcg/tcg.c static void tcg_liveness_analysis(TCGContext *s) · line 1530

Quoted 10 lines · Aurelien Jarno
tcg/tcg.c +3 -0
@@ -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

Quoted 7 lines

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

for the first and

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

for the second.

Good point.

Quoted 5 lines

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.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net