From patchwork Wed Oct 25 07:26:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 737846 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp150155wrq; Wed, 25 Oct 2023 00:32:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSsA1OXNr1Xvmr8vAxrDNRDl/+VfywjmScNzfxiQsim7NPk9QQmE1wvW6QrbFc4A4yuEWu X-Received: by 2002:a05:622a:4cd:b0:41e:31b5:5c8d with SMTP id q13-20020a05622a04cd00b0041e31b55c8dmr2880384qtx.56.1698219123931; Wed, 25 Oct 2023 00:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698219123; cv=none; d=google.com; s=arc-20160816; b=E0GNvT25MIdpcrPFijObKIWtF33ruGv9VIkpzIUN2DxEGyKmiIl6RCcmu3/ghAcxie gJYN3AIlRPxOF02DyXwsbOEGOnzQ9Xqk8jivr7qmHY4v9z43HYdKlom/kskkOE6OWQbJ WgP9S+TcjhHBFC9jP0gk73f7hw8pc2DB0Vv4TWlwWf2czLQ0Ogo4GWCKsGIRKuCr8MoT u9CX2VA8ACJSRb1dXo6cgjcczMSzolMH0t2D7N/+5uMJevbKgKMVz6kLhwTYi1VUeEyo w9lSCFD9fycB9VD3sieb5tuFDnMnXSpS7g+t/Z5vCyYriCGCqZhEc6DZ/pdADtUy0RfW N69Q== 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=9eXocbu34bghBLrSPFKvIsugn7thygfTREC245booiE=; fh=ycigHkwOPieh2u5PmcA89sNk/qPD1ZkdDlL8Mchfvw8=; b=iSRIqZ4vdSnef9aW4ydtu3BqkkLJjzdj4umcY1y3j0YUSLrrT1o6offlSSPypx7ORI kLDDkqQOfTCY23zZCaiKgEQxUpxYicRPicteT9DWKBM5tB/O3aeIpMyox9xz9ujSEWfb /tTX4pPIEfv/G6hqqKQw7lqkcj4Nk/pw2CaRif27esafaU9b5EEy0lTF/5SVUVeVGrmP wPPI/mjOzExD5quev8MkMvJp2NNuxbShlhDGbHUSnYgz3c21AUZPOwjgxrl4zs97S8OY C45vJqT1CGA5dUNQS4IoX5gmC3e0oZyCgDkjrrpK5VO5TaPtximSgHucUdvgswK1VIWZ ag5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VhkYNyup; 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 o11-20020a05622a008b00b00419629f7784si8273968qtw.198.2023.10.25.00.32.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2023 00:32:03 -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=VhkYNyup; 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 1qvYIR-0000AC-Kf; Wed, 25 Oct 2023 03:27:19 -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 1qvYIN-00008V-41 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 03:27:16 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvYIL-0004dz-Cq for qemu-devel@nongnu.org; Wed, 25 Oct 2023 03:27:14 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1cab2c24ecdso35342085ad.0 for ; Wed, 25 Oct 2023 00:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698218832; x=1698823632; darn=nongnu.org; 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=9eXocbu34bghBLrSPFKvIsugn7thygfTREC245booiE=; b=VhkYNyup9hyWgyQjSCrfqG8ZSEUoNYIKdOhahB6iPscVbVJCCezrjKJHhuHvPWx7FG 07omVMQTf2MlDAqeDOYP160OX7CWhm/QP6rhXogBRHrKGjta8TPSoKjPsRQq5ktbDNpe 7v7tqsl+KbnV+P6ZzfFOWm6oQwnvQNpkYHoh30uRMVVHra4Lw0WX/0zPuRo7Yb4i73OU /IHMm26nkyh6nT8bJjsoptHdvQlIVGs7VJnwa7i1rjXtw435Dg/8uPs5TglbXmtpUEsU 6nPKzfnwtGipqFYLVWiLSMdfDv4NOGeb325RpswIqtYYArEvgymO3RMo83b/KXPRaRGp Arsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698218832; x=1698823632; 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=9eXocbu34bghBLrSPFKvIsugn7thygfTREC245booiE=; b=wWUZOKUFJHLJ1NbrI/4/mnHU9xxEjoDIOT6iwsE/WkqSQJNBPWm5aiF4+uR7fYJyEj ZXhAG66ij4bWUeNlPCN1y6G84lF6G91fU6jMzZva4qSPR4AwmNyG/U8ipNj8ZKQl+A7Y GcC4R2PNH6Zq99ndIa58eaqczBFFZvD7VsKGIp3L29OdjHjbKL5VGdSOzPfOV/US/Vdt +BVJe/CqfJBUwkwZJ2biECO/x1kD17VRG0ZCBRdJADLC6Mgkzb/6wlmSYB7igtrPnugx Ncaz7H7CH3uBDOsk1e+KffvETCpi0r4NoMJytKZZF88Kg5biDt2Yfq7AnyYnnVHGk2BQ xUrg== X-Gm-Message-State: AOJu0YyH3IxYLF2B7QVc0S2QKlBSfbI9MBVz6KSb2NLWij/cniNB0BQR 45/xsM/tMQmBDyXKHAt/5Ild4x53DxbPRaD722A= X-Received: by 2002:a17:902:e887:b0:1ca:79b6:ce38 with SMTP id w7-20020a170902e88700b001ca79b6ce38mr11679045plg.17.1698218831856; Wed, 25 Oct 2023 00:27:11 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id ji5-20020a170903324500b001b06c106844sm8578661plb.151.2023.10.25.00.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 00:27:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: philmd@linaro.org Subject: [PATCH 03/29] tcg/optimize: Split out do_constant_folding_cond1 Date: Wed, 25 Oct 2023 00:26:41 -0700 Message-Id: <20231025072707.833943-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025072707.833943-1-richard.henderson@linaro.org> References: <20231025072707.833943-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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 Handle modifications to the arguments and condition in a single place. Signed-off-by: Richard Henderson --- tcg/optimize.c | 57 ++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index e8a13fedb5..89cc794d24 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -672,6 +672,23 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) return false; } +static int do_constant_folding_cond1(OptContext *ctx, TCGArg dest, + TCGArg *p1, TCGArg *p2, TCGArg *pcond) +{ + TCGCond cond; + bool swap; + int r; + + swap = swap_commutative(dest, p1, p2); + cond = *pcond; + if (swap) { + *pcond = cond = tcg_swap_cond(cond); + } + + r = do_constant_folding_cond(ctx->type, *p1, *p2, cond); + return r; +} + static void init_arguments(OptContext *ctx, TCGOp *op, int nb_args) { for (int i = 0; i < nb_args; i++) { @@ -1053,14 +1070,8 @@ static bool fold_andc(OptContext *ctx, TCGOp *op) static bool fold_brcond(OptContext *ctx, TCGOp *op) { - TCGCond cond = op->args[2]; - int i; - - if (swap_commutative(NO_DEST, &op->args[0], &op->args[1])) { - op->args[2] = cond = tcg_swap_cond(cond); - } - - i = do_constant_folding_cond(ctx->type, op->args[0], op->args[1], cond); + int i = do_constant_folding_cond1(ctx, NO_DEST, &op->args[0], + &op->args[1], &op->args[2]); if (i == 0) { tcg_op_remove(ctx->tcg, op); return true; @@ -1550,21 +1561,18 @@ static bool fold_mov(OptContext *ctx, TCGOp *op) static bool fold_movcond(OptContext *ctx, TCGOp *op) { - TCGCond cond = op->args[5]; int i; - if (swap_commutative(NO_DEST, &op->args[1], &op->args[2])) { - op->args[5] = cond = tcg_swap_cond(cond); - } /* * Canonicalize the "false" input reg to match the destination reg so * that the tcg backend can implement a "move if true" operation. */ if (swap_commutative(op->args[0], &op->args[4], &op->args[3])) { - op->args[5] = cond = tcg_invert_cond(cond); + op->args[5] = tcg_invert_cond(op->args[5]); } - i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); + i = do_constant_folding_cond1(ctx, NO_DEST, &op->args[1], + &op->args[2], &op->args[5]); if (i >= 0) { return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]); } @@ -1578,6 +1586,7 @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) uint64_t tv = arg_info(op->args[3])->val; uint64_t fv = arg_info(op->args[4])->val; TCGOpcode opc, negopc = 0; + TCGCond cond = op->args[5]; switch (ctx->type) { case TCG_TYPE_I32: @@ -1805,14 +1814,8 @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) static bool fold_setcond(OptContext *ctx, TCGOp *op) { - TCGCond cond = op->args[3]; - int i; - - if (swap_commutative(op->args[0], &op->args[1], &op->args[2])) { - op->args[3] = cond = tcg_swap_cond(cond); - } - - i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); + int i = do_constant_folding_cond1(ctx, op->args[0], &op->args[1], + &op->args[2], &op->args[3]); if (i >= 0) { return tcg_opt_gen_movi(ctx, op, op->args[0], i); } @@ -1824,14 +1827,8 @@ static bool fold_setcond(OptContext *ctx, TCGOp *op) static bool fold_negsetcond(OptContext *ctx, TCGOp *op) { - TCGCond cond = op->args[3]; - int i; - - if (swap_commutative(op->args[0], &op->args[1], &op->args[2])) { - op->args[3] = cond = tcg_swap_cond(cond); - } - - i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); + int i = do_constant_folding_cond1(ctx, op->args[0], &op->args[1], + &op->args[2], &op->args[3]); if (i >= 0) { return tcg_opt_gen_movi(ctx, op, op->args[0], -i); }