From patchwork Mon Aug 30 06:24:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 504303 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp1516533jai; Sun, 29 Aug 2021 23:38:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgawFKdicADlKyiS4BPNsTNBFeiPiETJ493udEs9Fb2fSYikFGcRDrA4wgdN5ENyun3tdb X-Received: by 2002:a25:1257:: with SMTP id 84mr20560260ybs.363.1630305527452; Sun, 29 Aug 2021 23:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630305527; cv=none; d=google.com; s=arc-20160816; b=w2rISqacPCIZijUF+xhqUst7uNPaBEbGmqqRLrh+C/QjzX7XlhS7jW+zsdRynstW+q K45P97DDXFEr1s1nFIVV4Fwg+9uFP43OFE6C49GU07g9paemeBCxz49rC9Nmrsr2FvqQ XPf48gyDk4lNHxX73uvrxUQW2JeMHm/rFXI3/jl07WzC0MqaV782LI2vKf6Hr9EXRuqr vUrWKOC4URyyxOmd78N52RYJ7h9hO6IIwx19TVrA/9UHnNB07whhCaYzkp5w2p1P3qoE oW+E3FG0YMHfJTxl+nsTFgZzr9uQuELy/Bnn5yNM+NNx7qMyKXBs2fHG4eec2SmPXkOw h9Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=NHt8cYm8EKeBALKp+ZROcv2m1GndeyHCLq0Etmcw7us=; b=tLlG/jSi3PcY9F9s/UoI1cB/X8K5KejQpJz6RPwhulnFPN2agyfo29ktOTzsHp2AwA o1FPdacwrjo2uzkHINopjUppqoJRKPg6sNVmNrC8yW9myK2f/3MRa0hIaQe3pLK5QuM5 U74iMXK2oc5efXpmqXM2W/K37WAqn5AstscwXkCdWOTTMB84c+b+tO/bRNqqmpL/9v2G nSAqpw+KQK66VdB3VdZ2rBioeW3S+wi2j20ANLKEPCzYwmhVbegGbdn3QiyEeEwbYSYk Xt3e7zD7vNSOuQKDaAUy9BnvnFOfg+TShrtJPLdSxlp20CG2BBSY7yRPgKP4uTn1yyiW DDxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HGAWA00B; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s23si16395342ybc.123.2021.08.29.23.38.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Aug 2021 23:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HGAWA00B; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKawP-0002BX-Mx for patch@linaro.org; Mon, 30 Aug 2021 02:38:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKajD-0003w7-9L for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:07 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:42992) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mKajA-0007VM-P1 for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:07 -0400 Received: by mail-pl1-x62e.google.com with SMTP id n4so834422plh.9 for ; Sun, 29 Aug 2021 23:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=NHt8cYm8EKeBALKp+ZROcv2m1GndeyHCLq0Etmcw7us=; b=HGAWA00B3c8DjyChhA6Ay8B003NBQh/iYWP3KrqV3CjmGdRWwfaAlaSmIJ/V/LIMQL j2I539VB3tzOymejCLJR4Qn3gqBl4LL6WkvJPth5VnbgFbSpoOZg97uAMrfWdpelHpck /Ves87G3Q9aU5SHt6rPT9brvIoVacg+xAkz7JE1wrsKG4YirAzf1H0RtFBlITJUI91wx DiX643EJNnFFBuXVmyfryJ/ysQhkVpm5yPo/q9JPUY252v8jSudJDKgp+fDI4yMbiyBN htt/oSJpeMInzZeMUPURCY3zUDxqUtt6OJrx6giNFlz5/2aRSl6PuYDQ2HS1XQVsyFuS T9VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NHt8cYm8EKeBALKp+ZROcv2m1GndeyHCLq0Etmcw7us=; b=dUIP+jJitvb+9allSq/m3HiM1Wz6EqPPPBmKKELm9Yvzn9pGuVsEhb53WhAlYYJ0Ra gamYBE9cF43eJ/2BONxGNOIbsLg9XY8XIPi/8FrmZtv2jmkTdzngSFxS1UGGh1Y/LWsF dE64h6jXXcw7vWtH46GkBo/HxkboOOPDnuNwPzkL9GfSqDKwZiebcWMxpLLcvL9Q71TV s2mxzCVV1THwJ+f1LzMeufDCZJ/jt43OmlrA9kR6kNJmDPcnvN5GEj+m2ej2hQ9swN/0 kim3WYuSp7P0gjEXwFMvQzxNFMZi7NteNYb9ec3vmbrjbfiTzSktZq8P5EK92tl6TK9N dvFg== X-Gm-Message-State: AOAM531WhXTy5iDTBHyWJSwzSnfj2p3SBZ3GXCPDM9fPkQWOI/HsMqY7 Lei4mxPeJobnXvfFhcR1WLn2bAOPigsXnQ== X-Received: by 2002:a17:90a:44:: with SMTP id 4mr24609140pjb.130.1630304703415; Sun, 29 Aug 2021 23:25:03 -0700 (PDT) Received: from localhost.localdomain (174-21-72-39.tukw.qwest.net. [174.21.72.39]) by smtp.gmail.com with ESMTPSA id b12sm13942084pff.63.2021.08.29.23.25.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Aug 2021 23:25:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 16/48] tcg/optimize: Split out fold_setcond2 Date: Sun, 29 Aug 2021 23:24:19 -0700 Message-Id: <20210830062451.639572-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210830062451.639572-1-richard.henderson@linaro.org> References: <20210830062451.639572-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reduce some code duplication by folding the NE and EQ cases. Signed-off-by: Richard Henderson --- tcg/optimize.c | 145 ++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 73 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index 05de083d50..7de76b6de9 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -839,6 +839,75 @@ static bool fold_qemu_st(OptContext *ctx, TCGOp *op) return false; } +static bool fold_setcond2(OptContext *ctx, TCGOp *op) +{ + TCGCond cond = op->args[5]; + int i = do_constant_folding_cond2(&op->args[1], &op->args[3], cond); + int inv = 0; + + if (i >= 0) { + goto do_setcond_const; + } + + switch (cond) { + case TCG_COND_LT: + case TCG_COND_GE: + /* + * Simplify LT/GE comparisons vs zero to a single compare + * vs the high word of the input. + */ + if (arg_is_const(op->args[3]) && arg_info(op->args[3])->val == 0 && + arg_is_const(op->args[4]) && arg_info(op->args[4])->val == 0) { + goto do_setcond_high; + } + break; + + case TCG_COND_NE: + inv = 1; + QEMU_FALLTHROUGH; + case TCG_COND_EQ: + /* + * Simplify EQ/NE comparisons where one of the pairs + * can be simplified. + */ + i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[1], + op->args[3], cond); + switch (i ^ inv) { + case 0: + goto do_setcond_const; + case 1: + goto do_setcond_high; + } + + i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[2], + op->args[4], cond); + switch (i ^ inv) { + case 0: + goto do_setcond_const; + case 1: + op->args[2] = op->args[3]; + op->args[3] = cond; + op->opc = INDEX_op_setcond_i32; + break; + } + break; + + default: + break; + + do_setcond_high: + op->args[1] = op->args[2]; + op->args[2] = op->args[4]; + op->args[3] = cond; + op->opc = INDEX_op_setcond_i32; + break; + } + return false; + + do_setcond_const: + return tcg_opt_gen_movi(ctx, op, op->args[0], i); +} + static bool fold_shift(OptContext *ctx, TCGOp *op) { return fold_const2(ctx, op); @@ -1638,79 +1707,6 @@ void tcg_optimize(TCGContext *s) } break; - case INDEX_op_setcond2_i32: - i = do_constant_folding_cond2(&op->args[1], &op->args[3], - op->args[5]); - if (i >= 0) { - do_setcond_const: - tcg_opt_gen_movi(&ctx, op, op->args[0], i); - continue; - } - if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE) - && arg_is_const(op->args[3]) - && arg_info(op->args[3])->val == 0 - && arg_is_const(op->args[4]) - && arg_info(op->args[4])->val == 0) { - /* Simplify LT/GE comparisons vs zero to a single compare - vs the high word of the input. */ - do_setcond_high: - reset_temp(op->args[0]); - arg_info(op->args[0])->z_mask = 1; - op->opc = INDEX_op_setcond_i32; - op->args[1] = op->args[2]; - op->args[2] = op->args[4]; - op->args[3] = op->args[5]; - break; - } - if (op->args[5] == TCG_COND_EQ) { - /* Simplify EQ comparisons where one of the pairs - can be simplified. */ - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[1], op->args[3], - TCG_COND_EQ); - if (i == 0) { - goto do_setcond_const; - } else if (i > 0) { - goto do_setcond_high; - } - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[2], op->args[4], - TCG_COND_EQ); - if (i == 0) { - goto do_setcond_high; - } else if (i < 0) { - break; - } - do_setcond_low: - reset_temp(op->args[0]); - arg_info(op->args[0])->z_mask = 1; - op->opc = INDEX_op_setcond_i32; - op->args[2] = op->args[3]; - op->args[3] = op->args[5]; - break; - } - if (op->args[5] == TCG_COND_NE) { - /* Simplify NE comparisons where one of the pairs - can be simplified. */ - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[1], op->args[3], - TCG_COND_NE); - if (i == 0) { - goto do_setcond_high; - } else if (i > 0) { - goto do_setcond_const; - } - i = do_constant_folding_cond(INDEX_op_setcond_i32, - op->args[2], op->args[4], - TCG_COND_NE); - if (i == 0) { - goto do_setcond_low; - } else if (i > 0) { - goto do_setcond_const; - } - } - break; - default: break; @@ -1796,6 +1792,9 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(shr): done = fold_shift(&ctx, op); break; + case INDEX_op_setcond2_i32: + done = fold_setcond2(&ctx, op); + break; CASE_OP_32_64_VEC(sub): done = fold_sub(&ctx, op); break;