Skip to contentSkip to conversation

tcg: correctly mark dead inputs for mov with a constant

PATCH Superseded Aurelien Jarno 2 participants 5 messages Jul 24, 2015 – Jul 26, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg: correctly mark dead inputs for mov with a constant

When tcg_reg_alloc_mov propagate a constant, we failed to correctly mark a temp as dead if the liveness analysis hints so. This fixes the following assert when configure with --enable-debug-tcg:

qemu-x86_64: tcg/tcg.c:1827: tcg_reg_alloc_bb_end: Assertion `ts->val_type == TEMP_VAL_DEAD' failed.

---
 tcg/tcg.c | 3 +++
 1 file changed, 3 insertions(+)

This is triggered by the patch "tcg/optimize: allow constant to have copies", but I guess it might be triggered other ways. Therefore it's a good candidate for 2.4.

tcg/tcg.c +3 -0
index 7e088b1..9a2508b 100644
@@ -1920,6 +1920,9 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
         }
         ots->val_type = TEMP_VAL_CONST;
         ots->val = ts->val;
+        if (IS_DEAD_ARG(1)) {
+            temp_dead(s, args[1]);
+        }
     } else {
         /* The code in the first if block should have moved the
            temp to a register. */
Signature · 1 line
2.1.4
#1 lore raw

tcg/tcg.c static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, · line 1925

Quoted 5 lines · Aurelien Jarno
          ots->val_type = TEMP_VAL_CONST;
          ots->val = ts->val;
tcg/tcg.c +3 -0
+        if (IS_DEAD_ARG(1)) {
+            temp_dead(s, args[1]);
+        }

Aren't we also missing

  if (NEED_SYNC_ARG(0)) {
    temp_sync(s, args[0], allocated_regs);
  }

along this path? Seems like there's room for cleanup here, at least for 2.5...

r~

#2 lore raw
Quoted 7 lines · Richard Henderson

tcg/tcg.c static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, · line 1925

Quoted 5 lines · Aurelien Jarno
         ots->val_type = TEMP_VAL_CONST;
         ots->val = ts->val;
tcg/tcg.c +3 -0
+        if (IS_DEAD_ARG(1)) {
+            temp_dead(s, args[1]);
+        }
Quoted 7 lines

Aren't we also missing

  if (NEED_SYNC_ARG(0)) {
    temp_sync(s, args[0], allocated_regs);
  }

along this path?

I don't think so, I guess it's covered by the first part of this function:

|    if (((NEED_SYNC_ARG(0) || ots->fixed_reg) && ts->val_type != TEMP_VAL_REG)
|        || ts->val_type == TEMP_VAL_MEM) {

It means after this block, a value that need to be synced will always be in a register, including in the constant case.

Quoted 1 line

Seems like there's room for cleanup here, at least for 2.5...

I agree we might want to clean a bit the code. It might even go beyond this function, as we repeatedly have almost the same code in various places of tcg.c. For example we can imagine a function "move this temp whatever it is (mem, const, reg) in this register". If we declare it inline, we can leave the compiler do the few optimizations we have done.

But indeed that's for 2.5.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
Reviewed-by
#3 lore raw
Quoted 16 lines · Aurelien Jarno
Quoted 7 lines · Richard Henderson

tcg/tcg.c static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, · line 1925

Quoted 5 lines · Aurelien Jarno
          ots->val_type = TEMP_VAL_CONST;
          ots->val = ts->val;
tcg/tcg.c +3 -0
+        if (IS_DEAD_ARG(1)) {
+            temp_dead(s, args[1]);
+        }
Quoted 7 lines

Aren't we also missing

   if (NEED_SYNC_ARG(0)) {
     temp_sync(s, args[0], allocated_regs);
   }

along this path?

Quoted 8 lines

I don't think so, I guess it's covered by the first part of this function:

|    if (((NEED_SYNC_ARG(0) || ots->fixed_reg) && ts->val_type != TEMP_VAL_REG)
|        || ts->val_type == TEMP_VAL_MEM) {

It means after this block, a value that need to be synced will always be in a register, including in the constant case.

Quite right. Therefore,

Do you want to go ahead and push this for 2.4?

r~

#4 lore raw
Quoted 23 lines · Richard Henderson
Quoted 22 lines · Aurelien Jarno
Quoted 7 lines · Richard Henderson

tcg/tcg.c static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, · line 1925

Quoted 5 lines · Aurelien Jarno
         ots->val_type = TEMP_VAL_CONST;
         ots->val = ts->val;
tcg/tcg.c +3 -0
+        if (IS_DEAD_ARG(1)) {
+            temp_dead(s, args[1]);
+        }
Quoted 7 lines

Aren't we also missing

  if (NEED_SYNC_ARG(0)) {
    temp_sync(s, args[0], allocated_regs);
  }

along this path?

I don't think so, I guess it's covered by the first part of this function:

|    if (((NEED_SYNC_ARG(0) || ots->fixed_reg) && ts->val_type != TEMP_VAL_REG)
|        || ts->val_type == TEMP_VAL_MEM) {
Quoted 8 lines
Quoted 2 lines

It means after this block, a value that need to be synced will always be in a register, including in the constant case.

Quite right. Therefore,

Do you want to go ahead and push this for 2.4?

Yes, I think we should push it for 2.4. Do you want to do the pull request or should I do it?

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