From patchwork Wed Aug 23 20:22:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716101 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1002186wrp; Wed, 23 Aug 2023 13:25:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEu20qJSEeDJ5JNZ9CoLvDro8zHy7D0rcy+FpUhFl14z68azsS+DJprP84bIPHuCxHSGKM4 X-Received: by 2002:a05:622a:1c2:b0:410:888d:e11b with SMTP id t2-20020a05622a01c200b00410888de11bmr15761932qtw.25.1692822333421; Wed, 23 Aug 2023 13:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692822333; cv=none; d=google.com; s=arc-20160816; b=F8kc2sQpKvJ5rVTFJf+5NUwKz7NUdMgli2ffb5Qh+xFLK7mrUvp0ShKpYVi+OnjC4c x9q14lGoVQri7xNiOcRHKzuEx+xCsHwMWT/fs6b17hPyE4pCYeLnu0H8DEGCdgAdppuN gThWFUt2jfYkYfsMyPHyZ43wq48q4ndk+RS34aK1lTXlfinV2bhnsk+XzaNYRkl7ELKe s3XHZ6gpXMR3R2QsT/yjjLElE1kfjU4xbTsEYjDu925fQJlGyDFxHKIqyXbf19EstJia Px9QaVzseWqJEYLAnuIq21HrkV+gqRPyrMOvCoUoEEOLf2DSE8/Mz7k665byybylk6n4 lNsA== 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:cc:to :from:dkim-signature; bh=JJH5DAXKpxVvxGZBhnGdGfJdujLL25EIiq+q/aDhCI4=; fh=hqFW2tULe/VYZL5cutrFBQv2fOj+hfBo4XY3KgwhGJw=; b=CzrgH8KDi1FUqG/H2ZDy/cYMq/qWgBdnUuYAE+KIPaP3FdlXxL9Uoc/shbqcbkGVAa HgpYCqVufidOkFCj871Iw3AAVOvO2SkoNzbjRvct5wYUJ60tVIW5hE3z+cgOpgCXxzBV yOpkspn69c0u7rDDwkTkcI7C6vvJb2ZWbdxmNQUg6R5QtoWKeqVTklhlYECYG8Unv9Lj CVq5AEHq+upef2SzogWR+WA4hdCmE146du6u97hJVMaSI8DII7squlowkX5JIvMem8EU Sup/2A49ZE9PbK9WCSJ/OFsxvk7sl+u/plF7ZoRMVAMRFHBskZXg1PcJGA9DwA7AkKiP 8F6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bZus8SsO; 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 g20-20020ac87f54000000b004036d2abaa9si7787998qtk.52.2023.08.23.13.25.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Aug 2023 13:25:33 -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=bZus8SsO; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYuOd-0008US-Cp; Wed, 23 Aug 2023 16:24:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYuOV-0008L5-8P for qemu-devel@nongnu.org; Wed, 23 Aug 2023 16:23:59 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYuOK-0005UA-Tu for qemu-devel@nongnu.org; Wed, 23 Aug 2023 16:23:56 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bbc87ded50so41173835ad.1 for ; Wed, 23 Aug 2023 13:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692822219; x=1693427019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JJH5DAXKpxVvxGZBhnGdGfJdujLL25EIiq+q/aDhCI4=; b=bZus8SsOIdrq9tLnLASKzh/xUmascleeVXt1dbn48NJyfFv3YQJcDgwFGeZtqa05e1 COOjjSN7Sduo9XyaXBek36wJlrRjKBYtvLJbLfUu/2kcp6HzUpzL/JTJgzNFKnIIgdHE Obo1aZap80oSnvznvkOKiqh+KGk/A//R5wqHplicGLqZEuAxGXllO4n4njSSxpnRzoZu /gdLesAmX9cn12736ISxyDr5innthnMTsAx3IyeOXLsuWwz6vyce8JIV4mKBaf/VTS3u FomJ0UDSILUvpBP+FuBuniF662zQC9HBgm3Ft5mdUIR05JzpJR0ydQK/K0OtpOKG38vD NWmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692822219; x=1693427019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JJH5DAXKpxVvxGZBhnGdGfJdujLL25EIiq+q/aDhCI4=; b=FarHbEMpuqKYYtq3kj9fDtzvdp46Ek7dV2ewaJjiyvqSQkg3X+GWPL5aKkpO946yfz TEmqLQzAfBiMZGsTw998wXWWb7SUeGAQl1vEkBpdUUH6rncdPid8oi/7O8yoO5WfOfAV DJ0qvGUi/IRXxXI40iiri7Hal+UD6yH2abWuh01/+q+r23P6ERXnUJEtYeN+iHuxboJ9 xr/UYxq7SqzGtKdOthUrVBxKd2rHZ4b5l32pl1CAo2ZDuZztqJXyOsgU0GvuJ/d/8R8m WcAEgG8LA2Q4lmAZEs/DloIVi95gD5+3NiHGu3vJG5jT9qBBGJckJ/K1TsCgkW3f3fYO l16A== X-Gm-Message-State: AOJu0YxvozRvQzN9NX/yFIYJCxv2wxu1GWKiu5KgVF0ZhMbm4P/Ba6O9 LOr1YxE8tetbt/P1sHcpXhaV0LWizf85sTBc9XY= X-Received: by 2002:a17:903:124b:b0:1b7:e646:4cc4 with SMTP id u11-20020a170903124b00b001b7e6464cc4mr14122325plh.28.1692822219307; Wed, 23 Aug 2023 13:23:39 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:72f0:1ea7:85d2:141e]) by smtp.gmail.com with ESMTPSA id iz22-20020a170902ef9600b001b9da42cd7dsm11418641plb.279.2023.08.23.13.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 13:23:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PULL 12/48] tcg: Fold deposit with zero to and Date: Wed, 23 Aug 2023 13:22:50 -0700 Message-Id: <20230823202326.1353645-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823202326.1353645-1-richard.henderson@linaro.org> References: <20230823202326.1353645-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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.29 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-bounces+patch=linaro.org@nongnu.org Inserting a zero into a value, or inserting a value into zero at offset 0 may be implemented with AND. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/optimize.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tcg/optimize.c b/tcg/optimize.c index d2156367a3..bbd9bb64c6 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -1279,6 +1279,8 @@ static bool fold_ctpop(OptContext *ctx, TCGOp *op) static bool fold_deposit(OptContext *ctx, TCGOp *op) { + TCGOpcode and_opc; + if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { uint64_t t1 = arg_info(op->args[1])->val; uint64_t t2 = arg_info(op->args[2])->val; @@ -1287,6 +1289,41 @@ static bool fold_deposit(OptContext *ctx, TCGOp *op) return tcg_opt_gen_movi(ctx, op, op->args[0], t1); } + switch (ctx->type) { + case TCG_TYPE_I32: + and_opc = INDEX_op_and_i32; + break; + case TCG_TYPE_I64: + and_opc = INDEX_op_and_i64; + break; + default: + g_assert_not_reached(); + } + + /* Inserting a value into zero at offset 0. */ + if (arg_is_const(op->args[1]) + && arg_info(op->args[1])->val == 0 + && op->args[3] == 0) { + uint64_t mask = MAKE_64BIT_MASK(0, op->args[4]); + + op->opc = and_opc; + op->args[1] = op->args[2]; + op->args[2] = temp_arg(tcg_constant_internal(ctx->type, mask)); + ctx->z_mask = mask & arg_info(op->args[1])->z_mask; + return false; + } + + /* Inserting zero into a value. */ + if (arg_is_const(op->args[2]) + && arg_info(op->args[2])->val == 0) { + uint64_t mask = deposit64(-1, op->args[3], op->args[4], 0); + + op->opc = and_opc; + op->args[2] = temp_arg(tcg_constant_internal(ctx->type, mask)); + ctx->z_mask = mask & arg_info(op->args[1])->z_mask; + return false; + } + ctx->z_mask = deposit64(arg_info(op->args[1])->z_mask, op->args[3], op->args[4], arg_info(op->args[2])->z_mask);