Blame 0069-tcg-optimize-check-types-in-copy-propagation.patch

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