From patchwork Mon Oct 24 13:46:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 685851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t2dJq0B0pz9sfH for ; Tue, 25 Oct 2016 01:02:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ZkECk2gh; dkim-atps=neutral Received: from localhost ([::1]:46938 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byfpf-000810-Sv for incoming@patchwork.ozlabs.org; Mon, 24 Oct 2016 10:02:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byfbZ-00042k-03 for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:47:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byfbX-0006L3-EH for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:47:57 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:37481) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byfbX-0006Kf-6h for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:47:55 -0400 Received: by mail-wm0-x236.google.com with SMTP id f193so121210978wmg.0 for ; Mon, 24 Oct 2016 06:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=jsAf1pZeBHbuV0chiDj/jpdyv7YhYAn7260u4jm1Y8g=; b=ZkECk2ghaO23WxY1aA0YQjrgwxTeh6cwTj6YirwNdUyN52obyDl4whvicCzLP2ri1k IgSU8KRs53L/lZKtK9+jt3sVfYnwcUmGOoLN0Z9ONCMPGWsuaJe1UYNq3Kb78O5Y4coy iXPs1dDBKH3+1yFJUjm8AO4tWS7AIiP6bKpGCayP24cGC+M7kNiUS1H9xXkOBZVeN/L4 qzjy1UX4O07eJaz2ACLAn3XF21OGys251uC40W+hM18yfWSQHrvenyt4THL8rOYIOmxN A0Oj8zHlrS+USVY+NP9DY9To8TknGhbNDcYSXizi/x6ApZY14oF00zGMfAFzhPcvqNgz FZ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=jsAf1pZeBHbuV0chiDj/jpdyv7YhYAn7260u4jm1Y8g=; b=R0TRQMuN0zM4XloAgEES11yHKm+4Dgq0i1si7yqMnQKBSkvpf43eGpFqJOD4Ocagib kQT8lNJHAp1t2s7su7dK6p3FIoFjh6626HjuPmDQHv3MqahGOoGSQG6XcT9LZeWotkoQ QR7e0gs1LJ4KuAAel+CEdVa/RqSEdggCrOwv9R6JfoDPY634ja/T9AXs7a4Ls0kpCUse sgk38SlmIOdJXHrz+iIALBHeGIMkRiUC/uXLz8b+npSynns60WXhzAXoXxHrrbHpEHHI oqXEUU6G6CwL623uXx+Nr5WgKi9dFaflkMAYkLxQ/OJaowU3d2fbiDaTKkhcUUZWLUmJ 2tdw== X-Gm-Message-State: ABUngvd4/Z1S3rUSISGwDkOSY4ht0NuYdiKl38D7G3mbLB/+i1yD6OEl828OC6EpRNUywg== X-Received: by 10.195.13.107 with SMTP id ex11mr11357251wjd.99.1477316873751; Mon, 24 Oct 2016 06:47:53 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-246-178.clienti.tiscali.it. [78.12.246.178]) by smtp.gmail.com with ESMTPSA id us3sm19434867wjb.32.2016.10.24.06.47.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 06:47:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 24 Oct 2016 15:46:58 +0200 Message-Id: <1477316855-42218-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1477316855-42218-1-git-send-email-pbonzini@redhat.com> References: <1477316855-42218-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::236 Subject: [Qemu-devel] [PULL 13/50] tcg: try sti when moving a constant into a dead memory temp X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This comes from free from unifying tcg_reg_alloc_mov and tcg_reg_alloc_movi's handling of TEMP_VAL_CONST. It triggers often on moves to cc_dst, such as the following translation of "sub $0x3c,%esp": before: after: subl $0x3c,%ebp subl $0x3c,%ebp movl %ebp,0x10(%r14) movl %ebp,0x10(%r14) movl $0x3c,%ebx movl $0x3c,0x2c(%r14) movl %ebx,0x2c(%r14) Signed-off-by: Paolo Bonzini Message-Id: <1473945360-13663-1-git-send-email-pbonzini@redhat.com> Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- tcg/tcg.c | 56 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index c450c62..2d3e498 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2097,15 +2097,9 @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs) save_globals(s, allocated_regs); } -static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args, - TCGLifeData arg_life) +static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots, + tcg_target_ulong val, TCGLifeData arg_life) { - TCGTemp *ots; - tcg_target_ulong val; - - ots = &s->temps[args[0]]; - val = args[1]; - if (ots->fixed_reg) { /* For fixed registers, we do not do any constant propagation. */ tcg_out_movi(s, ots->type, ots->reg, val); @@ -2126,6 +2120,15 @@ static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args, } } +static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args, + TCGLifeData arg_life) +{ + TCGTemp *ots = &s->temps[args[0]]; + tcg_target_ulong val = args[1]; + + tcg_reg_alloc_do_movi(s, ots, val, arg_life); +} + static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, const TCGArg *args, TCGLifeData arg_life) { @@ -2141,21 +2144,29 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, otype = ots->type; itype = ts->type; - /* If the source value is not in a register, and we're going to be - forced to have it in a register in order to perform the copy, - then copy the SOURCE value into its own register first. That way - we don't have to reload SOURCE the next time it is used. */ - if (((NEED_SYNC_ARG(0) || ots->fixed_reg) && ts->val_type != TEMP_VAL_REG) - || ts->val_type == TEMP_VAL_MEM) { + if (ts->val_type == TEMP_VAL_CONST) { + /* propagate constant or generate sti */ + tcg_target_ulong val = ts->val; + if (IS_DEAD_ARG(1)) { + temp_dead(s, ts); + } + tcg_reg_alloc_do_movi(s, ots, val, arg_life); + return; + } + + /* If the source value is in memory we're going to be forced + to have it in a register in order to perform the copy. Copy + the SOURCE value into its own register first, that way we + don't have to reload SOURCE the next time it is used. */ + if (ts->val_type == TEMP_VAL_MEM) { temp_load(s, ts, tcg_target_available_regs[itype], allocated_regs); } + tcg_debug_assert(ts->val_type == TEMP_VAL_REG); if (IS_DEAD_ARG(0) && !ots->fixed_reg) { /* mov to a non-saved dead register makes no sense (even with liveness analysis disabled). */ tcg_debug_assert(NEED_SYNC_ARG(0)); - /* The code above should have moved the temp to a register. */ - tcg_debug_assert(ts->val_type == TEMP_VAL_REG); if (!ots->mem_allocated) { temp_allocate_frame(s, args[0]); } @@ -2164,20 +2175,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, temp_dead(s, ts); } temp_dead(s, ots); - } else if (ts->val_type == TEMP_VAL_CONST) { - /* propagate constant */ - if (ots->val_type == TEMP_VAL_REG) { - s->reg_to_temp[ots->reg] = NULL; - } - ots->val_type = TEMP_VAL_CONST; - ots->val = ts->val; - if (IS_DEAD_ARG(1)) { - temp_dead(s, ts); - } } else { - /* The code in the first if block should have moved the - temp to a register. */ - tcg_debug_assert(ts->val_type == TEMP_VAL_REG); if (IS_DEAD_ARG(1) && !ts->fixed_reg && !ots->fixed_reg) { /* the mov can be suppressed */ if (ots->val_type == TEMP_VAL_REG) {