From patchwork Thu Oct 26 01:39:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 738305 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp577119wrq; Wed, 25 Oct 2023 18:40:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeMT7/KZnjEcCqMu2oJr2QlYy+eIKVpuYlfu8n90DakMFiMoXmyqv6GwyTv3SVVf6LUj3g X-Received: by 2002:a5d:4043:0:b0:314:1313:c3d6 with SMTP id w3-20020a5d4043000000b003141313c3d6mr9874946wrp.33.1698284427681; Wed, 25 Oct 2023 18:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698284427; cv=none; d=google.com; s=arc-20160816; b=joCZ0teVye/p0XsHBm0x3RbJQFUEB9XcQfAG5bpQE7VasOrA0hS236lL0rho1YZlIQ DyMvucFeV1/2MqBTmPUPAUcO+ADXgRGXjY+i5yLBpIjzGcpONw9qN7326lFDcWmWUCPH la+S2LyX3W6M6psqjYgJdqmrKCGfAE2EFSdRw+RRe9z7NFdEHIVCnOOBQtzPLBhdScYC nKY76py1ybNKbqtxwRCIxgwN3wGbHxbbmfnc96EcxuZclqvpBrtyaYlIH32qLwFSGPeV vJckcyYQuFmpop4D33A87BUQOpMBrv7oACKtemYdgKEr4fmIwdkBNVEVe8Xylt7Y9Dht XGFg== 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=IT+iq26XpeNaP4p8agkQswthWt+k2V7nM8eUPcDBar8=; fh=3mEp7FusppN5Drq2PN08R8D/9xXM9YdbtG5TkJxJBiE=; b=1In54Lv7ztwNMWeLIAc1Wbsd67VP2eMtsAPC5JTSYVO299nhZ74tpj3duv+/ftlaCN H+bnQb9z7UriyJGKf24tLinXbVsuTn0fTdwRKHqPIaHeGH8+My9WGhALG9Bd4FOaaoWH e6M8waa6Y+sjqNurjAvGK/0HYj2qTm7MgjcDHhAYmWuWjK1aS1aUGv94mVSv/28TLVKd 4bnGoevLJDzn5vCeeWDRT5GJGyATAUM2UZk+EfquemDo7X6lkBh2tVxv5VByo1cz87VK GJPm3V6wFov2jXfDzlERSlG6/G5BH8f1OHQvfiCXLmJsWXaBGsGf+1XZkqOEDYaNC9Vd glUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="l/3NxxcX"; 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 d4-20020a5d4f84000000b0032da4763a5dsi8251653wru.754.2023.10.25.18.40.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2023 18:40:27 -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="l/3NxxcX"; 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 1qvpLk-0001sl-Og; Wed, 25 Oct 2023 21:39:52 -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-0001rh-Ef 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 1qvpLh-000348-Le for qemu-devel@nongnu.org; Wed, 25 Oct 2023 21:39:51 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ca215cc713so2413345ad.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=1698284388; x=1698889188; 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=IT+iq26XpeNaP4p8agkQswthWt+k2V7nM8eUPcDBar8=; b=l/3NxxcXjr8ZuVdTRjiRuhrNC5nDjcOePV2+lHRYqLNFSWzhRgKJboNbMwv2os4Eff UM/X2JPeFsvCJs+k8XUQ4tk/UoMm7Q0S35dVvtUarHDPxSux4riuwgOO5owAmC1OMe2h ewMiZ+ai1tTSkpOgqCrWytQehS61vfZZAl3iIYnJVtEQIBsJA0pBb5ZPZdZqkJV8MNnQ hmEhUB9scSRggJB1rXsWF2mTjuNFiiwYj6It7FSXkxvgI0Qn+P9dm0sNkgOwYweZrc4J 7DMshuHW+gGEuFpVcd0rIgV1ZM2grGYYWD/QFoz8C6YxKuB3ij0eeB9q3OnkWkEZZd7E cnoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698284388; x=1698889188; 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=IT+iq26XpeNaP4p8agkQswthWt+k2V7nM8eUPcDBar8=; b=cu5mzUJu+jqVD/NyXJFvtgpXJ9Yl+vcE4/fLSwyZiKj0+PoTVqEl51VCFsRMyorbCg keszT//nMFb8v8kcZX3pNLT1cXu6poL8dyRn7Am7AKSWqaUI2ZW7qYmOVgPCNE/iDCee F2JNU88o6aLXPNko0sUVmOEUxLmnN6ZeZxnm0xpjiwWetS5K5lV2IbuyzM+TnIRMO/cv QbObqUMeOGtRihQz7kkdxzFH9rtPIlKqLTkPjU97LPr04pKHE7m2cZUfQe+L+reBRO+C q3az8GXCeEiSvR9rFnYg/AMrTgTWgJEtYETaKhn6PAIZnPYgAYt8o4xkxcEJUX+KzD7h Bjig== X-Gm-Message-State: AOJu0YyV4QFRXam3fkiW6TmuwtMMJi2t+yrxU1g7n8/hpoIj6jYZlFeD inEgorpmgf08f9qIE6XYeUsf6x7uoeaZqUdEwKg= X-Received: by 2002:a17:902:ca14:b0:1ca:8629:829b with SMTP id w20-20020a170902ca1400b001ca8629829bmr12274464pld.50.1698284388020; 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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 18:39:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 2/4] tcg/optimize: Canonicalize subi to addi during optimization Date: Wed, 25 Oct 2023 18:39:43 -0700 Message-Id: <20231026013945.1152174-3-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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 5e16800cfa..9d91c25f68 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -2237,7 +2237,19 @@ static bool fold_sub_vec(OptContext *ctx, TCGOp *op) static bool fold_sub(OptContext *ctx, TCGOp *op) { - return fold_const2(ctx, op) || fold_sub_vec(ctx, op); + if (fold_const2(ctx, op) || fold_sub_vec(ctx, op)) { + return true; + } + + /* Fold sub r,x,i to add r,x,-i */ + if (arg_is_const(op->args[2])) { + uint64_t val = arg_info(op->args[2])->val; + + op->opc = (ctx->type == TCG_TYPE_I32 + ? INDEX_op_add_i32 : INDEX_op_add_i64); + op->args[2] = arg_new_constant(ctx, -val); + } + return false; } static bool fold_sub2(OptContext *ctx, TCGOp *op)