From patchwork Mon Jun 21 23:18:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 464617 Delivered-To: patch@linaro.org Received: by 2002:a17:906:71d0:0:0:0:0 with SMTP id i16csp4669300ejk; Mon, 21 Jun 2021 16:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytrru33S80/XikVUw+l8UoSD4fcOjx6mIW6Q9fE1nAUiEmqPpmAY+1eteFBL4B1Pg7EPEQ X-Received: by 2002:a1f:194a:: with SMTP id 71mr17191964vkz.18.1624317717077; Mon, 21 Jun 2021 16:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624317717; cv=none; d=google.com; s=arc-20160816; b=lQbObdNKQr1zwbQ4C020IGOvT8GRO2Y9NdyGNQ0KqwzDvTnz6Q5/R0oxuGwniM9f0/ V2+IMLYf+PcGuGtzK27n96As7R5xgqErxcCI9Tc8onvWDfYuJevQOpoKxSV60sQamB4s FWwmvqaPHdFudhHkDNWV66lC58BkHGL7A3Nn/NV3vkF4wYSv+i4lpmMIkUuT6LZnqeGV T+vR7DKxp6E8ncXLpnftN/9RsKps4PzHFOPX262uitKxNLkdIyx+vldso56chx4gzGHS pc4aQR6VYgmGcGRF0znGTDLbSWwaEq/JWNKsT02xOIsKppstCPfypvy25/VA1fVGvnQX 06wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=DgN2RVC9T7a74NE01POCZUsNKgpvvfqPoLVvw7rnjlE=; b=vNxtVeUVHMcekOlGJ9+I9pTUL6P2LAcyAxZLrxjb2P4DN/treajQp8C3EG3gx2Bdf3 XPP+SLwJ2KtB9T3c4qyN0rhkOfgl1nCH7I9klArzkYI0714rY8RQ6NVx0KmtcCC+R2Sz +EVcPXLxrqhQpCHG5oXnE1OFncwoLnQd4D+RrECAcuofPOXLcxt978JNtLX8qAav9+du TyrdBGtmmP2d95NM48V5LMhqSNgn6cbCTu7oXRY+gcJozfiRFHTU+/juVw4XiZkblu05 dtDali3gjrpBjWao/Gr531ONSFtZRt2PMbmadNss5dRcecv9Rij2lCRjpOLRAeh4LTWB J5KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ye2+IaCh; 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 v7si14485693vsr.224.2021.06.21.16.21.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jun 2021 16:21:57 -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=Ye2+IaCh; 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]:36026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lvTEq-0006kr-EU for patch@linaro.org; Mon, 21 Jun 2021 19:21:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvTC6-0000wd-M5 for qemu-devel@nongnu.org; Mon, 21 Jun 2021 19:19:06 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:50718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lvTC3-0005zW-5i for qemu-devel@nongnu.org; Mon, 21 Jun 2021 19:19:06 -0400 Received: by mail-pj1-x1035.google.com with SMTP id g4so10910949pjk.0 for ; Mon, 21 Jun 2021 16:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DgN2RVC9T7a74NE01POCZUsNKgpvvfqPoLVvw7rnjlE=; b=Ye2+IaCh4rLM6YJmP+3C8eR/l30VtUAvi5Jw8Fh87J8vPNgpSZkUNMIO4GnuqraX5x ITcGm5AQWRA9cPz6hx7j26yIbkCYqahOd795z5u7MclWcqMVFuFzzEry8UE0HNPOwcy0 ectSrKDAsdP3GrMKPINiZeTYFe6hXj8FvWeoUwBr3/Oggq5Y1TyLsBK+mHeYdRoraUg0 2LqAHL/qMtvgnWswlo7Zg8c3INZKs24jg4xSQyxcyZSHk5JnJRZjk2zDlsaFZfrGUwOF uYHQf7MFlZxY75/9C+yJStn1C3+oQKqV+29z5BcnnNEEd0emBEOifNEHvIv3d0V8WoDE EndA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DgN2RVC9T7a74NE01POCZUsNKgpvvfqPoLVvw7rnjlE=; b=ASvtjwPUDSx7oYlRuoJb0Da2bG96pAyPWarL/yLVliWHeKfFa+1kX/rZPde9GfjJ5M v2VfKtR8i0/rppX4GY+VvAr7SRqQOjGpUkNgHZpYM7UWrHKh7rJEhxPr8Umg2+Wuqua0 PUa8QSKOyDIEmWBudSp3LslBB/5I/pcuBNrykM7ZiejXMAD8suGcCpYHJIoc8hRP4R2t vjGS2BIa0tOX0JtYhKCAhh/frLOetsgar7iR4YJfXzkCrHhiG0Su0FVt/x0xrLjoOeEF KH/MXPBXNIfBQodpongjMngf6gWYwVFSodke52Y5/reZM3p7kIYMhglxSbzRHHGht6SP ERFw== X-Gm-Message-State: AOAM532sydZbjt8uOieA0+/jjqEymk1qCHrb+QSJsHMvNuIJPqIPQ9cX xmQI7poPYp9VrSi4DoOm+WmJ3zUcMaB17A== X-Received: by 2002:a17:90b:33c4:: with SMTP id lk4mr642983pjb.191.1624317541901; Mon, 21 Jun 2021 16:19:01 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id 135sm14429952pgf.20.2021.06.21.16.19.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 16:19:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/29] tcg: Handle new bswap flags during optimize Date: Mon, 21 Jun 2021 16:18:37 -0700 Message-Id: <20210621231849.1871164-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210621231849.1871164-1-richard.henderson@linaro.org> References: <20210621231849.1871164-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Notice when the input is known to be zero-extended and force the TCG_BSWAP_IZ flag on. Honor the TCG_BSWAP_OS bit during constant folding. Propagate the input to the output mask. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/optimize.c | 56 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index 37c902283e..3b6983fbef 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -354,10 +354,12 @@ static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) return (uint16_t)x; CASE_OP_32_64(bswap16): - return bswap16(x); + x = bswap16(x); + return y & TCG_BSWAP_OS ? (int16_t)x : x; CASE_OP_32_64(bswap32): - return bswap32(x); + x = bswap32(x); + return y & TCG_BSWAP_OS ? (int32_t)x : x; case INDEX_op_bswap64_i64: return bswap64(x); @@ -1028,6 +1030,42 @@ void tcg_optimize(TCGContext *s) } break; + CASE_OP_32_64(bswap16): + mask = arg_info(op->args[1])->mask; + if (mask <= 0xffff) { + op->args[2] |= TCG_BSWAP_IZ; + } + mask = bswap16(mask); + switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { + case TCG_BSWAP_OZ: + break; + case TCG_BSWAP_OS: + mask = (int16_t)mask; + break; + default: /* undefined high bits */ + mask |= MAKE_64BIT_MASK(16, 48); + break; + } + break; + + case INDEX_op_bswap32_i64: + mask = arg_info(op->args[1])->mask; + if (mask <= 0xffffffffu) { + op->args[2] |= TCG_BSWAP_IZ; + } + mask = bswap32(mask); + switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { + case TCG_BSWAP_OZ: + break; + case TCG_BSWAP_OS: + mask = (int32_t)mask; + break; + default: /* undefined high bits */ + mask |= MAKE_64BIT_MASK(32, 32); + break; + } + break; + default: break; } @@ -1134,9 +1172,6 @@ void tcg_optimize(TCGContext *s) CASE_OP_32_64(ext16s): CASE_OP_32_64(ext16u): CASE_OP_32_64(ctpop): - CASE_OP_32_64(bswap16): - CASE_OP_32_64(bswap32): - case INDEX_op_bswap64_i64: case INDEX_op_ext32s_i64: case INDEX_op_ext32u_i64: case INDEX_op_ext_i32_i64: @@ -1150,6 +1185,17 @@ void tcg_optimize(TCGContext *s) } goto do_default; + CASE_OP_32_64(bswap16): + CASE_OP_32_64(bswap32): + case INDEX_op_bswap64_i64: + if (arg_is_const(op->args[1])) { + tmp = do_constant_folding(opc, arg_info(op->args[1])->val, + op->args[2]); + tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); + break; + } + goto do_default; + CASE_OP_32_64(add): CASE_OP_32_64(sub): CASE_OP_32_64(mul):