5544c1b
From 71f0bcf065ddd00d5659e846ddfdffb9a06ee896 Mon Sep 17 00:00:00 2001
5544c1b
From: Aurelien Jarno <aurelien@aurel32.net>
5544c1b
Date: Tue, 11 Sep 2012 12:26:23 +0200
5544c1b
Subject: [PATCH] tcg/optimize: check types in copy propagation
5544c1b
5544c1b
The copy propagation doesn't check the types of the temps during copy
5544c1b
propagation. However TCG is using the mov_i32 for the i64 to i32
5544c1b
conversion and thus the two are not equivalent.
5544c1b
5544c1b
With this patch tcg_opt_gen_mov() doesn't consider two temps of
5544c1b
different type as copies anymore.
5544c1b
5544c1b
So far it seems the optimization was not aggressive enough to trigger
5544c1b
this bug, but it will be triggered later in this series once the copy
5544c1b
propagation is improved.
5544c1b
5544c1b
Reviewed-by: Richard Henderson <rth@twiddle.net>
5544c1b
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1b
---
5544c1b
 tcg/optimize.c | 18 ++++++++----------
5544c1b
 1 file changed, 8 insertions(+), 10 deletions(-)
5544c1b
5544c1b
diff --git a/tcg/optimize.c b/tcg/optimize.c
5544c1b
index 308b7f9..da8dffe 100644
5544c1b
--- a/tcg/optimize.c
5544c1b
+++ b/tcg/optimize.c
5544c1b
@@ -106,12 +106,13 @@ static TCGOpcode op_to_movi(TCGOpcode op)
5544c1b
     }
5544c1b
 }
5544c1b
 
5544c1b
-static void tcg_opt_gen_mov(TCGArg *gen_args, TCGArg dst, TCGArg src,
5544c1b
-                            int nb_temps, int nb_globals)
5544c1b
+static void tcg_opt_gen_mov(TCGContext *s, TCGArg *gen_args,
5544c1b
+                            TCGArg dst, TCGArg src)
5544c1b
 {
5544c1b
-        reset_temp(dst, nb_temps, nb_globals);
5544c1b
+        reset_temp(dst, s->nb_temps, s->nb_globals);
5544c1b
         assert(temps[src].state != TCG_TEMP_COPY);
5544c1b
-        if (src >= nb_globals) {
5544c1b
+        /* Only consider temps with the same type (width) as copies. */
5544c1b
+        if (src >= s->nb_globals && s->temps[dst].type == s->temps[src].type) {
5544c1b
             assert(temps[src].state != TCG_TEMP_CONST);
5544c1b
             if (temps[src].state != TCG_TEMP_HAS_COPY) {
5544c1b
                 temps[src].state = TCG_TEMP_HAS_COPY;
5544c1b
@@ -461,8 +462,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1b
                     gen_opc_buf[op_index] = INDEX_op_nop;
5544c1b
                 } else {
5544c1b
                     gen_opc_buf[op_index] = op_to_mov(op);
5544c1b
-                    tcg_opt_gen_mov(gen_args, args[0], args[1],
5544c1b
-                                    nb_temps, nb_globals);
5544c1b
+                    tcg_opt_gen_mov(s, gen_args, args[0], args[1]);
5544c1b
                     gen_args += 2;
5544c1b
                 }
5544c1b
                 args += 3;
5544c1b
@@ -499,8 +499,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1b
                     gen_opc_buf[op_index] = INDEX_op_nop;
5544c1b
                 } else {
5544c1b
                     gen_opc_buf[op_index] = op_to_mov(op);
5544c1b
-                    tcg_opt_gen_mov(gen_args, args[0], args[1], nb_temps,
5544c1b
-                                    nb_globals);
5544c1b
+                    tcg_opt_gen_mov(s, gen_args, args[0], args[1]);
5544c1b
                     gen_args += 2;
5544c1b
                 }
5544c1b
                 args += 3;
5544c1b
@@ -524,8 +523,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
5544c1b
                 break;
5544c1b
             }
5544c1b
             if (temps[args[1]].state != TCG_TEMP_CONST) {
5544c1b
-                tcg_opt_gen_mov(gen_args, args[0], args[1],
5544c1b
-                                nb_temps, nb_globals);
5544c1b
+                tcg_opt_gen_mov(s, gen_args, args[0], args[1]);
5544c1b
                 gen_args += 2;
5544c1b
                 args += 2;
5544c1b
                 break;