From patchwork Mon Jun 14 08:37:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 459771 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3084327jae; Mon, 14 Jun 2021 01:43:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy64R2b0NkycUz7tRO4ZY+mV+RgriChgNwYpnhHPxvTc5hYlQMpmctJ0OhpprbimbcJz+V4 X-Received: by 2002:a25:d257:: with SMTP id j84mr23613777ybg.404.1623660239095; Mon, 14 Jun 2021 01:43:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623660239; cv=none; d=google.com; s=arc-20160816; b=Zk0Xq3YYN1OKkstwo9nuymr3epGO12lpkrIa+pvTbfxVlmXN20WM5+dt/bGc7iEqEq IezUR+AQXo62204eKPK9igejjv8pPof9yJ894/0Ycq+34jvhi9ZdBoTD9IE1dqGs4ao6 CzV/fkziSE4SSQsWpuzZEoxq4FktjTSjN16R0JHY6g95AYD+tlK7lDRCwMWEXV0olR6S Buf/vhOWsslXSRx730U93CV8t59KVFEE2F7Wa5KsaTbJVAjGP991ZnmRk8GZD+wHRK/k AT7TYI/we2yXXPSIUUD+J/QmF2L4G27RPrFgvZQxeLUfYmQSHGtWJMzBSlv3aKdMCMHr Si4A== 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=UZkn/bCz3YGcO9TqhXoosXO7opN8+jen9eeeiO+Mw8Y=; b=AK9ZZRd/0xdlh6xVb+bns9Z2I9s7qdMwLKTTvy06YowsDsUebN9KQ79eeqb+mORN3i 9deoTWGufA6Rjp+K/jfY3WldVKhAlhuWgf2M88ocKd3lHrBql/3C7xDxqatePfCzzWB9 wXBMf2QoaLIUceBHugtYkw3AIAsza9VauW9Jvw+t82WBcLOxtUUbjZ+iNcVhSOoKtXg0 6hjr3rPj+xatSObhy/vlsdAyZsFPnqLgIYyzZYFmWLGh4CfE0H+GQ/pDed2neAc6vCz9 xQ5wq6skseB6dMOoCfQbLtTMJ3Hm1xc8wpjA5Roz42FQxew0Pwav8Y4cgwl6k77RqTkL Bfmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SSJlREGT; 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 m81si13570315ybf.257.2021.06.14.01.43.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jun 2021 01:43:59 -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=SSJlREGT; 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]:54364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lsiCM-0004N1-Iw for patch@linaro.org; Mon, 14 Jun 2021 04:43:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lsi6v-0002MP-LE for qemu-devel@nongnu.org; Mon, 14 Jun 2021 04:38:21 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:40619) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lsi6n-0003Zv-5j for qemu-devel@nongnu.org; Mon, 14 Jun 2021 04:38:21 -0400 Received: by mail-pj1-x1032.google.com with SMTP id mp5-20020a17090b1905b029016dd057935fso9589252pjb.5 for ; Mon, 14 Jun 2021 01:38:11 -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=UZkn/bCz3YGcO9TqhXoosXO7opN8+jen9eeeiO+Mw8Y=; b=SSJlREGT/yv8Er9ROaPRLix0KZGEhoeElfqmFmPuh1LkGcO0KuZvpCZFgmCnNdB2Jn Xdn2eItMpgGbK/fImwcCHnafZPSlgRuhIA7qIIVfnymNhoTCW3oAaVC0Jw0C8L/Ucdyi IW8AZU1PfheTPYJdFCPGJCo9FtAYhk5KGFtWrhhpGdrT0PiIo4B4zeUj2ImePYFYM7cz awk0xU6kmEhWDvUZBlwXa10P6ejLhrQDuj2ney61sv/5FudCRs7HW2czRlA64/ikT5TU dliyR42zN7sst2wPh2y1fKPPJKo0LfpPxBhgbygX8FevVtq9G9Z1HTwkeSe1Q5hqVRQJ ZsBQ== 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=UZkn/bCz3YGcO9TqhXoosXO7opN8+jen9eeeiO+Mw8Y=; b=j2sjOsICCQKC3neNFBdMtiVBOTPkReH0XafKP9nUvIEUyYwVudjfeweDT5ElHikQ+e Esoy14CdW7i4bSFZLrBq6Vn40TipkX9tOFilLPgKCD59tm4LWYH9XlQjUU0SbkfmxlM8 Tg8xErUfmClSoddfyGCKiXwGxW6RwWgv2alVj/XuOXJ4nBQSABRhVOm/ShsjJmZnfTq6 uhN09tAPyFiGEE3t3g1qwn3PJwMPhsSg7pkKe0huznHoHqZPxx5/zVAAgCiEfkql/XSb 0edUk1ShjeCxmxVVmKZqFA4JSvvfKrYujpdmSN0rM2q3+KfZJ+gevlKVPTcgCohkU9Cf bhFQ== X-Gm-Message-State: AOAM530LcHaXeVVCCKs7HnZuArs9BekR+6vfG60I4TzlBtE1bo21ZEx/ WtpxW06T3HqnHn6KxDWxxpAg9JCFWqLOHA== X-Received: by 2002:a17:902:222:b029:11b:9cea:eea9 with SMTP id 31-20020a1709020222b029011b9ceaeea9mr3816446plc.11.1623659891130; Mon, 14 Jun 2021 01:38:11 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id h20sm2242022pfh.24.2021.06.14.01.38.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 01:38:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 16/28] tcg: Handle new bswap flags during optimize Date: Mon, 14 Jun 2021 01:37:48 -0700 Message-Id: <20210614083800.1166166-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614083800.1166166-1-richard.henderson@linaro.org> References: <20210614083800.1166166-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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" 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. Signed-off-by: Richard Henderson --- tcg/optimize.c | 56 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) -- 2.25.1 Reviewed-by: Peter Maydell 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):