From patchwork Thu Mar 21 16:13:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 229754 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 48A9C2C0092 for ; Fri, 22 Mar 2013 03:14:41 +1100 (EST) Received: from localhost ([::1]:46688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIi8V-0001L8-8r for incoming@patchwork.ozlabs.org; Thu, 21 Mar 2013 12:14:39 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIi85-0001FN-1c for qemu-devel@nongnu.org; Thu, 21 Mar 2013 12:14:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIi81-0000LG-OP for qemu-devel@nongnu.org; Thu, 21 Mar 2013 12:14:12 -0400 Received: from mail-ve0-f173.google.com ([209.85.128.173]:49310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIi81-0000Kp-L6 for qemu-devel@nongnu.org; Thu, 21 Mar 2013 12:14:09 -0400 Received: by mail-ve0-f173.google.com with SMTP id oz10so2572428veb.4 for ; Thu, 21 Mar 2013 09:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer; bh=dAKPmFtOyGQoxBLbgVTZk0gemOVagH4PWkAaGAFqoL8=; b=LRkqvlq3DnpvuIl2NDncPmb23WqY1G4xmS1kjWJ3UyXJzxGMbQMonvhff0St0J+nwH PEuqmu2EWGc470FziAPgKUMgWIEkCwiRf5f/WdBxPVOg45YenkN4YVVz6hPZgowA8RBD 1d7k6/K807Ed7pIX4NO1MI1DlTvF6pUxfpUxYe98tZd/KJVTtBjNLdeHZchnLYYEeQCw DVxKyr70Ff8ETgnikYaZpTmx5McUvj2WkqyE7A845BeKkjIqH5lUJSa5z7Z/O+CEgdgS CZzKY8NBVS58kNwCyQ4Y2ex0ymzTqt+WZTS+hxbbb2cfgnCstjmHsBmRipqr654U3m1V hvLA== X-Received: by 10.220.156.68 with SMTP id v4mr14143260vcw.10.1363882448639; Thu, 21 Mar 2013 09:14:08 -0700 (PDT) Received: from anchor.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id h11sm41924588vdj.12.2013.03.21.09.14.06 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 21 Mar 2013 09:14:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 21 Mar 2013 09:13:33 -0700 Message-Id: <1363882413-15534-1-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.173 Cc: Blue Swirl Subject: [Qemu-devel] [PATCH v2] tcg-optimize: Fold sub r,0,x to neg r,x 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 Cc: Blue Swirl Signed-off-by: Richard Henderson --- V2 properly does a reset_temp on the output of the neg. This was the cause of the sparc32 boot problem. r~ --- tcg/optimize.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index bc6e5c1..1b6644c 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -576,7 +576,8 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, break; } - /* Simplify expressions for "shift/rot r, 0, a => movi r, 0" */ + /* Simplify expressions for "shift/rot r, 0, a => movi r, 0", + and "sub r, 0, a => neg r, a" case. */ switch (op) { CASE_OP_32_64(shl): CASE_OP_32_64(shr): @@ -592,6 +593,37 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, continue; } break; + CASE_OP_32_64(sub): + { + TCGOpcode neg_op; + bool have_neg; + + if (temps[args[2]].state == TCG_TEMP_CONST) { + /* Proceed with possible constant folding. */ + break; + } + if (op == INDEX_op_sub_i32) { + neg_op = INDEX_op_neg_i32; + have_neg = TCG_TARGET_HAS_neg_i32; + } else { + neg_op = INDEX_op_neg_i64; + have_neg = TCG_TARGET_HAS_neg_i64; + } + if (!have_neg) { + break; + } + if (temps[args[1]].state == TCG_TEMP_CONST + && temps[args[1]].val == 0) { + s->gen_opc_buf[op_index] = neg_op; + reset_temp(args[0]); + gen_args[0] = args[0]; + gen_args[1] = args[2]; + args += 3; + gen_args += 2; + continue; + } + } + break; default: break; }