From patchwork Thu Sep 27 17:19:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 187414 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 38B492C00B5 for ; Fri, 28 Sep 2012 03:20:40 +1000 (EST) Received: from localhost ([::1]:39068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THHlO-0002lq-5S for incoming@patchwork.ozlabs.org; Thu, 27 Sep 2012 13:20:38 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THHlB-0002h8-Sk for qemu-devel@nongnu.org; Thu, 27 Sep 2012 13:20:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THHkz-0003Fy-CC for qemu-devel@nongnu.org; Thu, 27 Sep 2012 13:20:20 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:59438) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THHkz-0003CJ-0l for qemu-devel@nongnu.org; Thu, 27 Sep 2012 13:20:13 -0400 Received: by padfb10 with SMTP id fb10so1531899pad.4 for ; Thu, 27 Sep 2012 10:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=Se3l4F4A1qb1hiwa96sODjUYsP/9zvW2ux25sqQtgv4=; b=TLucQredwa4mQ4Ivqt4Xg1FMwN6WOAtsBFWdNqc1b2B9lgiODja+whO7/fpkPhgPcK s4aoSBCzZ2XcRL3/iLw560vA/KmBgHyqhR78bYUPF/+4exwFHILgJL04JI36MPr3s6kQ JsssoHabOmSlRRMyNaT0ADgwustjhiBcYe4mecfxNFTnr5WguypSIz3QNdd4xdieVqLF O9wqU9xC4+9vSpE4G2+SM8XzNBEjOolyYFg7VbFujk2Ox7DC+E+ztR792Hd23fKlG8Qc Dx9noByRybFzroY5O7pYwhBAjNxHN1ejwLpxcnmtnjDpJJmTBQSaq/pdLFXFsGgeJQ9g 4XEA== Received: by 10.68.234.73 with SMTP id uc9mr13104368pbc.158.1348766408022; Thu, 27 Sep 2012 10:20:08 -0700 (PDT) Received: from anchor.twiddle.home.com ([173.160.232.49]) by mx.google.com with ESMTPS id jw14sm4118581pbb.36.2012.09.27.10.20.06 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 10:20:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2012 10:19:51 -0700 Message-Id: <1348766397-20731-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1348766397-20731-1-git-send-email-rth@twiddle.net> References: <1348766397-20731-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.45 Cc: Aurelien Jarno Subject: [Qemu-devel] [PATCH 1/7] tcg: Split out swap_commutative as a subroutine 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 Reduces code duplication and prefers movcond d, c1, c2, const, s to movcond d, c1, c2, s, const Signed-off-by: Richard Henderson Reviewed-by: Aurelien Jarno --- tcg/optimize.c | 54 ++++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 35532a1..55f2a24 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -382,6 +382,21 @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, tcg_abort(); } +static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) +{ + TCGArg a1 = *p1, a2 = *p2; + /* Prefer the constant in second argument, and then the form + op a, a, b, which is better handled on non-RISC hosts. */ + if (temps[a1].state == TCG_TEMP_CONST + || (dest != (TCGArg)-1 && dest == a2 + && temps[a2].state != TCG_TEMP_CONST)) { + *p1 = a2; + *p2 = a1; + return true; + } + return false; +} + /* Propagate constants and copies, fold constant expressions. */ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, TCGArg *args, TCGOpDef *tcg_op_defs) @@ -391,7 +406,6 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, const TCGOpDef *def; TCGArg *gen_args; TCGArg tmp; - TCGCond cond; /* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' element. @@ -434,52 +448,28 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, CASE_OP_32_64(eqv): CASE_OP_32_64(nand): CASE_OP_32_64(nor): - /* Prefer the constant in second argument, and then the form - op a, a, b, which is better handled on non-RISC hosts. */ - if (temps[args[1]].state == TCG_TEMP_CONST || (args[0] == args[2] - && temps[args[2]].state != TCG_TEMP_CONST)) { - tmp = args[1]; - args[1] = args[2]; - args[2] = tmp; - } + swap_commutative(args[0], &args[1], &args[2]); break; CASE_OP_32_64(brcond): - if (temps[args[0]].state == TCG_TEMP_CONST - && temps[args[1]].state != TCG_TEMP_CONST) { - tmp = args[0]; - args[0] = args[1]; - args[1] = tmp; + if (swap_commutative(-1, &args[0], &args[1])) { args[2] = tcg_swap_cond(args[2]); } break; CASE_OP_32_64(setcond): - 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; + if (swap_commutative(args[0], &args[1], &args[2])) { args[3] = tcg_swap_cond(args[3]); } break; CASE_OP_32_64(movcond): - cond = args[5]; - 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; - cond = tcg_swap_cond(cond); + if (swap_commutative(-1, &args[1], &args[2])) { + args[5] = tcg_swap_cond(args[5]); } /* For movcond, we canonicalize the "false" input reg to match the destination reg so that the tcg backend can implement a "move if true" operation. */ - if (args[0] == args[3]) { - tmp = args[3]; - args[3] = args[4]; - args[4] = tmp; - cond = tcg_invert_cond(cond); + if (swap_commutative(args[0], &args[4], &args[3])) { + args[5] = tcg_invert_cond(args[5]); } - args[5] = cond; default: break; }