From patchwork Thu Sep 20 22:04:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 185512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3FF812C0084 for ; Fri, 21 Sep 2012 08:04:45 +1000 (EST) Received: from localhost ([::1]:50282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEorS-0006xz-UE for incoming@patchwork.ozlabs.org; Thu, 20 Sep 2012 18:04:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEorK-0006xl-27 for qemu-devel@nongnu.org; Thu, 20 Sep 2012 18:04:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TEorH-0002R7-TM for qemu-devel@nongnu.org; Thu, 20 Sep 2012 18:04:33 -0400 Received: from hall.aurel32.net ([88.191.126.93]:38715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEorH-0002QB-KB for qemu-devel@nongnu.org; Thu, 20 Sep 2012 18:04:31 -0400 Received: from [2001:470:d4ed:1:2db:dfff:fe14:52d] (helo=ohm.aurel32.net) by hall.aurel32.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TEor6-0003Uj-Me; Fri, 21 Sep 2012 00:04:20 +0200 Received: from aurel32 by ohm.aurel32.net with local (Exim 4.80) (envelope-from ) id 1TEor5-00013J-Ii; Fri, 21 Sep 2012 00:04:19 +0200 Date: Fri, 21 Sep 2012 00:04:19 +0200 From: Aurelien Jarno To: Richard Henderson Message-ID: <20120920220419.GC4457@ohm.aurel32.net> References: <1347978240-20260-1-git-send-email-rth@twiddle.net> <1347978240-20260-5-git-send-email-rth@twiddle.net> <20120918211148.GA20933@ohm.aurel32.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120918211148.GA20933@ohm.aurel32.net> X-Mailer: Mutt 1.5.21 (2010-09-15) User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 88.191.126.93 Cc: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH 4/5] tcg: Optimize movcond for constant comparisons X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 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-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Tue, Sep 18, 2012 at 11:11:48PM +0200, Aurelien Jarno wrote: > On Tue, Sep 18, 2012 at 07:23:59AM -0700, Richard Henderson wrote: > > Signed-off-by: Richard Henderson > > --- > > tcg/optimize.c | 29 +++++++++++++++++++++++++++++ > > 1 file changed, 29 insertions(+) > > > > diff --git a/tcg/optimize.c b/tcg/optimize.c > > index fba0ed9..5b0a8ce 100644 > > --- a/tcg/optimize.c > > +++ b/tcg/optimize.c > > @@ -397,6 +397,14 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, > > args[3] = tcg_swap_cond(args[3]); > > } > > break; > > + CASE_OP_32_64(movcond): > > + if (temps[args[1]].state == TCG_TEMP_CONST > > + && temps[args[2]].state != TCG_TEMP_CONST) { > > + tmp = args[1]; > > + args[1] = args[2]; > > + args[2] = tmp; > > + args[5] = tcg_swap_cond(args[5]); > > + } > > default: > > break; > > } > > @@ -617,6 +625,27 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, > > } > > args += 4; > > break; > > + CASE_OP_33_64(movcond): > > + if (temps[args[1]].state == TCG_TEMP_CONST > > + && temps[args[2]].state == TCG_TEMP_CONST) { > > + gen_opc_buf[op_index] = op_to_mov(op); > > + tmp = do_constant_folding_cond(op, temps[args[1]].val, > > + temps[args[2]].val, args[5]); > > + tcg_opt_gen_mov(s, gen_args, args[0], args[4-tmp], > > + nb_temps, nb_globals); > > + gen_args += 2; > > + } else { > > + reset_temp(args[0], nb_temps, nb_globals); > > + gen_args[0] = args[0]; > > + gen_args[1] = args[1]; > > + gen_args[2] = args[2]; > > + gen_args[3] = args[3]; > > + gen_args[4] = args[4]; > > + gen_args[5] = args[5]; > > + gen_args += 6; > > + } > > + args += 6; > > + break; > > case INDEX_op_call: > > nb_call_args = (args[0] >> 16) + (args[0] & 0xffff); > > if (!(args[nb_call_args + 1] & (TCG_CALL_CONST | TCG_CALL_PURE))) { > > -- > > 1.7.11.4 > > > > Reviewed-by: Aurelien Jarno Playing a bit more with this patch, I have found it fails when v1 or v2 or constants or copies. The additional patch below fixes the problem. diff --git a/tcg/optimize.c b/tcg/optimize.c index f95c511..b7e235e 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -641,12 +641,23 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, CASE_OP_32_64(movcond): if (temps[args[1]].state == TCG_TEMP_CONST && temps[args[2]].state == TCG_TEMP_CONST) { - gen_opc_buf[op_index] = op_to_mov(op); tmp = do_constant_folding_cond(op, temps[args[1]].val, temps[args[2]].val, args[5]); - tcg_opt_gen_mov(gen_args, args[0], args[4-tmp], - nb_temps, nb_globals); - gen_args += 2; + if ((temps[args[4-tmp]].state == TCG_TEMP_COPY + && temps[args[4-tmp]].val == args[0]) + || args[0] == args[4-tmp]) { + gen_opc_buf[op_index] = INDEX_op_nop; + } else if (tmp && temps[args[4-tmp]].state == TCG_TEMP_CONST) { + gen_opc_buf[op_index] = op_to_movi(op); + tcg_opt_gen_movi(gen_args, args[0], temps[args[4-tmp]].val, + nb_temps, nb_globals); + gen_args += 2; + } else { + gen_opc_buf[op_index] = op_to_mov(op); + tcg_opt_gen_mov(gen_args, args[0], args[4-tmp], + nb_temps, nb_globals); + gen_args += 2; + } } else { reset_temp(args[0], nb_temps, nb_globals); gen_args[0] = args[0];