From patchwork Wed Jan 10 22:43:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 761466 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2112074wrz; Wed, 10 Jan 2024 14:45:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLMH3DiqcKIGFPS/zI1X2W4CgHN1NmvIOYXBnFKwHocikyvq+z8+ge7+PbIFPt3Fx4c74c X-Received: by 2002:a05:622a:2c7:b0:429:96e2:876b with SMTP id a7-20020a05622a02c700b0042996e2876bmr234244qtx.65.1704926731516; Wed, 10 Jan 2024 14:45:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704926731; cv=none; d=google.com; s=arc-20160816; b=Vqlf5RmgiCFurRHKBJu5fJgBKXYQzOqGhAfMLDFfU2tYN5utFQrKj1NNVaacy/zng3 kTCf+Org56EXnNq2TE6IGgrxT+wTQbcgeytAoD+iU8WdeF6+jMhewjEmf8NG12Hf6fLr ko18yuz85cbMBfqITRL2i6u/UjYEvFcuyS5zlPfbrYJ6wJdJCZgzUvn2Uu4G+N3jLFhK tXrDdYSpwtEuVPfW4CT79CgpxUr9JmIVnfqlB2HZgephvJYxeRfJMgaqww5bag2jJGA3 wq7AwWxusyIyc9sDDWHwERlZ4cKOEC7wM3AWC09brKGyC9enrdY+qdIBfHNruC1BQaUR UyWg== 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=rCOb1ACImxEyjzPr7SpomivAS+ARwGZqu81A17yuvPw=; fh=GbSB792CRg76qyQfASHmg380JBauy2gTuYi49sbOwBU=; b=QKiOiDchhMk/w79Ss37LFkqv4gSBQilVpELQcyTnqFKusot4ww1SVsm4b6yhd2KC2K KX17yNJu8uDBxip6bg8MAqYLcRKopl+HXOQZpssmyjHPh5TiHU3jFhRBS92ztWPm2hmy HflUbxxir5hRGGsLxvNpU8Z1G7K3CAk9Zzqw9dCpUUfilkl94U2+7PO5+9ElBtfMos0a 4XfmHpmBzOypjuQB9Io54PP6mWfzajvVFoVOej2KlCDkq0vgSWzkw+YAzz+mbKgOjZYm EWhWv7UXPPR9uo3wUwRPKI1gQfN+jo90SpFHoJRdi97mi6TN62lB3QBrbjb8UGBu9Spb kd2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UM/cDNJi"; 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 fv26-20020a05622a4a1a00b00429899fdb2esi5491873qtb.639.2024.01.10.14.45.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jan 2024 14:45:31 -0800 (PST) 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="UM/cDNJi"; 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 1rNhJg-0004VT-Ql; Wed, 10 Jan 2024 17:44:56 -0500 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 1rNhJf-0004Ul-05 for qemu-devel@nongnu.org; Wed, 10 Jan 2024 17:44:55 -0500 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNhJd-0002ei-78 for qemu-devel@nongnu.org; Wed, 10 Jan 2024 17:44:54 -0500 Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-429be9fe952so2179131cf.0 for ; Wed, 10 Jan 2024 14:44:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704926692; x=1705531492; 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=rCOb1ACImxEyjzPr7SpomivAS+ARwGZqu81A17yuvPw=; b=UM/cDNJiEpfgOuVsnNsDgYmJ5ffqf8VV23QtN0eyI7Q9k5MLlneuOJYFOIK5eQePlV nYvD6qCzdRObrOrJmNFKHJy58LgLyK+pChao6Xo329TZWbBVFVJQGN71iNcWupwcTguW NOhZnmYLI0Ru5qC5loSFwk0IaYFSMeW9LsnWlW8flV7JA3DAVzn2XDMuDd0fvT0T8UvJ knhGPTjpMgptRXmg7j0AGrIutb5BXYTLV4mcQMKeZ9e3O5FEjZoRgk7VntwQ/4RaNgHS E6t9TDfG70FtLpWz7Xb9L0Z6Ly+kPXMB+DRe2kDWzQxNWXZOmeZ6MbNs/Y3muzXQtPKc +iTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704926692; x=1705531492; 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=rCOb1ACImxEyjzPr7SpomivAS+ARwGZqu81A17yuvPw=; b=ttcSKeW2cvpAxAuqlAEbXAae2CUeXT01gVMGmkvDxdPUTvsKbBj/lbtTq+/dSAPXrN mQPz83qJ+CYaL7LQDdcS0lrgrqFCjZEqFqN/6JKEH/XYpr9JtxzPXzALalvL8LtWGo9X 0mgxlNguydRBN0/NrMYWGm3vNlhGQFXcQC4lGC8QGpIIlYkr69Si5/EFt/s2k1UKlOkH gT5QzNwPyaFW5uaszmGSukRafTGkknBi4Yphchma3ER60CSsjRnAYzmqiFUj9Iie4RO5 /2IvBkAL2hy3OR5R2IfQeZOHN3BzVSDSTcPcy2q/FgzYn4SfacSDiOTZg0dJrsArdWtM Aq6w== X-Gm-Message-State: AOJu0YwROVaxcfascXCZzwGHaVTK7nO636ytpK7a30VKs+MZ6uCIKg2L HglKUcvPbVCKXSSXvJmRDMZCHit3RE4+F/1ZKTqDOC7F8HmX5u1b X-Received: by 2002:ac8:5941:0:b0:429:9341:ddf2 with SMTP id 1-20020ac85941000000b004299341ddf2mr1373680qtz.29.1704926692155; Wed, 10 Jan 2024 14:44:52 -0800 (PST) Received: from stoup.. ([172.58.27.160]) by smtp.gmail.com with ESMTPSA id ks23-20020ac86217000000b0042987f6874bsm2092281qtb.92.2024.01.10.14.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 14:44:51 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: philmd@linaro.org, pbonzini@redhat.com Subject: [PATCH v3 04/38] tcg/optimize: Split out do_constant_folding_cond1 Date: Thu, 11 Jan 2024 09:43:34 +1100 Message-Id: <20240110224408.10444-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240110224408.10444-1-richard.henderson@linaro.org> References: <20240110224408.10444-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::830; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x830.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, T_SCC_BODY_TEXT_LINE=-0.01 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. Reviewed-by: Philippe Mathieu-Daudé 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 73019b9996..9c04dba099 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -796,6 +796,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++) { @@ -1193,14 +1210,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; @@ -1695,21 +1706,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]); } @@ -1723,6 +1731,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: @@ -1950,14 +1959,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); } @@ -1969,14 +1972,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); }