From patchwork Thu Oct 26 01:39:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 738306 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp577145wrq; Wed, 25 Oct 2023 18:40:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyDrRplmRD/TWgGA2eDQp9BAzuJYP1yuLXMhUnI4vbfXsEAAkX9xGcD//8ROTF3UZGFoE5 X-Received: by 2002:a05:620a:1a09:b0:76f:44c:5cd0 with SMTP id bk9-20020a05620a1a0900b0076f044c5cd0mr19766457qkb.48.1698284432295; Wed, 25 Oct 2023 18:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698284432; cv=none; d=google.com; s=arc-20160816; b=BgzmaR4o2zb6EjKean/NnJMDqwQeMtzEAVh0sLsJ5b3fT7czEjpmKi6QIeradPYwNi RFeKwlCoQzNoJAuqbQakwpGhKlpJmD67bDeke6uP8Qki+sZjdFXkpxfDZhyVrnytbirR wOsOiKVEVzb/mxgo9SuwuNOLNG4MiZgYqKFao1A0YQNPw8/igJ2tRmkx25N2XBizA7JK rOM/BM6qj3jpJHMVCGQSkQ7PskDZ470GWR6vGFxEqOIJ/iTa5K007FV+9CbW2qeXXg1b PmQRI+ufe188nwEXTdnXnJHlC3hVlaGpJ1vUKSR/Kd9OdeJ+x5ks/ejVj0rybGXhAzyR V6RQ== 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=xK+JWgkPgdP/B/2EKpKortnxne1iWP7pZx29ZgBu6Lk=; fh=3mEp7FusppN5Drq2PN08R8D/9xXM9YdbtG5TkJxJBiE=; b=rfY3j4Nhx+Yh8ZQKHgb4bsm2eHi/8zrQ3a7WnXnUosqj9Upfp6uOTWSqrEVHI7Lxr9 sxkN5uFCku+gDQr5xTmhGc2gx/Rhj3qi1OgzoOxPppT/iXcxUGJwxO4xvmk36SXvYt6H W7sR7FL7lx7Z5ce8yjgpI4wTYXwf1dgVJT8PhrxLFfmOEQLPO9LgipFl5r9+u8VaEhuC I9WGl/hw0+X0sracTTYuhSipsVmXkXgT1c27RBn4TPMuHxo5fFwJVzVFqsVW0b81IepR BsFP3XOOnE+uD+lWJUCq0Ixaf/tR174ATCtvhrBywKtUkIhAMTDYpYcUTE2ifQfn8jPe r8Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NzlRk95g; 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 qc12-20020a05620a654c00b007759f944c0fsi258848qkn.156.2023.10.25.18.40.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2023 18:40:32 -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=NzlRk95g; 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 1qvpLm-0001uj-VK; Wed, 25 Oct 2023 21:39:54 -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 1qvpLj-0001sM-UP for qemu-devel@nongnu.org; Wed, 25 Oct 2023 21:39:51 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvpLi-00034C-FD for qemu-devel@nongnu.org; Wed, 25 Oct 2023 21:39:51 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c9c5a1b87bso2394545ad.3 for ; Wed, 25 Oct 2023 18:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698284389; x=1698889189; 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=xK+JWgkPgdP/B/2EKpKortnxne1iWP7pZx29ZgBu6Lk=; b=NzlRk95gey5uqnF1AOUQ8ifpwdwnyzfGiNEs21RRPeZihq6u5/g1tImc7M4xsJJS/f CW3cJ+O1lrWFK3nsu4mpedd3RX/Q431SKQ2YcQA/ylWrU6ds6TeQTkNSRQn3oe+nQKuW qLfwlzxFKNz11MTE3ErKO4KTMwuhdUznHiXXvAtF1FnXRuyk5pJM+OvsucTFpTilsrIm ZKhCpu1dqlYrXD8I9TnmXM4lMxDxkCqAUz3ITLIaMWuhyqPDnV0y5X4asfuKf8vUgoLy GA08Pe4xx7a0pA/AKRsV7CH5ZbsYwbIu45HBxkQS8tUxpIi+QzcAfPMK8hfLUaX2TsqX HeQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698284389; x=1698889189; 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=xK+JWgkPgdP/B/2EKpKortnxne1iWP7pZx29ZgBu6Lk=; b=qRsT+EACeIrYPSxzntiruhDFXh8YJ46w1qyQ7saezUx0Kpqpp2dLM+rijNywiXTrNq ux6wtdwUGFWChcHg3IJrldfPSTNe+2PGqgi0k6cDoujTyhjbdODfgRaEg8Eqy7Qnuv+w L9ylX5pOqL4tHHtYUIzK1Wzz9LxE8dWGU07JT0Swzc/XAT4IcTfgopIxdvgsglflUOOq S0yv/4YCtUsvdKltthphXg1OOqaPVQeIpBSi7EfbCp2pP9fRlQVacAs8/sHFtMpZyC8i Ic38PMU3k8z9YszH+opErOKHl15951lcuMOO6NiUAcjaIjgGYDAj7Gqown/6HfGYNOCt 4Ehg== X-Gm-Message-State: AOJu0YwIDKBzl4I99Vh9nqGuV5tk6ApbXZzw3ij5bEoJHlhkC6JOvzAI jtc1Du+rXttPoPg6/jTacKHxiL7CchFFUvWYiKI= X-Received: by 2002:a17:902:d4c6:b0:1ca:15ad:1c6 with SMTP id o6-20020a170902d4c600b001ca15ad01c6mr15791608plg.33.1698284388962; Wed, 25 Oct 2023 18:39:48 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id y6-20020a170902864600b001c0c86a5415sm9817032plt.154.2023.10.25.18.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 18:39:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 3/4] tcg/optimize: Canonicalize sub2 with constants to add2 Date: Wed, 25 Oct 2023 18:39:44 -0700 Message-Id: <20231026013945.1152174-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026013945.1152174-1-richard.henderson@linaro.org> References: <20231026013945.1152174-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.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 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/optimize.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 9d91c25f68..280e6089a6 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -1030,8 +1030,10 @@ static bool fold_add_vec(OptContext *ctx, TCGOp *op) static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) { - if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) && - arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { + bool a_const = arg_is_const(op->args[2]) && arg_is_const(op->args[3]); + bool b_const = arg_is_const(op->args[4]) && arg_is_const(op->args[5]); + + if (a_const && b_const) { uint64_t al = arg_info(op->args[2])->val; uint64_t ah = arg_info(op->args[3])->val; uint64_t bl = arg_info(op->args[4])->val; @@ -1075,6 +1077,21 @@ static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) tcg_opt_gen_movi(ctx, op2, rh, ah); return true; } + + /* Fold sub2 r,x,i to add2 r,x,-i */ + if (!add && b_const) { + uint64_t bl = arg_info(op->args[4])->val; + uint64_t bh = arg_info(op->args[5])->val; + + /* Negate the two parts without assembling and disassembling. */ + bl = -bl; + bh = ~bh + !bl; + + op->opc = (ctx->type == TCG_TYPE_I32 + ? INDEX_op_add2_i32 : INDEX_op_add2_i64); + op->args[4] = arg_new_constant(ctx, bl); + op->args[5] = arg_new_constant(ctx, bh); + } return false; }