From patchwork Thu Jul 7 12:37:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Batuzov X-Patchwork-Id: 103651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4F20E1007D1 for ; Thu, 7 Jul 2011 22:52:01 +1000 (EST) Received: from localhost ([::1]:55249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qeo3g-0003Gw-Nz for incoming@patchwork.ozlabs.org; Thu, 07 Jul 2011 08:51:56 -0400 Received: from eggs.gnu.org ([140.186.70.92]:45454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qenpj-0000VL-DY for qemu-devel@nongnu.org; Thu, 07 Jul 2011 08:37:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qenpg-0005YC-35 for qemu-devel@nongnu.org; Thu, 07 Jul 2011 08:37:31 -0400 Received: from smtp.ispras.ru ([83.149.198.202]:51663) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qenpf-0005Xm-4z for qemu-devel@nongnu.org; Thu, 07 Jul 2011 08:37:27 -0400 Received: from ispserv.ispras.ru (ispserv.ispras.ru [83.149.198.72]) by smtp.ispras.ru (Postfix) with ESMTP id 9EE905D407D; Thu, 7 Jul 2011 16:30:31 +0400 (MSD) Received: from bulbul.intra.ispras.ru (winnie.ispras.ru [83.149.198.236]) by ispserv.ispras.ru (Postfix) with ESMTP id 4909D3FC48; Thu, 7 Jul 2011 16:37:26 +0400 (MSD) From: Kirill Batuzov To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2011 16:37:15 +0400 Message-Id: <8d57658941ed272a9a2dc920965897d15809d233.1309865252.git.batuzovk@ispras.ru> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 83.149.198.202 Cc: zhur@ispras.ru Subject: [Qemu-devel] [PATCH v3 4/6] Do constant folding for boolean operations. 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 Perform constant folding for AND, OR, XOR operations. Signed-off-by: Kirill Batuzov --- tcg/optimize.c | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 42a1bda..c469952 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -99,12 +99,18 @@ static int op_bits(int op) case INDEX_op_add_i32: case INDEX_op_sub_i32: case INDEX_op_mul_i32: + case INDEX_op_and_i32: + case INDEX_op_or_i32: + case INDEX_op_xor_i32: return 32; #if TCG_TARGET_REG_BITS == 64 case INDEX_op_mov_i64: case INDEX_op_add_i64: case INDEX_op_sub_i64: case INDEX_op_mul_i64: + case INDEX_op_and_i64: + case INDEX_op_or_i64: + case INDEX_op_xor_i64: return 64; #endif default: @@ -190,6 +196,15 @@ static TCGArg do_constant_folding_2(int op, TCGArg x, TCGArg y) CASE_OP_32_64(mul): return x * y; + CASE_OP_32_64(and): + return x & y; + + CASE_OP_32_64(or): + return x | y; + + CASE_OP_32_64(xor): + return x ^ y; + default: fprintf(stderr, "Unrecognized operation %d in do_constant_folding.\n", op); @@ -246,6 +261,9 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, switch (op) { CASE_OP_32_64(add): CASE_OP_32_64(mul): + CASE_OP_32_64(and): + CASE_OP_32_64(or): + CASE_OP_32_64(xor): if (temps[args[1]].state == TCG_TEMP_CONST) { tmp = args[1]; args[1] = args[2]; @@ -291,6 +309,22 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, continue; } break; + CASE_OP_32_64(or): + CASE_OP_32_64(and): + if (args[1] == args[2]) { + if (args[1] == args[0]) { + args += 3; + 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); + gen_args += 2; + args += 3; + } + continue; + } + break; } /* Propagate constants through copy operations and do constant @@ -326,6 +360,9 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, CASE_OP_32_64(add): CASE_OP_32_64(sub): CASE_OP_32_64(mul): + CASE_OP_32_64(or): + CASE_OP_32_64(and): + CASE_OP_32_64(xor): if (temps[args[1]].state == TCG_TEMP_CONST && temps[args[2]].state == TCG_TEMP_CONST) { gen_opc_buf[op_index] = op_to_movi(op);