qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Cc: Aurelien Jarno <aurelien@aurel32.net>
Subject: [Qemu-devel] [PATCH v2 02/10] tcg/optimize: check types in copy propagation
Date: Fri, 21 Sep 2012 21:43:10 +0200	[thread overview]
Message-ID: <1348256598-8146-3-git-send-email-aurelien@aurel32.net> (raw)
In-Reply-To: <1348256598-8146-1-git-send-email-aurelien@aurel32.net>

The copy propagation doesn't check the types of the temps during copy
propagation. However TCG is using the mov_i32 for the i64 to i32
conversion and thus the two are not equivalent.

With this patch tcg_opt_gen_mov() doesn't consider two temps of
different type as copies anymore.

So far it seems the optimization was not aggressive enough to trigger
this bug, but it will be triggered later in this series once the copy
propagation is improved.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 tcg/optimize.c |   18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index 308b7f9..da8dffe 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -106,12 +106,13 @@ static TCGOpcode op_to_movi(TCGOpcode op)
     }
 }
 
-static void tcg_opt_gen_mov(TCGArg *gen_args, TCGArg dst, TCGArg src,
-                            int nb_temps, int nb_globals)
+static void tcg_opt_gen_mov(TCGContext *s, TCGArg *gen_args,
+                            TCGArg dst, TCGArg src)
 {
-        reset_temp(dst, nb_temps, nb_globals);
+        reset_temp(dst, s->nb_temps, s->nb_globals);
         assert(temps[src].state != TCG_TEMP_COPY);
-        if (src >= nb_globals) {
+        /* Only consider temps with the same type (width) as copies. */
+        if (src >= s->nb_globals && s->temps[dst].type == s->temps[src].type) {
             assert(temps[src].state != TCG_TEMP_CONST);
             if (temps[src].state != TCG_TEMP_HAS_COPY) {
                 temps[src].state = TCG_TEMP_HAS_COPY;
@@ -461,8 +462,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
                     gen_opc_buf[op_index] = INDEX_op_nop;
                 } else {
                     gen_opc_buf[op_index] = op_to_mov(op);
-                    tcg_opt_gen_mov(gen_args, args[0], args[1],
-                                    nb_temps, nb_globals);
+                    tcg_opt_gen_mov(s, gen_args, args[0], args[1]);
                     gen_args += 2;
                 }
                 args += 3;
@@ -499,8 +499,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
                     gen_opc_buf[op_index] = INDEX_op_nop;
                 } else {
                     gen_opc_buf[op_index] = op_to_mov(op);
-                    tcg_opt_gen_mov(gen_args, args[0], args[1], nb_temps,
-                                    nb_globals);
+                    tcg_opt_gen_mov(s, gen_args, args[0], args[1]);
                     gen_args += 2;
                 }
                 args += 3;
@@ -524,8 +523,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
                 break;
             }
             if (temps[args[1]].state != TCG_TEMP_CONST) {
-                tcg_opt_gen_mov(gen_args, args[0], args[1],
-                                nb_temps, nb_globals);
+                tcg_opt_gen_mov(s, gen_args, args[0], args[1]);
                 gen_args += 2;
                 args += 2;
                 break;
-- 
1.7.10.4

  parent reply	other threads:[~2012-09-21 19:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-21 19:43 [Qemu-devel] [PATCH v2 00/10] tcg/optimize: rework copy propagation Aurelien Jarno
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 01/10] tcg/optimize: remove TCG_TEMP_ANY Aurelien Jarno
2012-09-21 19:43 ` Aurelien Jarno [this message]
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 03/10] tcg/optimize: rework copy progagation Aurelien Jarno
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 04/10] tcg/optimize: do copy propagation for all operations Aurelien Jarno
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 05/10] tcg/optimize: optimize "op r, a, a => mov r, a" Aurelien Jarno
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 06/10] tcg/optimize: optimize "op r, a, a => movi r, 0" Aurelien Jarno
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 07/10] tcg/optimize: further optimize brcond/movcond/setcond Aurelien Jarno
2012-09-21 23:17   ` Richard Henderson
2012-09-22  9:35     ` Aurelien Jarno
2012-09-22 12:46       ` Richard Henderson
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 08/10] tcg/optimize: prefer the "op a, a, b" form for commutative ops Aurelien Jarno
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 09/10] tcg: remove #ifdef #endif around TCGOpcode tests Aurelien Jarno
2012-09-21 19:43 ` [Qemu-devel] [PATCH v2 10/10] tcg/optimize: add constant folding for deposit Aurelien Jarno
2012-09-21 23:22   ` Richard Henderson
2012-09-22  9:41     ` Aurelien Jarno
2012-09-22 12:45       ` Richard Henderson
2012-09-22 14:41       ` Blue Swirl
2012-09-21 23:23 ` [Qemu-devel] [PATCH v2 00/10] tcg/optimize: rework copy propagation Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1348256598-8146-3-git-send-email-aurelien@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).