From patchwork Tue Jun 29 18:54:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 468338 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5254578jao; Tue, 29 Jun 2021 12:32:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI+3NUuWSwcdmeM/c5XHYrYcf8NtCiDhhaBr9MIfCRVeLQ7VtSl63yxzbChO0C0xH1aSwq X-Received: by 2002:a25:e68e:: with SMTP id d136mr13251995ybh.120.1624995125375; Tue, 29 Jun 2021 12:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624995125; cv=none; d=google.com; s=arc-20160816; b=kR7qOQhk91979TbRkqlvcffQkZ5804M/eY6d5TJuwF0EpFLK26Jxnh+UqPG5Wpn+I6 hwDuIh9LJxy0b6Q41DAJTiX6Pl5Tzgah5MVCU+WK6O40EYYHXz4dfBSQdZOggRCdhlTn So4dtR5tVhuGxPMCb+WgoJKNCKfQzb5GK1WPvG3yQaESCzS5xTgkNhq8ryJjqP668YEb 0NB+Y5SQOJFaRSdfxw1kVLe7sTEPv7FTSpWulZArcGlHMHML7QtD8XTts9DWSaNR+Ij3 V/ZklLn/phFQFB71rbqubhAkv7fLd+1un/gg9geOhakXu/DtT/tdY31xpZrUpK7Is0WS Vy6A== 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=r6z5etdTT2JEFWUbs+95xLr9toUzAo+pdbx3zMIT52I=; b=rRqalffM7xgwOkZrcZ16ZZfsMX5+Yr9fkDSRht+rPnB6bIOwjTPwDarNALisFWWSnR eRsmZS5b9251Tp+db6QEHWtgL9J6go+sEWSGSBgd5Ou4jTczvRllxo/fRKRoVK1D+2n4 eci4GlShnjIH+hZXtJEtenCX6pdZkDCrZ9zOrPTCsEgWiIzFQVlapSk47dSZKAwclCfM Dkm98kuCCpFisZp2uvaIIA09S2O8wztLj4Za7pkm5Q9DbYc4ViQg3u6txFiPn4MMH6Ad m/lSoNepweOID1mjxom1TZFKVPjrl7w0qK87Q+/o0bOK/5GxdjxsA2f91UunREInc2Od 77Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q56kToAO; 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 v125si178817ybv.86.2021.06.29.12.32.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jun 2021 12:32:05 -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=q56kToAO; 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]:55812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyJSm-0004nI-P9 for patch@linaro.org; Tue, 29 Jun 2021 15:32:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyIwY-00045t-Ea for qemu-devel@nongnu.org; Tue, 29 Jun 2021 14:58:47 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:46769) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyIwM-00030K-NB for qemu-devel@nongnu.org; Tue, 29 Jun 2021 14:58:46 -0400 Received: by mail-pl1-x632.google.com with SMTP id c15so21770pls.13 for ; Tue, 29 Jun 2021 11:58:31 -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=r6z5etdTT2JEFWUbs+95xLr9toUzAo+pdbx3zMIT52I=; b=q56kToAOfVmr8IjoXyg3FeJOoSAuSDPX/psFzzrlpLc9Lowj60QOSLSNSxdvWOhNFy dyZNC3e1cRbFGZrWAypFQhaEqAO4dFGpaNCJLhRurSCVKFfHv6ltQw87PPoneBE46fmV YOK5qD2yZIsOAIXpeHmmgmvyU7z6gUQYTd7cNhXkPuFpTuXMtmspyLkh9k9aK9uWFnfV skfWhkV8nPS1mhNxYUpRQHu6rOVqidOhULsmo0D6j6CR/ET4Pq34z877PUmktuKo25LR QIJFAalI08wQZVlt+DKwnD0Sw7t8mdrMNkGh329io3trF5/YbT0ps4XmfQDWvSiqOv0H 5BPg== 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=r6z5etdTT2JEFWUbs+95xLr9toUzAo+pdbx3zMIT52I=; b=gKPusYAfNdlN1sxO/t255FmDHwF5pO5pYbvW52V2ofabrRpyWevyLwcgHo1EFpvYuH 8EGusw3nbLhxo+FFhmWg6Po4B6a1scVDVTmX62O6CVJkx9pyiBh/YIkhQ01IBKVF+kN6 AY6OyWWvF7pQM4nD1Y6K9Pvu/FXXbUstaqCmSLK9w5JIoBf2fgdNzsoiyU85Hpu0I9yc 98284LatXB3+P+NP4qSORnhJK/ajemuAQYvFEU7v8BEb6DgX7WJsgHX7SAbycxc4aM5O HNqkcocPsUr7V9Hy5EGQZIGL9Z6/6wUsReZ/mI4nEjm15g3bLL3uo/El7Z0Tkzcaw+dn hqkQ== X-Gm-Message-State: AOAM531lDFRZlJnPeA1+d58gpNz7zeY5qI0kcEXCVXBrD0a9Ilw7J4CH J57A/X9gY1KbGZD0iGL6y+9TpOrrRkq1Kw== X-Received: by 2002:a17:902:f1d3:b029:128:b8db:24dc with SMTP id e19-20020a170902f1d3b0290128b8db24dcmr17543235plc.47.1624993111114; Tue, 29 Jun 2021 11:58:31 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id 21sm18002849pfh.103.2021.06.29.11.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 11:58:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 51/63] tcg: Handle new bswap flags during optimize Date: Tue, 29 Jun 2021 11:54:43 -0700 Message-Id: <20210629185455.3131172-52-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210629185455.3131172-1-richard.henderson@linaro.org> References: <20210629185455.3131172-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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 211a4209a0..9876ac52a8 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -355,10 +355,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); @@ -1029,6 +1031,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; } @@ -1135,9 +1173,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: @@ -1151,6 +1186,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):