From patchwork Fri Oct 29 04:33:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516405 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp405293iml; Thu, 28 Oct 2021 22:00:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOfK5h/jrypANMwgTWQMFVS0dzhy80z3Phi5rVF8NFK+RjkZYAY7FiIz0WpOzlrl18AUB+ X-Received: by 2002:a9d:8d7:: with SMTP id 81mr6876537otf.352.1635483643716; Thu, 28 Oct 2021 22:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635483643; cv=none; d=google.com; s=arc-20160816; b=kCZoo+wbqH6pfqBWF0j8EOZVZCuMejv3cKCAxg1PeKASxSXvKHIo5gFb6yFXHB7/os vL/06Sb21Ig70HYFr3o/j0XTMfbW8mPcux+hthAbXIrvWpo4BHMWmLSASU5fLMKJYe3U W5SBQ01GYLDTRFGAdPkesEsqs3gqHX8eIi1G5EP/4qaEzzAXHUG/UxZxkFv0gv/o7iaP hYrPLyGyiWi1JzB0QWYX8guFTIqlgILu12/G77B6PBMJHWpmp+3mikNfTrddVvuTuB52 hjK4YlZKO2puUkG/fTH4yp5bIRjHpoXWxn/4z+yD7PIvzra+6lh35magavwUYzGDh8wV Ithg== 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=p1UNT79xG4oDnmYUiMREY20bNauejtvwzT0okXNXFUU=; b=jkaRSRWYh8xsCab69F1PcygRoJ+ISuBN6B8d+Ll11TuUYpE+YFmcobftVbDYgRyyFl WPR/x7IxlkZW0NHJ0W0c2JcZu9RkZ/zNuUXm0MrmD76BSHXSk98mLhc+3HlS7MM5bGD6 chsLlAs4MurMcL/1rKqm6LXsB62FwrMzhCNw304C97t50ivcUc68Fz7AJAQPfesyZJx+ LBq85NMRWMi6Vrn8eI8VADWeq0HoNIFAXM9RBtwX7dfNwwp4Crv4nv75DiaiIDQy8N6C x+RbTrfTfDPkF1gIkdTdKRD71slN3NYxmFSxILivsDMsXrMh7HSn02XfE51YFKqS4xYp Whmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GjuBGiG0; 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 q13si6374329otv.301.2021.10.28.22.00.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Oct 2021 22:00:43 -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=GjuBGiG0; 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]:44646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgK0R-0001vS-11 for patch@linaro.org; Fri, 29 Oct 2021 01:00:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgJae-0004oq-Kt for qemu-devel@nongnu.org; Fri, 29 Oct 2021 00:34:04 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:45802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgJab-00080Z-Om for qemu-devel@nongnu.org; Fri, 29 Oct 2021 00:34:04 -0400 Received: by mail-pg1-x529.google.com with SMTP id f5so8660068pgc.12 for ; Thu, 28 Oct 2021 21:34:01 -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=p1UNT79xG4oDnmYUiMREY20bNauejtvwzT0okXNXFUU=; b=GjuBGiG0LoAzwp+/kUW+5lg2ClS6oIYxI3P+eeqsJCcvTT0RVQCem6Wvm0ijHzEcZB xWL2fqvF2gofc9LIm7TxhJPdlwZBDbvnosCKxQOM5hxiaxWaovSldigsG9U8XuuXW9ML 3KB7OI2onkS5XjddVvHOYQsODmwqNPmp7G2RKGmaCzR7TzCbkhIwOl7n+Z+SieNMjRtR C7Cc4EIiYU/Lu2LDWFflQ1cmRrYZ6KslkXKLGYR1Bz3YewLIF39/hDzNGq6+Sa/Cc+Oe cgxTx6HOpznP8ndUYqaEzn/pAdPTp/+Hkq7OXz/XcusiX05unEKK3gRkpBX9PXrRhks7 7PHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p1UNT79xG4oDnmYUiMREY20bNauejtvwzT0okXNXFUU=; b=uECfZun+bVrVysjMKAiBeVNsRa7ilN7PQCUf0U6LzrijE7kEqE+oVuNKzPoca/IJ0r Gtx+LbZpg1xK5WVuWM8YfSv+rtF/9tYFxJ4Af4RRVK1uPXGUGMwEWg6wvx7rfV1H6Lw5 SwlWVWlRQV+Oj0I1VmLt0ggugP/XnQ5iLoc4p0AQ64DpLhLrKvBUfi/JLNaCXLO8/aqZ 1Y6pRVdmN5zZEv67TPoX8/yxFxGptzWiSZ62Y+VLEbkIbAgsr8Fuj7twlgLtcDHPX9Pm KOFNvWmvzZpIVaLpYllvOp9pfI7mfm3yVuiwrlPOdr9/cElonCwV6kOATtq3xqHhN7UQ JcdA== X-Gm-Message-State: AOAM5327dM2FumdsCIWVHIpBBRKY2UKAEKzJdupU6nNhYGNpVcsrAgeC J4uZNwTh9AlGocoDoUQrZHF+VvXuBRSREw== X-Received: by 2002:a63:fa16:: with SMTP id y22mr2165439pgh.53.1635482040553; Thu, 28 Oct 2021 21:34:00 -0700 (PDT) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id i11sm4120257pgp.18.2021.10.28.21.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 21:34:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL v2 36/60] tcg/optimize: Split out fold_xx_to_x Date: Thu, 28 Oct 2021 21:33:05 -0700 Message-Id: <20211029043329.1518029-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211029043329.1518029-1-richard.henderson@linaro.org> References: <20211029043329.1518029-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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: Luis Pires , =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Pull the "op r, a, a => mov r, a" optimization into a function, and use it in the outer opcode fold functions. Reviewed-by: Luis Pires Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/optimize.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) -- 2.25.1 diff --git a/tcg/optimize.c b/tcg/optimize.c index 2f55dc56c0..ab96849edf 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -704,8 +704,22 @@ static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) return false; } +/* If the binary operation has both arguments equal, fold to identity. */ +static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) +{ + if (args_are_copies(op->args[1], op->args[2])) { + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); + } + return false; +} + /* * These outermost fold_ functions are sorted alphabetically. + * + * The ordering of the transformations should be: + * 1) those that produce a constant + * 2) those that produce a copy + * 3) those that produce information about the result value. */ static bool fold_add(OptContext *ctx, TCGOp *op) @@ -748,7 +762,11 @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op) static bool fold_and(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xx_to_x(ctx, op)) { + return true; + } + return false; } static bool fold_andc(OptContext *ctx, TCGOp *op) @@ -1111,7 +1129,11 @@ static bool fold_not(OptContext *ctx, TCGOp *op) static bool fold_or(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op); + if (fold_const2(ctx, op) || + fold_xx_to_x(ctx, op)) { + return true; + } + return false; } static bool fold_orc(OptContext *ctx, TCGOp *op) @@ -1747,19 +1769,6 @@ void tcg_optimize(TCGContext *s) break; } - /* Simplify expression for "op r, a, a => mov r, a" cases */ - switch (opc) { - CASE_OP_32_64_VEC(or): - CASE_OP_32_64_VEC(and): - if (args_are_copies(op->args[1], op->args[2])) { - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); - continue; - } - break; - default: - break; - } - /* * Process each opcode. * Sorted alphabetically by opcode as much as possible.