qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: Aurelien Jarno <aurelien@aurel32.net>
Subject: [Qemu-devel] [PATCH 09/10] tcg: Optimize half-dead add2/sub2
Date: Tue,  2 Oct 2012 11:32:29 -0700	[thread overview]
Message-ID: <1349202750-16815-10-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1349202750-16815-1-git-send-email-rth@twiddle.net>

When x86_64 guest is not in 64-bit mode, the high-part of the 64-bit
add is dead.  When the host is 32-bit, we can simplify to 32-bit
arithmetic.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 tcg/tcg.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index c069e44..21c1074 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -1306,8 +1306,39 @@ static void tcg_liveness_analysis(TCGContext *s)
             break;
         case INDEX_op_end:
             break;
-            /* XXX: optimize by hardcoding common cases (e.g. triadic ops) */
+
+        case INDEX_op_add2_i32:
+        case INDEX_op_sub2_i32:
+            args -= 6;
+            nb_iargs = 4;
+            nb_oargs = 2;
+            /* Test if the high part of the operation is dead, but not
+               the low part.  The result can be optimized to a simple
+               add or sub.  This happens often for x86_64 guest when the
+               cpu mode is set to 32 bit.  */
+            if (dead_temps[args[1]]) {
+                if (dead_temps[args[0]]) {
+                    goto do_remove;
+                }
+                /* Create the single operation plus nop.  */
+                if (op == INDEX_op_add2_i32) {
+                    op = INDEX_op_add_i32;
+                } else {
+                    op = INDEX_op_sub_i32;
+                }
+                gen_opc_buf[op_index] = op;
+                args[1] = args[2];
+                args[2] = args[4];
+                assert(gen_opc_buf[op_index + 1] == INDEX_op_nop);
+                tcg_set_nop(s, gen_opc_buf + op_index + 1, args + 3, 3);
+                /* Fall through and mark the single-word operation live.  */
+                nb_iargs = 2;
+                nb_oargs = 1;
+            }
+            goto do_not_remove;
+
         default:
+            /* XXX: optimize by hardcoding common cases (e.g. triadic ops) */
             args -= def->nb_args;
             nb_iargs = def->nb_iargs;
             nb_oargs = def->nb_oargs;
@@ -1321,6 +1352,7 @@ static void tcg_liveness_analysis(TCGContext *s)
                     if (!dead_temps[arg])
                         goto do_not_remove;
                 }
+            do_remove:
                 tcg_set_nop(s, gen_opc_buf + op_index, args, def->nb_args);
 #ifdef CONFIG_PROFILER
                 s->del_op_count++;
-- 
1.7.11.4

  parent reply	other threads:[~2012-10-02 18:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-02 18:32 [Qemu-devel] [PATCH v2 00/10] Double-word tcg/optimize improvements Richard Henderson
2012-10-02 18:32 ` [Qemu-devel] [PATCH 01/10] tcg: Split out swap_commutative as a subroutine Richard Henderson
2012-10-09 15:13   ` Aurelien Jarno
2012-10-09 15:23     ` Richard Henderson
2012-10-09 15:31       ` Aurelien Jarno
2012-10-09 16:40         ` Richard Henderson
2012-10-02 18:32 ` [Qemu-devel] [PATCH 02/10] tcg: Canonicalize add2 operand ordering Richard Henderson
2012-10-09 15:14   ` Aurelien Jarno
2012-10-02 18:32 ` [Qemu-devel] [PATCH 03/10] tcg: Swap commutative double-word comparisons Richard Henderson
2012-10-09 15:16   ` Aurelien Jarno
2012-10-09 15:31     ` Richard Henderson
2012-10-09 15:48       ` Aurelien Jarno
2012-10-02 18:32 ` [Qemu-devel] [PATCH 04/10] tcg: Use common code when failing to optimize Richard Henderson
2012-10-09 15:25   ` Aurelien Jarno
2012-10-09 15:33     ` Richard Henderson
2012-10-02 18:32 ` [Qemu-devel] [PATCH 05/10] tcg: Optimize double-word comparisons against zero Richard Henderson
2012-10-09 16:32   ` Aurelien Jarno
2012-10-02 18:32 ` [Qemu-devel] [PATCH 06/10] tcg: Split out subroutines from do_constant_folding_cond Richard Henderson
2012-10-09 16:33   ` Aurelien Jarno
2012-10-02 18:32 ` [Qemu-devel] [PATCH 07/10] tcg: Do constant folding on double-word comparisons Richard Henderson
2012-10-10  9:45   ` Aurelien Jarno
2012-10-02 18:32 ` [Qemu-devel] [PATCH 08/10] tcg: Constant fold add2 and sub2 Richard Henderson
2012-10-10  9:52   ` Aurelien Jarno
2012-10-02 18:32 ` Richard Henderson [this message]
2012-10-16 23:25   ` [Qemu-devel] [PATCH 09/10] tcg: Optimize half-dead add2/sub2 Aurelien Jarno
2012-10-02 18:32 ` [Qemu-devel] [PATCH 10/10] tcg: Optimize mulu2 Richard Henderson
2012-10-16 23:25   ` Aurelien Jarno
2012-10-17  1:09     ` Richard Henderson
2012-10-17 10:58       ` Avi Kivity
2012-10-17 16:41 ` [Qemu-devel] [PATCH v2 00/10] Double-word tcg/optimize improvements Aurelien Jarno

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=1349202750-16815-10-git-send-email-rth@twiddle.net \
    --to=rth@twiddle.net \
    --cc=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).