From patchwork Mon Aug 30 06:24:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 504327 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp1527348jai; Mon, 30 Aug 2021 00:00:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/fo9T5dVo0PV+KFyWDDptFHle3ghPVDnso0d9HcMKgh4l1KD7kLaOjbjkhNx0W92yTjJ0 X-Received: by 2002:a25:5ec5:: with SMTP id s188mr21135595ybb.465.1630306822992; Mon, 30 Aug 2021 00:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630306822; cv=none; d=google.com; s=arc-20160816; b=tC30eRZJDyf/8wDchNP0ZmINVAqYhx3DiMF6w+kTayMm7Xu4vmT8DRYaAGfhl9YUbH XuGKvZDE9oPpnHpeqjsD1u7d3qjC0o7SirFxdkGQl5fD6i1FteCQFQY1pJzao0u9Ve9A EpkfTi6noZKEdrwpCRiq8gpypjl79PMLIJScHbFwjmP2UIv4Kg4/F8rFurCoaAc/DV6s lOWWGysYAIwH+VhSt0uGh9TenJUpkOCVvmvzH2yJCJhPbs3mFa2Jal5Ke333iQLPqGJt RwZ7itAQWRKr4+Mp0vtMXcGWDpUWNL5yJZbQZjARQ0XXr35wDg2+JSnQf0fE11GCYiz6 w3eQ== 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=RiX0h+LZeFsC/CB7zg0i2+qNE9Z0TV/acHiKkwOyOgI=; b=aGqy/g+1EN5rcbUN5RAFpB0r9KoIwuIOOBbUB3nJmbUBvTPBmrqaloOjKC4LN70MB6 1gVRwm//2CRv1D7bTQ7N2K+9C6o5sdasNHul6rKydV+lltFFLP83dcbqkDrzxPmYmnuf og04r7vioxGiCCrPV/Wmk72aQdcXlthyGCaw+6OTi2JLBkk4WLEI44NbDWuabG9E3adu kPRM4D7JC7+UKMCAEv9MZSKJHZAlXEg3Cb70F2l+D0QiZS9O5WBenNAXrkbAvQpv9DQX GcX0ESwnmjX7rraWcxcSu0bdspUjc/9yrc6Z00notiHOHBORoFzIwE1JSCyS1gRnpiGz zQKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mdJs2dKL; 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 i17si13080040ybm.135.2021.08.30.00.00.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Aug 2021 00:00:22 -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=mdJs2dKL; 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]:39216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKbHK-0008JL-EF for patch@linaro.org; Mon, 30 Aug 2021 03:00:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKajP-0004Rz-CC for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:19 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:52752) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mKajN-0007i3-TC for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:19 -0400 Received: by mail-pj1-x1033.google.com with SMTP id d5so2966108pjx.2 for ; Sun, 29 Aug 2021 23:25:17 -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=RiX0h+LZeFsC/CB7zg0i2+qNE9Z0TV/acHiKkwOyOgI=; b=mdJs2dKLGgL2rINaF/vCJUuXn6NWKgVM1AvHIxOUCiPs0setjBvidm0Mr2lStQD1XV VA6AXHS7K5NNTv9lfHGD+en/cYarx9cPojH7HqmThpJui215rpYUc1fsAkkTDSwzYSqU 5qvR0Jhz1QvGGlcTo5cAva+01FUOlWPAQJBD4rImMRDzydcXV+1Bobemh0MEBO+AP6sS kq3RhHAsKJjb6EjvdGTbshYcsF9vj9HlgrSECHkNsqeSaerrvD49w0cpFBDZ4xdNPDzt 23icTQ8FD0pxSTOBVs4q01M9+aQo1O5m2vpJcvz1HG6ublKFTOu4sOGZfxoLlS44pCaV jJcQ== 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=RiX0h+LZeFsC/CB7zg0i2+qNE9Z0TV/acHiKkwOyOgI=; b=gtipbnxPmxNkb1yHpAp5zs9MrygapXO9qBf1mZe/fajNhTFuoeu2zhKc0p488ItkqY E4dGLwgiaxzf4xwDzIUV2PxeP897C0SA09zd8DLOve+ygdqRL2sF20o/04MxtnEw0qAS Agbzo+mOCEzJkx5g5Ctr2x5lmfdef8HAK4pV/UcaJ/EJPgN2X7D6rpumiZYN0Dl9c3aT 8ElQfcSIx1oqSNOtIS/P8LVhe9FX//S5J5B4EsZaJaoXvNVDab1XkIbyviY1/Tz/H045 72QC73BEfgB8iO1GQ839r0ImcPD6/DOwPEb1WfTn29hm6KmFvfyFSv4TwAy//khLFcpV uc0Q== X-Gm-Message-State: AOAM531Jr13h1Af0vi/y55GMQKbj5oIEt0MLXzE0wWlHoCIz/hlhI5PP seoE8KHXmRUQmBRVoPg++p1bUcQtHWj3IQ== X-Received: by 2002:a17:90a:7f85:: with SMTP id m5mr36007998pjl.185.1630304715504; Sun, 29 Aug 2021 23:25:15 -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.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Aug 2021 23:25:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 35/48] tcg/optimize: Split out fold_sub_to_neg Date: Sun, 29 Aug 2021 23:24:38 -0700 Message-Id: <20210830062451.639572-36-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::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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" Even though there is only one user, place this more complex conversion into its own helper. Signed-off-by: Richard Henderson --- tcg/optimize.c | 84 ++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 37 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index aba65fdbd3..23594e1a03 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -1183,7 +1183,15 @@ static bool fold_nand(OptContext *ctx, TCGOp *op) static bool fold_neg(OptContext *ctx, TCGOp *op) { - return fold_const1(ctx, op); + if (fold_const1(ctx, op)) { + return true; + } + /* + * Because of fold_sub_to_neg, we want to always return true, + * via finish_folding. + */ + finish_folding(ctx, op); + return true; } static bool fold_nor(OptContext *ctx, TCGOp *op) @@ -1335,10 +1343,47 @@ static bool fold_shift(OptContext *ctx, TCGOp *op) return fold_const2(ctx, op); } +static bool fold_sub_to_neg(OptContext *ctx, TCGOp *op) +{ + TCGOpcode neg_op; + bool have_neg; + + if (!arg_is_const(op->args[1]) || arg_info(op->args[1])->val != 0) { + return false; + } + + switch (ctx->type) { + case TCG_TYPE_I32: + neg_op = INDEX_op_neg_i32; + have_neg = TCG_TARGET_HAS_neg_i32; + break; + case TCG_TYPE_I64: + neg_op = INDEX_op_neg_i64; + have_neg = TCG_TARGET_HAS_neg_i64; + break; + case TCG_TYPE_V64: + case TCG_TYPE_V128: + case TCG_TYPE_V256: + neg_op = INDEX_op_neg_vec; + have_neg = (TCG_TARGET_HAS_neg_vec && + tcg_can_emit_vec_op(neg_op, ctx->type, TCGOP_VECE(op)) > 0); + break; + default: + g_assert_not_reached(); + } + if (have_neg) { + op->opc = neg_op; + op->args[1] = op->args[2]; + return fold_neg(ctx, op); + } + return false; +} + static bool fold_sub(OptContext *ctx, TCGOp *op) { if (fold_const2(ctx, op) || - fold_xx_to_i(ctx, op, 0)) { + fold_xx_to_i(ctx, op, 0) || + fold_sub_to_neg(ctx, op)) { return true; } return false; @@ -1472,41 +1517,6 @@ void tcg_optimize(TCGContext *s) continue; } break; - CASE_OP_32_64_VEC(sub): - { - TCGOpcode neg_op; - bool have_neg; - - if (arg_is_const(op->args[2])) { - /* Proceed with possible constant folding. */ - break; - } - switch (ctx.type) { - case TCG_TYPE_I32: - neg_op = INDEX_op_neg_i32; - have_neg = TCG_TARGET_HAS_neg_i32; - break; - case TCG_TYPE_I64: - neg_op = INDEX_op_neg_i64; - have_neg = TCG_TARGET_HAS_neg_i64; - break; - default: - neg_op = INDEX_op_neg_vec; - have_neg = tcg_can_emit_vec_op(neg_op, ctx.type, TCGOP_VECE(op)) > 0; - break; - } - if (!have_neg) { - break; - } - if (arg_is_const(op->args[1]) - && arg_info(op->args[1])->val == 0) { - op->opc = neg_op; - reset_temp(op->args[0]); - op->args[1] = op->args[2]; - continue; - } - } - break; default: break; }