From patchwork Mon Aug 30 06:24:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 504299 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp1515059jai; Sun, 29 Aug 2021 23:36:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIcePMBoX3CCW6f9BeDRF6APZ/erkDa9FrimstTYFoC3uxHyAAmtXUQ95YeHdu5TPl5p5s X-Received: by 2002:a25:5908:: with SMTP id n8mr22388941ybb.193.1630305360564; Sun, 29 Aug 2021 23:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630305360; cv=none; d=google.com; s=arc-20160816; b=IClJDv2Xdjaq5l+6EI22py/tKxdmWbOR4uRA5dFf6qs4w0hrWoOWehVJ02rghQ4V2m 7PilaqxmzXP1/sjsJYrRrwbOOdN3s8j9XUgu15LMkDAjpoYgMckYS/k4w0NH3aKtM9uw KOTXLj9sngrm92HdmS3yMFcrBn19GO5Ntb8HogOcohHc9EMI05oRLgFrBKUZt9BjqEXd VhVaADuEnhjUPG1AsSmxfMk0oU/y8tK3QG7u0bh8woBIrpaHVqNMkbZpgvpINfDWPCNv JWEVKJH42aX30V+1NnjlXsTNJcN2kAX/TO1CqKGy/crxAygzvocJI+JBVdOsn7QXr7En VRCQ== 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=pU+TfWaNabr7baPocO4XBLVY8gDQ0e05DOYx5MFcfKU=; b=BjBhZuGsz6SrZCX7AMf2/RB3fBsj5aWjOFhh8Map7hxWeahyEKvjFzwjHhN/41aCeQ zhn3DdmyeoeRxvl+z5nNqdx61FJmS3xKmvW+4NyROMus5WDJxlv2Uhleu3+u1OxQH/Bx QTZcfAsyblYI/poalY5t5FlSFWC1CNaPltuXqcv3I6nOtJZhFnLDqTkDR1fcp3JTRNfh GmtDRa08OQXL2ZhCuj3v7SqrX8L6Yl4HdcGoYwufygWL9I5FShtvokTLux6nYmexAowL sxM/UUuXM7zyswaYgBroQopkfhvO3S8pXaHyrDlQG0zA2WxbfFeNNIvBQ9ISq5DfXWXy Px7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bMRfYiqs; 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 e185si9472920ybf.247.2021.08.29.23.36.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Aug 2021 23:36:00 -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=bMRfYiqs; 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]:56802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKatk-0004yM-1U for patch@linaro.org; Mon, 30 Aug 2021 02:36:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKajC-0003v3-Lj for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:07 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:34416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mKaj9-0007Ui-JW for qemu-devel@nongnu.org; Mon, 30 Aug 2021 02:25:06 -0400 Received: by mail-pl1-x629.google.com with SMTP id j2so7949117pll.1 for ; Sun, 29 Aug 2021 23:25:03 -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=pU+TfWaNabr7baPocO4XBLVY8gDQ0e05DOYx5MFcfKU=; b=bMRfYiqsjaV7QSOY/6WNEQUb4sUceIhzg/lwQ4ieDLV/OsyHR6nuK3bcAc0nf6Z3RB uCKEeyXqEBkNRMtojNfGjbOZ+XgmcJx/HiMlORqXDAeQ85vQQZz/A9azo/uCTdU4ORlP ijH9hFUrGUuVpLKUxfMAQpnVAuvhvzeu7zMXXMjjALJfnVOkIujfKillAv/+BncTl9UU IwBTflnC9JyTMtS7Xn1Os0et2E8hW1TbF8qB7e3vuyY/jxETWUTPWsrNRgNxBHhQSIU1 nqkNP2ysSOFE6rS92OXpYrOsADc8GuVzAWOwIvYaxxXgTLF4FhTBwk5wcbtm0HaRYpyG JXYA== 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=pU+TfWaNabr7baPocO4XBLVY8gDQ0e05DOYx5MFcfKU=; b=P3uXHG494aqa70JrlSth5cE7as6Yar0R80J7wIOQz9IiH2QycbrDJelg353sl/h8iE hHn/d9MmqEQLPVVhLd3oSn9SWvwINFsKiTCevjiVzPuV8DWrvh5RLj8LPCpM0nhh7CIf 939+raYh6iYK67YffZ8hQP2xMFs8xeXEwumvD90+ySpMnJXD6bChj5Kl00xvyADDOzqL rXl8/ZQvGgdbpFmNuIxG3efGZSq+4hcPRcM5TekDKBme4hp3RosoWE8WPHpZW7elXooH dNnMZYQ4zbjgzg7G3knYP7qbb9lJggJkDPcSK9W1HSX1WOMg6Gbog/Y58WVAdkrb7p7o NMKQ== X-Gm-Message-State: AOAM533iTquVCzDRTQlbrs6+4jnaYNMIN2Z3VS57/C2/buPuhQxmIHSD 0PA6SCLu+H0yAs6NBvawqD94Ia+NEN+cww== X-Received: by 2002:a17:902:c40a:b0:138:a82d:3aa7 with SMTP id k10-20020a170902c40a00b00138a82d3aa7mr12243432plk.54.1630304702155; Sun, 29 Aug 2021 23:25:02 -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.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Aug 2021 23:25:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 14/48] tcg/optimize: Split out fold_mb, fold_qemu_{ld,st} Date: Sun, 29 Aug 2021 23:24:17 -0700 Message-Id: <20210830062451.639572-15-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::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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" This puts the separate mb optimization into the same framework as the others. While fold_qemu_{ld,st} are currently identical, that won't last as more code gets moved. Signed-off-by: Richard Henderson --- tcg/optimize.c | 89 +++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 38 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index 76f9772648..a3780514e5 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -692,6 +692,44 @@ static bool fold_call(OptContext *ctx, TCGOp *op) return true; } +static bool fold_mb(OptContext *ctx, TCGOp *op) +{ + /* Eliminate duplicate and redundant fence instructions. */ + if (ctx->prev_mb) { + /* + * Merge two barriers of the same type into one, + * or a weaker barrier into a stronger one, + * or two weaker barriers into a stronger one. + * mb X; mb Y => mb X|Y + * mb; strl => mb; st + * ldaq; mb => ld; mb + * ldaq; strl => ld; mb; st + * Other combinations are also merged into a strong + * barrier. This is stricter than specified but for + * the purposes of TCG is better than not optimizing. + */ + ctx->prev_mb->args[0] |= op->args[0]; + tcg_op_remove(ctx->tcg, op); + } else { + ctx->prev_mb = op; + } + return true; +} + +static bool fold_qemu_ld(OptContext *ctx, TCGOp *op) +{ + /* Opcodes that touch guest memory stop the mb optimization. */ + ctx->prev_mb = NULL; + return false; +} + +static bool fold_qemu_st(OptContext *ctx, TCGOp *op) +{ + /* Opcodes that touch guest memory stop the mb optimization. */ + ctx->prev_mb = NULL; + return false; +} + /* Propagate constants and copies, fold constant expressions. */ void tcg_optimize(TCGContext *s) { @@ -1599,6 +1637,19 @@ void tcg_optimize(TCGContext *s) } break; + case INDEX_op_mb: + done = fold_mb(&ctx, op); + break; + case INDEX_op_qemu_ld_i32: + case INDEX_op_qemu_ld_i64: + done = fold_qemu_ld(&ctx, op); + break; + case INDEX_op_qemu_st_i32: + case INDEX_op_qemu_st8_i32: + case INDEX_op_qemu_st_i64: + done = fold_qemu_st(&ctx, op); + break; + default: break; } @@ -1606,43 +1657,5 @@ void tcg_optimize(TCGContext *s) if (!done) { finish_folding(&ctx, op); } - - /* Eliminate duplicate and redundant fence instructions. */ - if (ctx.prev_mb) { - switch (opc) { - case INDEX_op_mb: - /* Merge two barriers of the same type into one, - * or a weaker barrier into a stronger one, - * or two weaker barriers into a stronger one. - * mb X; mb Y => mb X|Y - * mb; strl => mb; st - * ldaq; mb => ld; mb - * ldaq; strl => ld; mb; st - * Other combinations are also merged into a strong - * barrier. This is stricter than specified but for - * the purposes of TCG is better than not optimizing. - */ - ctx.prev_mb->args[0] |= op->args[0]; - tcg_op_remove(s, op); - break; - - default: - /* Opcodes that end the block stop the optimization. */ - if ((def->flags & TCG_OPF_BB_END) == 0) { - break; - } - /* fallthru */ - case INDEX_op_qemu_ld_i32: - case INDEX_op_qemu_ld_i64: - case INDEX_op_qemu_st_i32: - case INDEX_op_qemu_st8_i32: - case INDEX_op_qemu_st_i64: - /* Opcodes that touch guest memory stop the optimization. */ - ctx.prev_mb = NULL; - break; - } - } else if (opc == INDEX_op_mb) { - ctx.prev_mb = op; - } } }