From nobody Sat Sep 21 07:30:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704926933733703.5371158790749; Wed, 10 Jan 2024 14:48:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNhK2-0004da-2W; Wed, 10 Jan 2024 17:45:18 -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 1rNhJz-0004cn-Fc for qemu-devel@nongnu.org; Wed, 10 Jan 2024 17:45:15 -0500 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNhJx-0002uL-LF for qemu-devel@nongnu.org; Wed, 10 Jan 2024 17:45:15 -0500 Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-429c00bf0efso736131cf.1 for ; Wed, 10 Jan 2024 14:45:13 -0800 (PST) Received: from stoup.. ([172.58.27.160]) by smtp.gmail.com with ESMTPSA id ks23-20020ac86217000000b0042987f6874bsm2092281qtb.92.2024.01.10.14.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 14:45:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704926712; x=1705531512; 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=y2ce6D5ByMe3tDiT00xgPKeYRv8+A16TaFSE/MtfeS0=; b=VFS39RS0y8vYnEcaMFmr/G+2y5leAv0vEgk6LgnXLJyijUD7Q3C//I8L4yIYuDYCvb 7Sa9viokTUv2I722qHFo+Uw3WAdtrd2e04PEHUcNJBHkTphSKvaVqLnNF2fM+XXYQ1ln vPFN7pa8dloRpYgZ/DsZCuKLKGJfr/u5zJPOzNyW9+kROsOe30uRxXvgG8ddg8KinJk+ 0BV9W3Elg5TEIkaxxrOBS3gbebUSm28YXxWKTSSOXVDrp16jWvccfdV92ftUoAyY1eN6 8vFXz2MEPpXWpneBG1gbxCsKXsENtMeqmP9XYkx7T7fGSa2v2MUh/ecZzLG4p+emBhRk Aqbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704926712; x=1705531512; 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=y2ce6D5ByMe3tDiT00xgPKeYRv8+A16TaFSE/MtfeS0=; b=F4IGCEqN1Qad0muBofixZPj1RjR7mtIpt2cGdKC41hgdM4TIcYfENsdiaikaGADOpq f2W2TWQn0QwPtzMSj3MLCaZINwH27CbkEl3zlyvOKcP0jakD33EgYP2SYU7n8DtklMiU mbfnD+M5Y6GTT1h1Wv4qQPNpY7B3QeaokCZnzOcyBCpXmor3GQMbze+4YmOAd6g6aVtm acquU5JNkOjIjj7q0aRp7jqP/iPUuRpM2ZFAh7WogSXTL2NsAkn5L+TYXEIiKju48S3o ZtkQv4PfFTuL21NPevYxjpycpwswrg2dIeom+7Gz68vrX5mmjqOBNQl9GQXosr5Onq5f 6q7A== X-Gm-Message-State: AOJu0Yxb+RpNxlD0OO5vtbwrZQ7W0pZAX1k3a5NDgmU/YIbCx96vT0E8 22Go8NKrhyuSNGkqS8IdLSWwJTjum9TUsbn0Au7D0jzoIMVA6TRT X-Google-Smtp-Source: AGHT+IHdKv3jBs+ypfoFgSjfogUm9LKhVW+JE9Dq65WGNk8GxePySztDJmRzQONs+bztmo/ZbU7ryw== X-Received: by 2002:ac8:7fcd:0:b0:429:a1e3:d036 with SMTP id b13-20020ac87fcd000000b00429a1e3d036mr358917qtk.47.1704926712499; Wed, 10 Jan 2024 14:45:12 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: philmd@linaro.org, pbonzini@redhat.com Subject: [PATCH v3 07/38] tcg/optimize: Lower TCG_COND_TST{EQ, NE} if unsupported Date: Thu, 11 Jan 2024 09:43:37 +1100 Message-Id: <20240110224408.10444-8-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1704926935737100001 Content-Type: text/plain; charset="utf-8" After having performed other simplifications, lower any remaining test comparisons with AND. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tcg/tcg-internal.h | 2 ++ tcg/optimize.c | 60 +++++++++++++++++++++++++++++++++++++++------- tcg/tcg.c | 2 +- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h index 6c9d9e48db..9b0d982f65 100644 --- a/tcg/tcg-internal.h +++ b/tcg/tcg-internal.h @@ -83,6 +83,8 @@ static inline TCGv_i64 TCGV128_HIGH(TCGv_i128 t) =20 bool tcg_target_has_memory_bswap(MemOp memop); =20 +TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind); + /* * Locate or create a read-only temporary that is a constant. * This kind of temporary need not be freed, but for convenience diff --git a/tcg/optimize.c b/tcg/optimize.c index 2ed6322f97..79e701652b 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -364,6 +364,13 @@ static TCGArg arg_new_constant(OptContext *ctx, uint64= _t val) return temp_arg(ts); } =20 +static TCGArg arg_new_temp(OptContext *ctx) +{ + TCGTemp *ts =3D tcg_temp_new_internal(ctx->type, TEMP_EBB); + init_ts_info(ctx, ts); + return temp_arg(ts); +} + static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg= src) { TCGTemp *dst_ts =3D arg_temp(dst); @@ -782,7 +789,7 @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) * Return -1 if the condition can't be simplified, * and the result of the condition (0 or 1) if it can. */ -static int do_constant_folding_cond1(OptContext *ctx, TCGArg dest, +static int do_constant_folding_cond1(OptContext *ctx, TCGOp *op, TCGArg de= st, TCGArg *p1, TCGArg *p2, TCGArg *pcond) { TCGCond cond; @@ -818,11 +825,28 @@ static int do_constant_folding_cond1(OptContext *ctx,= TCGArg dest, ? INT32_MIN : INT64_MIN))) { *p2 =3D arg_new_constant(ctx, 0); *pcond =3D tcg_tst_ltge_cond(cond); + return -1; + } + + /* Expand to AND with a temporary if no backend support. */ + if (!TCG_TARGET_HAS_tst) { + TCGOpcode and_opc =3D (ctx->type =3D=3D TCG_TYPE_I32 + ? INDEX_op_and_i32 : INDEX_op_and_i64); + TCGOp *op2 =3D tcg_op_insert_before(ctx->tcg, op, and_opc, 3); + TCGArg tmp =3D arg_new_temp(ctx); + + op2->args[0] =3D tmp; + op2->args[1] =3D *p1; + op2->args[2] =3D *p2; + + *p1 =3D tmp; + *p2 =3D arg_new_constant(ctx, 0); + *pcond =3D tcg_tst_eqne_cond(cond); } return -1; } =20 -static int do_constant_folding_cond2(OptContext *ctx, TCGArg *args) +static int do_constant_folding_cond2(OptContext *ctx, TCGOp *op, TCGArg *a= rgs) { TCGArg al, ah, bl, bh; TCGCond c; @@ -898,6 +922,26 @@ static int do_constant_folding_cond2(OptContext *ctx, = TCGArg *args) return -1; } } + + /* Expand to AND with a temporary if no backend support. */ + if (!TCG_TARGET_HAS_tst && is_tst_cond(c)) { + TCGOp *op1 =3D tcg_op_insert_before(ctx->tcg, op, INDEX_op_and_i32= , 3); + TCGOp *op2 =3D tcg_op_insert_before(ctx->tcg, op, INDEX_op_and_i32= , 3); + TCGArg t1 =3D arg_new_temp(ctx); + TCGArg t2 =3D arg_new_temp(ctx); + + op1->args[0] =3D t1; + op1->args[1] =3D al; + op1->args[2] =3D bl; + op2->args[0] =3D t2; + op2->args[1] =3D ah; + op2->args[2] =3D bh; + + args[0] =3D t1; + args[1] =3D t2; + args[3] =3D args[2] =3D arg_new_constant(ctx, 0); + args[4] =3D tcg_tst_eqne_cond(c); + } return -1; } =20 @@ -1298,7 +1342,7 @@ static bool fold_andc(OptContext *ctx, TCGOp *op) =20 static bool fold_brcond(OptContext *ctx, TCGOp *op) { - int i =3D do_constant_folding_cond1(ctx, NO_DEST, &op->args[0], + int i =3D do_constant_folding_cond1(ctx, op, NO_DEST, &op->args[0], &op->args[1], &op->args[2]); if (i =3D=3D 0) { tcg_op_remove(ctx->tcg, op); @@ -1317,7 +1361,7 @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) TCGArg label; int i, inv =3D 0; =20 - i =3D do_constant_folding_cond2(ctx, &op->args[0]); + i =3D do_constant_folding_cond2(ctx, op, &op->args[0]); cond =3D op->args[4]; label =3D op->args[5]; if (i >=3D 0) { @@ -1815,7 +1859,7 @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) op->args[5] =3D tcg_invert_cond(op->args[5]); } =20 - i =3D do_constant_folding_cond1(ctx, NO_DEST, &op->args[1], + i =3D do_constant_folding_cond1(ctx, op, NO_DEST, &op->args[1], &op->args[2], &op->args[5]); if (i >=3D 0) { return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]); @@ -2151,7 +2195,7 @@ static void fold_setcond_tst_pow2(OptContext *ctx, TC= GOp *op, bool neg) =20 static bool fold_setcond(OptContext *ctx, TCGOp *op) { - int i =3D do_constant_folding_cond1(ctx, op->args[0], &op->args[1], + int i =3D do_constant_folding_cond1(ctx, op, op->args[0], &op->args[1], &op->args[2], &op->args[3]); if (i >=3D 0) { return tcg_opt_gen_movi(ctx, op, op->args[0], i); @@ -2165,7 +2209,7 @@ static bool fold_setcond(OptContext *ctx, TCGOp *op) =20 static bool fold_negsetcond(OptContext *ctx, TCGOp *op) { - int i =3D do_constant_folding_cond1(ctx, op->args[0], &op->args[1], + int i =3D do_constant_folding_cond1(ctx, op, op->args[0], &op->args[1], &op->args[2], &op->args[3]); if (i >=3D 0) { return tcg_opt_gen_movi(ctx, op, op->args[0], -i); @@ -2182,7 +2226,7 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) TCGCond cond; int i, inv =3D 0; =20 - i =3D do_constant_folding_cond2(ctx, &op->args[1]); + i =3D do_constant_folding_cond2(ctx, op, &op->args[1]); cond =3D op->args[5]; if (i >=3D 0) { goto do_setcond_const; diff --git a/tcg/tcg.c b/tcg/tcg.c index 9d146b13aa..2f4522488a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1655,7 +1655,7 @@ TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_= t off, const char *name) return temp_tcgv_ptr(ts); } =20 -static TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind) +TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind) { TCGContext *s =3D tcg_ctx; TCGTemp *ts; --=20 2.34.1