From patchwork Thu Oct 26 01:39:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 738308 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp577255wrq; Wed, 25 Oct 2023 18:41:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZIn8m2bwal/goVZDOdAGw332T7EK/adHQTFgilMEfzJGDx6gZgTfJg/b+5P1Kwl02y6TJ X-Received: by 2002:a05:600c:4709:b0:408:5a1c:9de7 with SMTP id v9-20020a05600c470900b004085a1c9de7mr10740313wmo.7.1698284460534; Wed, 25 Oct 2023 18:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698284460; cv=none; d=google.com; s=arc-20160816; b=DJ0YzpfsOIGdzN1p9WmzpJc6lPsbWmRSwZLDCQAaJtCOTRckYFBUi0Llha+/Ldtd8t hJsegloW78dYK+RiSoVT2Ub7ZbSapaJDYnABPg2KZhuYFMrC7Bu8JSs2K6hXzGK90wBp S+ZytCYUG0B622bvuvbjsESfGhNrG1oXv/Rdax+SbHUnLV/sqeqp7LTN94azfnptjXpQ cV0GFruS1Xsc85wohQHuauF3/GA4BmiUDC4qUHEYSe519zASmUIWPyE8ZUe/RCMNoT13 3eUzuZ/Di+XctjH4fm7AUI6eZx33J41vCF6HQTut6k91E/Em+l+otQzAmrqT6ExnKPUV O9nw== 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=B3I9nizKVluJjWOS7Ntil0G+hzizNGtF2y9jpiXdsHc=; fh=3mEp7FusppN5Drq2PN08R8D/9xXM9YdbtG5TkJxJBiE=; b=neJMEm9kTv7AhklimY3YgJ+GlW4zhHlFb5+aseiZaplZpv9GpPAChbgllnvLmrMLF8 LcQ+xA1M9BetsIIUCRPvTQ9EtkLJtQfrXwBhH/l0PiBDJfYHtpqwJqOeH8mUFYBj/U/4 OlOaRYKynnqGSiHMV1GhIKeg79gWL6Xgv6ReKQr6qVd4zLTdP/ugLGOIqQ/1+KCu52sJ H3DkqW5DFKGmld3cOBSyI2sAsM3FFRm1NG/k1SIZFTlSNLjgs+1+IFP5eQdVyBaJSwAF fXuQ4zNarZLXPJjmu5h17UH6fPC6luCTbM+Q8eyuEzPW2g9cHKHIc44SB9TUs45+9Rvk Wk+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qoII4+rV; 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 bi15-20020a05600c3d8f00b00406517c55d9si863284wmb.123.2023.10.25.18.41.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2023 18:41:00 -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=qoII4+rV; 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 1qvpLl-0001sS-9J; Wed, 25 Oct 2023 21:39:53 -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 1qvpLi-0001rL-AP for qemu-devel@nongnu.org; Wed, 25 Oct 2023 21:39:50 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvpLg-000341-Fu for qemu-devel@nongnu.org; Wed, 25 Oct 2023 21:39:50 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c9b7c234a7so2757775ad.3 for ; Wed, 25 Oct 2023 18:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698284387; x=1698889187; 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=B3I9nizKVluJjWOS7Ntil0G+hzizNGtF2y9jpiXdsHc=; b=qoII4+rVqK83dyh3M+HfxJJ4Aolu3vz2hE2qy/CbdrVkeD+JGMHIZUhho0zMFLJnOd n6NuR0EBoSH9tIBMRMVvzOhHMpNHnw/sFftgLZUp7fd/buT6kSmf++S8jFFfN1O3+xlz mjr1gn8mYVm3PP8vG4hRwQNGtBBNdqRAxipuvkHm2MJDVjueVW6vNtrJkh2kIFEqLdhz canUzqao8/IrATkeepWlCpvgb3MdojWDs2oR4n+SJaNhIcwb5iGObDgUbz7MNwkbGagE hfvzViNBYjHHYNgStQXExpb7egCTgYkpSCwCNnVjFdb7MZVKCwUszDzma7qBGTeO2NYB eIeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698284387; x=1698889187; 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=B3I9nizKVluJjWOS7Ntil0G+hzizNGtF2y9jpiXdsHc=; b=t6xE/SKvksE3s/0p801DofGUDTsVDXnVVXT2yRLSKfN+H50GHwkFH9mG0RLP0G8osr AbMGa12MNncYH0yS0w0PKP5VqQaHHGKqap044uAnCR5Y1aUPNjRKCDRCqE49WTFNxRBX XqQy8p7KL36V/MPd6wv0jB+Kw2do586R4HxO1PFzea7NqMg57NedloyM7K+TsnRwuzNq qcfB8av9BvHQJUK69TfScAx4pGPOcDJb0MoVq/Jv7PAuL3yg/QcHgIW/FFILmY8dsC6M bMJVAnxO2/MvgN39KVda/HdZUN1M2ZzZGqvm0M6fUFU86H5qzgAp7lG9U6xyUK+e7yIz ppZQ== X-Gm-Message-State: AOJu0YzOdtvdaowiZ/o9TzrO3Cww/HM427Pp1KnPXjXEmsbAVlCjiRVq +iKP40FOQJzvK5b3wczzriGcEUi4cEd8pyCNspE= X-Received: by 2002:a17:902:d4cf:b0:1c5:ec97:1718 with SMTP id o15-20020a170902d4cf00b001c5ec971718mr18926174plg.6.1698284387204; Wed, 25 Oct 2023 18:39:47 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id y6-20020a170902864600b001c0c86a5415sm9817032plt.154.2023.10.25.18.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 18:39:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 1/4] tcg: Canonicalize subi to addi during opcode generation Date: Wed, 25 Oct 2023 18:39:42 -0700 Message-Id: <20231026013945.1152174-2-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::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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 Suggested-by: Paolo Bonzini Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/tcg-op.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 59deb3cbbb..3fce9bd8f4 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -147,12 +147,7 @@ void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2) void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2) { - /* some cases can be optimized here */ - if (arg2 == 0) { - tcg_gen_mov_i32(ret, arg1); - } else { - tcg_gen_sub_i32(ret, arg1, tcg_constant_i32(arg2)); - } + tcg_gen_addi_i32(ret, arg1, -arg2); } void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2) @@ -1258,6 +1253,13 @@ void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) { + TCGTemp *ts2 = tcgv_i64_temp(arg2); + + /* Canonicalize subi into addi. */ + if (ts2->kind == TEMP_CONST) { + tcg_gen_addi_i64(ret, arg1, -ts2->val); + return; + } tcg_gen_sub2_i32(TCGV_LOW(ret), TCGV_HIGH(ret), TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2), TCGV_HIGH(arg2)); } @@ -1354,16 +1356,7 @@ void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2) void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2) { - /* some cases can be optimized here */ - if (arg2 == 0) { - tcg_gen_mov_i64(ret, arg1); - } else if (TCG_TARGET_REG_BITS == 64) { - tcg_gen_sub_i64(ret, arg1, tcg_constant_i64(arg2)); - } else { - tcg_gen_sub2_i32(TCGV_LOW(ret), TCGV_HIGH(ret), - TCGV_LOW(arg1), TCGV_HIGH(arg1), - tcg_constant_i32(arg2), tcg_constant_i32(arg2 >> 32)); - } + tcg_gen_addi_i64(ret, arg1, -arg2); } void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2) 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) 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; } From patchwork Thu Oct 26 01:39:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 738307 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp577144wrq; Wed, 25 Oct 2023 18:40:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMU4kITvAxLVA44EEqueJUJ+E7RxB+280OPZam+QpYH6aArMqS3FhpZl4EaCtWnP7tssXe X-Received: by 2002:a5d:548c:0:b0:32d:9395:dec2 with SMTP id h12-20020a5d548c000000b0032d9395dec2mr11975708wrv.71.1698284432324; 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=TVBtb7OWM4EIge4wrpmcrgpyyPmLkUhEknS8Yjyfl8tSuSHTrEIkOwNtXy2ugLT+Km xkh3Ra/YXhPElwV/owGiZxC5iUJOQOQ9KJJCYfED0YpuwDLOsbBwFOFFFKeOirN17B2Z /MpfeX7dfsbvTyxCKXTpNKvbTpwXZvG6Ng/zrMYVj4WMIWVR3v9O7axMUdwQbmXkqAEq 8erk+LQz9vp5y4zF/UJWyeaItbrfl5UpUd8k7UfuqlVgqlmEz0df5RKGZSVocaCGU19z LnZ/s2m3SX/+7dFLjq1Bbtkgbi7xHCEdJ1gNZBL8hPOnZYXjXxCgVOBf5Z/KBvksPEKk ZX1Q== 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=FoKclLNER0V8XEHrKIXGl1qWfltrfJBKVAYf+F60a9E=; fh=3mEp7FusppN5Drq2PN08R8D/9xXM9YdbtG5TkJxJBiE=; b=TqG9JTYh9jmyQHy9ZIcRfCMQEXQ4Z6iYrxWYcJIB118Y2UyCqQm2+LWTA/eDllyrhn AMTAZdZ+qiJJFNauuviq1pzrXqhtU884FJwWXrpVhpKfe+XM6ej6wK+AJ9rMgEZB0x0W M9TLySD9CABYWCFkCG3KRXbYHLocaNYcl3OurCwNR50p5CXOZe6EfGH0/GNsFfqAO/Nj fIX3AVhW+ENqHcqb9kFU+B2dzQo0GKgZwLRZvCecgnwM8+m63lN2YvqLH1SpWblxpwt/ Fg9K3oz/rf9KUu3wwZJAmJpC4Vov+6JvtrDA7+71xPGr1XQfI3FEez44X+Q2UI/eg10V 2WAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jm8ziepP; 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 j11-20020adff00b000000b0031fecade57dsi8308100wro.1051.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=Jm8ziepP; 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 1qvpLn-0001us-RU; Wed, 25 Oct 2023 21:39:56 -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 1qvpLm-0001u2-2u for qemu-devel@nongnu.org; Wed, 25 Oct 2023 21:39:54 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvpLj-00034O-8f for qemu-devel@nongnu.org; Wed, 25 Oct 2023 21:39:53 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1ca3a54d2c4so2743155ad.3 for ; Wed, 25 Oct 2023 18:39:50 -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=FoKclLNER0V8XEHrKIXGl1qWfltrfJBKVAYf+F60a9E=; b=Jm8ziepP689N0M/Uwee1IybdKnGvVAepVoevyZa9nBWWNZMSvJjVNNV0HWY+6Q5iT7 zqMzcWuhJnzHhHQBDBB3YLh9AO8HlOJ22Xj5hwWKOTjrLHwro4qV8mX9k4uVanwa7PZg aM/WqHrsOAWOeoJ+EIwCIW65v8bhxmyah7fyM89w5IDf3g5NmJ6+rY56n5m8Lz6T5Kpv MhYf3TNiCdt5mCDLJAL7FspiQ1tGErGAcxdWPygR7P+z1oqvKo8yAqsFN63CyrsibZ14 KKkaaWXGhkbbQC+ckYm3HW6XNCly/xhwEUeC7GQOOnfUWEWXUdjJ6hmjIDPXz+eT1Ln3 C1Iw== 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=FoKclLNER0V8XEHrKIXGl1qWfltrfJBKVAYf+F60a9E=; b=DSCR/quWBBuBCrszoFgJ7AGLGbnmf3I1XqvhHnGgiXFxTf/S2Y3rYkdrdDDEp3AK9G Cs90M3BjpcKRu4joIi8P0cyoDaWmeliXeADyGDu4x0Rio5NxpNGBR3jvYff7TuHXqlVD L4TDjat1nu+RvRdNlB5Ri4g3LzW5xL8yA1IuTXsfkU9TLfGRhJYDbE6gS6NrLuKnbExR wpWsiY8pRzjlofY6aBUkQxmWSLrViCSJmfkRGD20NicgnDa/F1X7mOBhHjCNzV7EJ7s/ +5691TP7NuOGEWyCOCU4iTxWojri4S9/U7M1PWVlj/A7JU26/rRdwGSMA2Kp9Q8V5wL1 iHrQ== X-Gm-Message-State: AOJu0YzIR7zwP549qZszvkyu7EZD3bj9iDKD71AYX3IT5cFouHoxUicE woAwZDH48+4DKV+xT75Ev3DNCPlUIlNN5KIgdvU= X-Received: by 2002:a17:902:edc2:b0:1c6:2d13:5b77 with SMTP id q2-20020a170902edc200b001c62d135b77mr16245109plk.39.1698284389657; Wed, 25 Oct 2023 18:39:49 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id y6-20020a170902864600b001c0c86a5415sm9817032plt.154.2023.10.25.18.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 18:39:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 4/4] NOTFORMERGE tcg/i386: Assert sub of immediate has been folded Date: Wed, 25 Oct 2023 18:39:45 -0700 Message-Id: <20231026013945.1152174-5-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::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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 A release build should simply accept and emit the subtract. I'm not even sure if this is reasonable to keep for debug. Not-Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/tcg.c | 49 ++++++++++++++++++++++++++------------- tcg/i386/tcg-target.c.inc | 13 ++++++++--- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index a507c111cf..408647af7e 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3618,23 +3618,40 @@ liveness_pass_1(TCGContext *s) do_addsub2: nb_iargs = 4; nb_oargs = 2; - /* Test if the high part of the operation is dead, but not - the low part. The result can be optimized to a simple - add or sub. This happens often for x86_64 guest when the - cpu mode is set to 32 bit. */ - if (arg_temp(op->args[1])->state == TS_DEAD) { - if (arg_temp(op->args[0])->state == TS_DEAD) { - goto do_remove; - } - /* Replace the opcode and adjust the args in place, - leaving 3 unused args at the end. */ - op->opc = opc = opc_new; - op->args[1] = op->args[2]; - op->args[2] = op->args[4]; - /* Fall through and mark the single-word operation live. */ - nb_iargs = 2; - nb_oargs = 1; + /* + * Test if the high part of the operation is dead, but the low + * part is still live. The result can be optimized to a simple + * add or sub. + */ + if (arg_temp(op->args[1])->state != TS_DEAD) { + goto do_not_remove; } + if (arg_temp(op->args[0])->state == TS_DEAD) { + goto do_remove; + } + /* + * Replace the opcode and adjust the args in place, leaving 3 + * unused args at the end. Canonicalize subi to andi. + */ + op->args[1] = op->args[2]; + { + TCGTemp *src2 = arg_temp(op->args[4]); + if (src2->kind == TEMP_CONST) { + if (opc_new == INDEX_op_sub_i32) { + src2 = tcg_constant_internal(TCG_TYPE_I32, + (int32_t)-src2->val); + opc_new = INDEX_op_add_i32; + } else if (opc_new == INDEX_op_sub_i64) { + src2 = tcg_constant_internal(TCG_TYPE_I64, -src2->val); + opc_new = INDEX_op_add_i64; + } + } + op->args[2] = temp_arg(src2); + } + op->opc = opc = opc_new; + /* Mark the single-word operation live. */ + nb_iargs = 2; + nb_oargs = 1; goto do_not_remove; case INDEX_op_mulu2_i32: diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index 0d97864174..39d03fa698 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -2544,8 +2544,14 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, c = ARITH_ADD; goto gen_arith; OP_32_64(sub): - c = ARITH_SUB; - goto gen_arith; + /* + * Should have canonicalized all constants to add. + * Keep the constraint allowing any constant so that we catch this + * case without register allocation loading the constant first. + */ + tcg_debug_assert(!const_a2); + tgen_arithr(s, ARITH_SUB + rexw, a0, a2); + break; OP_32_64(and): c = ARITH_AND; goto gen_arith; @@ -3325,7 +3331,6 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) return C_O1_I2(r, r, re); case INDEX_op_sub_i32: - case INDEX_op_sub_i64: case INDEX_op_mul_i32: case INDEX_op_mul_i64: case INDEX_op_or_i32: @@ -3333,6 +3338,8 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_xor_i32: case INDEX_op_xor_i64: return C_O1_I2(r, 0, re); + case INDEX_op_sub_i64: + return C_O1_I2(r, 0, ri); case INDEX_op_and_i32: case INDEX_op_and_i64: