From patchwork Thu Aug 31 02:57:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718942 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp241318wrn; Wed, 30 Aug 2023 19:58:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhwvN5uzSS+t8J8diVu+hhYl03iZg3o1BADXG/WIexITeLYuIeF5AdqB088qO+rqz6e7n9 X-Received: by 2002:a05:622a:199f:b0:410:a895:21fd with SMTP id u31-20020a05622a199f00b00410a89521fdmr1910785qtc.23.1693450717604; Wed, 30 Aug 2023 19:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693450717; cv=none; d=google.com; s=arc-20160816; b=jqFLFfV4MF8UyYvBNq12Ptf5pXiKyCc/FZmNSYW4V388Hq579Qsc8aJ3tVfDPxUJpy DJOKDIIyss0sx3aB0Nlze7gaxs7gAEXk7BZVa+7AJoFtDYsI7JdAZyLBAYNb3uwR2Phw dlt+sJOEcDDn5aSeHYoZMxQyokji9wRQMHI7LbRDmblXqxMnD18fzgkTMzg1n9144+Yq B3RIxw0yGStdCp2wX5wadLjn/jfYqiqZ9REGfEB//uCnEm4HOrpFiJxDZyv3nJwz3kGk OhgRGrFPfzHZgl9qnAUl1QQNOGNfh8woMazxIa8jfmCNLsZsBsYQfvVSDIEn09GAdCTv pssg== 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:to:from :dkim-signature; bh=xmYRGdMxU32xHJwVCt1KMNjds4d5uoJumow+DOzr+1w=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=jokR2KapYbtjBj6vlkHuG5wk0I7mA3vxBTCJm8BdpnAmcsRQtDG4Q6EU5K8tx0Lpic vO1szN2Zmo+ou8BUQvI4YXBCzLOTxDMAo2jRAEg/D3T2eWgGURcBiHJ2MUCfR3kWAJ/E R4MRhY0H7YxkqBFJRg4wAHPNi3xfVvk+YYJ3fe/J63SD7W2EiZeVKYGMwi7N/5aWcmF8 WaJznrt5RBP99J+w5ngU6jTP5BDjcX8d0h2gwb/bjkvafxdJvdvuiR3z+azZHIAFRTvp 0Cg6j8lDpbAuPpOPlE4xSSWlLyk68LszThYMWLVRDrbn+SgxRGfsJUtzoX1BHsQxgEBt s+zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="EFWL/QcN"; 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 p6-20020a05622a048600b00403fbb9a8a5si272923qtx.269.2023.08.30.19.58.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Aug 2023 19:58:37 -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="EFWL/QcN"; 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 1qbXsG-0004sP-SW; Wed, 30 Aug 2023 22:57:36 -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 1qbXsG-0004s1-28 for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:36 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbXsD-0007oI-LH for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:35 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bf11b1c7d0so10588475ad.0 for ; Wed, 30 Aug 2023 19:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693450652; x=1694055452; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xmYRGdMxU32xHJwVCt1KMNjds4d5uoJumow+DOzr+1w=; b=EFWL/QcNs37Y7Fp1V5RavE1qTMXs37gNRePL4bxW6g2d9/ewsGeom+uv8Wlgz6RXBA j0gbHC6sng67RWB1pE43aXC9FYYU6v+opYKWrTxJBRtcOz0TOGRoupeRvED6tpPwcx+7 nhEh53FWWCME+X520HCUoxTVyWVDlJqvz9PuAt7PNUjTykSjoCkKA6hRCAHGKTjjPIeJ uk5k1vPSPEccGsWb4hbLtgGvPyBmfeklBND2OuMgWYPU7LWbwybgWTFtKGVKgiHniK+p /8Yq7ZIMu1ejUBjQ/LtOwaSfpy89KmXeXHiVShCF8XbI/9CkApwKeX1IWXGPMsTyuLgo +CrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693450652; x=1694055452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xmYRGdMxU32xHJwVCt1KMNjds4d5uoJumow+DOzr+1w=; b=M2Q0XUgwGfpEogni4WNhoXvHnDungMC3B/Sz9DUzukKgiAiZfNpHv62WKoV1+nlurP mP8vz0h52ULE7Ri7YMD5FnVnQfu/Kbirt7uqEvR6/QPazI/nlObgiA/hVRh8MeO32VcX YHM86y2EkvJUGDQd336N6v9ycCtVPpC8j47fd0vZrwHRTxU5hUI8aBymrbLqwyQj8Sd5 OmuT3Pgr2iP2J7W5zgx1X8ojtuVGTXQ2fDskfEcYe8yKeO3z/JTeV/cX0OVtuUqDpRRh YLlERyOeR6UltRc6xdNo5JcgvAci4eABhDNdkpEt54i86ipejXZRryOp40zOYyBkdBzg FZ4A== X-Gm-Message-State: AOJu0YzOyAKZfbpRDx9l2xL44KYpnpOhK1cr3wllpJbZVGcwhDrF7vhK JjXN6kVh51+P2hqug+XxOTIcNxchu5CtNEoD88s= X-Received: by 2002:a17:90b:91:b0:26d:5c07:ae3e with SMTP id bb17-20020a17090b009100b0026d5c07ae3emr2079071pjb.4.1693450652232; Wed, 30 Aug 2023 19:57:32 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id dw24-20020a17090b095800b00265c742a262sm288142pjb.4.2023.08.30.19.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 19:57:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/4] tcg: Don't free vector results Date: Wed, 30 Aug 2023 19:57:26 -0700 Message-Id: <20230831025729.1194388-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831025729.1194388-1-richard.henderson@linaro.org> References: <20230831025729.1194388-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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 Avoid reusing vector temporaries so that we may re-use them when propagating stores to loads. Signed-off-by: Richard Henderson --- tcg/tcg-op-gvec.c | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c index e260a07c61..f5cfd9bf99 100644 --- a/tcg/tcg-op-gvec.c +++ b/tcg/tcg-op-gvec.c @@ -561,7 +561,6 @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz, tcg_gen_dupi_vec(vece, t_vec, in_c); } do_dup_store(type, dofs, oprsz, maxsz, t_vec); - tcg_temp_free_vec(t_vec); return; } @@ -1036,8 +1035,6 @@ static void expand_2_vec(unsigned vece, uint32_t dofs, uint32_t aofs, fni(vece, t1, t0); tcg_gen_st_vec(t1, cpu_env, dofs + i); } - tcg_temp_free_vec(t0); - tcg_temp_free_vec(t1); } /* Expand OPSZ bytes worth of two-vector operands and an immediate operand @@ -1059,8 +1056,6 @@ static void expand_2i_vec(unsigned vece, uint32_t dofs, uint32_t aofs, fni(vece, t1, t0, c); tcg_gen_st_vec(t1, cpu_env, dofs + i); } - tcg_temp_free_vec(t0); - tcg_temp_free_vec(t1); } static void expand_2s_vec(unsigned vece, uint32_t dofs, uint32_t aofs, @@ -1081,8 +1076,6 @@ static void expand_2s_vec(unsigned vece, uint32_t dofs, uint32_t aofs, } tcg_gen_st_vec(t1, cpu_env, dofs + i); } - tcg_temp_free_vec(t0); - tcg_temp_free_vec(t1); } /* Expand OPSZ bytes worth of three-operand operations using host vectors. */ @@ -1105,9 +1098,6 @@ static void expand_3_vec(unsigned vece, uint32_t dofs, uint32_t aofs, fni(vece, t2, t0, t1); tcg_gen_st_vec(t2, cpu_env, dofs + i); } - tcg_temp_free_vec(t2); - tcg_temp_free_vec(t1); - tcg_temp_free_vec(t0); } /* @@ -1134,9 +1124,6 @@ static void expand_3i_vec(unsigned vece, uint32_t dofs, uint32_t aofs, fni(vece, t2, t0, t1, c); tcg_gen_st_vec(t2, cpu_env, dofs + i); } - tcg_temp_free_vec(t0); - tcg_temp_free_vec(t1); - tcg_temp_free_vec(t2); } /* Expand OPSZ bytes worth of four-operand operations using host vectors. */ @@ -1162,10 +1149,6 @@ static void expand_4_vec(unsigned vece, uint32_t dofs, uint32_t aofs, tcg_gen_st_vec(t1, cpu_env, aofs + i); } } - tcg_temp_free_vec(t3); - tcg_temp_free_vec(t2); - tcg_temp_free_vec(t1); - tcg_temp_free_vec(t0); } /* @@ -1191,10 +1174,6 @@ static void expand_4i_vec(unsigned vece, uint32_t dofs, uint32_t aofs, fni(vece, t0, t1, t2, t3, c); tcg_gen_st_vec(t0, cpu_env, dofs + i); } - tcg_temp_free_vec(t3); - tcg_temp_free_vec(t2); - tcg_temp_free_vec(t1); - tcg_temp_free_vec(t0); } /* Expand a vector two-operand operation. */ @@ -1732,7 +1711,6 @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, TCGv_vec t_vec = tcg_temp_new_vec(type); tcg_gen_dup_mem_vec(vece, t_vec, cpu_env, aofs); do_dup_store(type, dofs, oprsz, maxsz, t_vec); - tcg_temp_free_vec(t_vec); } else if (vece <= MO_32) { TCGv_i32 in = tcg_temp_ebb_new_i32(); switch (vece) { @@ -1766,7 +1744,6 @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, for (i = (aofs == dofs) * 16; i < oprsz; i += 16) { tcg_gen_st_vec(in, cpu_env, dofs + i); } - tcg_temp_free_vec(in); } else { TCGv_i64 in0 = tcg_temp_ebb_new_i64(); TCGv_i64 in1 = tcg_temp_ebb_new_i64(); @@ -1796,7 +1773,6 @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, for (i = (aofs == dofs) * 32; i < oprsz; i += 32) { tcg_gen_st_vec(in, cpu_env, dofs + i); } - tcg_temp_free_vec(in); } else if (TCG_TARGET_HAS_v128) { TCGv_vec in0 = tcg_temp_new_vec(TCG_TYPE_V128); TCGv_vec in1 = tcg_temp_new_vec(TCG_TYPE_V128); @@ -1807,8 +1783,6 @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, tcg_gen_st_vec(in0, cpu_env, dofs + i); tcg_gen_st_vec(in1, cpu_env, dofs + i + 16); } - tcg_temp_free_vec(in0); - tcg_temp_free_vec(in1); } else { TCGv_i64 in[4]; int j; @@ -3137,14 +3111,14 @@ static void expand_2sh_vec(unsigned vece, uint32_t dofs, uint32_t aofs, void (*fni)(unsigned, TCGv_vec, TCGv_vec, TCGv_i32)) { TCGv_vec t0 = tcg_temp_new_vec(type); + TCGv_vec t1 = tcg_temp_new_vec(type); uint32_t i; for (i = 0; i < oprsz; i += tysz) { tcg_gen_ld_vec(t0, cpu_env, aofs + i); - fni(vece, t0, t0, shift); - tcg_gen_st_vec(t0, cpu_env, dofs + i); + fni(vece, t1, t0, shift); + tcg_gen_st_vec(t1, cpu_env, dofs + i); } - tcg_temp_free_vec(t0); } static void @@ -3722,16 +3696,15 @@ static void expand_cmp_vec(unsigned vece, uint32_t dofs, uint32_t aofs, { TCGv_vec t0 = tcg_temp_new_vec(type); TCGv_vec t1 = tcg_temp_new_vec(type); + TCGv_vec t2 = tcg_temp_new_vec(type); uint32_t i; for (i = 0; i < oprsz; i += tysz) { tcg_gen_ld_vec(t0, cpu_env, aofs + i); tcg_gen_ld_vec(t1, cpu_env, bofs + i); - tcg_gen_cmp_vec(cond, vece, t0, t0, t1); - tcg_gen_st_vec(t0, cpu_env, dofs + i); + tcg_gen_cmp_vec(cond, vece, t2, t0, t1); + tcg_gen_st_vec(t2, cpu_env, dofs + i); } - tcg_temp_free_vec(t1); - tcg_temp_free_vec(t0); } void tcg_gen_gvec_cmp(TCGCond cond, unsigned vece, uint32_t dofs, From patchwork Thu Aug 31 02:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718940 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp241311wrn; Wed, 30 Aug 2023 19:58:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuenfpikj2x/JgmdRC2/Ay8N6+XAyIDQBRVYzfFP7Y5jQY/NAhMrZTHbCyj/0NIgV4xE3L X-Received: by 2002:a05:620a:288b:b0:767:954:a752 with SMTP id j11-20020a05620a288b00b007670954a752mr1590381qkp.73.1693450715208; Wed, 30 Aug 2023 19:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693450715; cv=none; d=google.com; s=arc-20160816; b=j7pFFuB/6lST4C5nikBE3443nzVwfkEniIXcaDIev0a/Izu0c0oqQOZwg3iOwebaHx 8DkWjnb9kdM3oEhGmmSEICefY9u7BYxrxwLz4EpEBLSKpkU6waoJ1dzE/VIS8w4wInSx Jmg68hBET1jVsXRB8t7+GCsFR6KD1tJjunwzQZrm14uCBG7gzA9xJ5mBEATN7hI6ThYD HXf2vEkjqNBaokc+tkAk7oNFUHRg0MHz+mYnNrm0Zg/6jCy98Lkau3NiSpD+4HocjzOq SlNkwosLeUnXMUzyefDMkwgPJb6QrRmkuIMFyCxR9CH5vMJQCzQ57Dza8bjiNd/wVEIt UvBg== 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:to:from :dkim-signature; bh=35LeKOF1XNerGikRaTSmAIP+dLZWVrcFdHv/rNI8hAg=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=Cyc3rxqYbRa949tOT6B3GLAw/3Q0vmnVmatSf83XE2KsDmJdRP2MNB8ZUuOxduxjnb HY9LE12AE4Mxlq7HjhCXtyEIJ1zlWd+80XK0HBDmFLuH/UVTeY0U33YSOwiCbULY4DxL Q7a7pTosKTLIlftGOjoUxfEoS/4jO2aMHmEOAPZUHKr8QBragZ03j543Ymppo4Eup7pz Fd1aQ5ry8Q1DrYbLm5a6kM8F2he/o64Z4cGFqqOzI06HVLLT5QFvG2s7ByEb2TX8AdLU aJj5cN3BRuvPTm+AjNZsM3LfnDZoFe1SQYvOrzbjuRfpOAFcBEXmqfHmehOs16ZiehYQ xsug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dKj0+Cf8; 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 dl4-20020a05620a1d0400b00767117b9c26si369750qkb.210.2023.08.30.19.58.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Aug 2023 19:58:35 -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=dKj0+Cf8; 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 1qbXsJ-0004te-5f; Wed, 30 Aug 2023 22:57:39 -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 1qbXsH-0004sZ-Fw for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:37 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbXsE-0007oX-Mx for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:37 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-26d49cf1811so248524a91.0 for ; Wed, 30 Aug 2023 19:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693450653; x=1694055453; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=35LeKOF1XNerGikRaTSmAIP+dLZWVrcFdHv/rNI8hAg=; b=dKj0+Cf8NExkGYwOr+RPHT9jfUYApNaLkFvQXXJS+GyPP/6bKe7CNrJ2soSfAOWeQk 9K78uceyVeUnP264tqldXSNSv2Jpw3Y6V88rzex3J7JQPRLwQeDPFbJVdjLiI/DRxAxs 51oV7+dbZIMkKVmh0eimzXfUL/ceGzh1AvfPajJmnsH8A8h7XjlICJAwvljmJN71tOV7 Ok2lJkbonsXeuUsVI0mGDIVx6KKkupmh4f23tui1VnoPvAHwlUM5Sy5DuVt3JMOAtWcH yxnitxgz5LDkeAfD5+uGwXezWrc7K3GkpBBDU/N7ZmOuckb8QEmhuJ1OS4IXVK2V/ND1 XATA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693450653; x=1694055453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=35LeKOF1XNerGikRaTSmAIP+dLZWVrcFdHv/rNI8hAg=; b=iKK5rGAvJzDIVS5zOamXmRZ17Zzvt3xgiskNrV5m8xjD97kx1ur8wp/GRiCBGw39Z9 ciGGTD1COFRcm3RaL50WFrvT59eXvY8K2n2sBOXvWYvx7UjZi4JC5fNLDxJArZr2G6cP 9J3v4E8JoGBM3hFjyw5OKhqzjmKcdP+RczUuSqoZ0H6NnflHIVUW1UwFI+pW50U8KWRD oZa5/SgOpX9JQor0TTvB0fIkskqskZXIvXqqNC0HiEhJrDfc7oGMonco7RrkY296zUs3 8NgGNyPXT5s2o1uxE6EkLbKblll0Y2dNEvTTphmhchqsGuUwrdrHdGfeivWTRZ8jr31F CaEQ== X-Gm-Message-State: AOJu0YxNYtOh/DkWfITA/Xql6XXTqaIudK3xadmmvhiX5syHxlfo/k12 kMMYjnpCTtYESVhOCwTPFe/+1ZreJ1FoNjLwRAA= X-Received: by 2002:a17:90a:304a:b0:269:4645:80b9 with SMTP id q10-20020a17090a304a00b00269464580b9mr3920052pjl.2.1693450653223; Wed, 30 Aug 2023 19:57:33 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id dw24-20020a17090b095800b00265c742a262sm288142pjb.4.2023.08.30.19.57.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 19:57:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/4] tcg/optimize: Pipe OptContext into reset_ts Date: Wed, 30 Aug 2023 19:57:27 -0700 Message-Id: <20230831025729.1194388-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831025729.1194388-1-richard.henderson@linaro.org> References: <20230831025729.1194388-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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 Will be needed in the next patch. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/optimize.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 3013eb04e6..f00db3aa38 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -123,7 +123,7 @@ static inline bool ts_is_copy(TCGTemp *ts) } /* Reset TEMP's state, possibly removing the temp for the list of copies. */ -static void reset_ts(TCGTemp *ts) +static void reset_ts(OptContext *ctx, TCGTemp *ts) { TempOptInfo *ti = ts_info(ts); TempOptInfo *pi = ts_info(ti->prev_copy); @@ -138,9 +138,9 @@ static void reset_ts(TCGTemp *ts) ti->s_mask = 0; } -static void reset_temp(TCGArg arg) +static void reset_temp(OptContext *ctx, TCGArg arg) { - reset_ts(arg_temp(arg)); + reset_ts(ctx, arg_temp(arg)); } /* Initialize and activate a temporary. */ @@ -239,7 +239,7 @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) return true; } - reset_ts(dst_ts); + reset_ts(ctx, dst_ts); di = ts_info(dst_ts); si = ts_info(src_ts); @@ -700,7 +700,7 @@ static void finish_folding(OptContext *ctx, TCGOp *op) nb_oargs = def->nb_oargs; for (i = 0; i < nb_oargs; i++) { TCGTemp *ts = arg_temp(op->args[i]); - reset_ts(ts); + reset_ts(ctx, ts); /* * Save the corresponding known-zero/sign bits mask for the * first output argument (only one supported so far). @@ -1213,14 +1213,14 @@ static bool fold_call(OptContext *ctx, TCGOp *op) for (i = 0; i < nb_globals; i++) { if (test_bit(i, ctx->temps_used.l)) { - reset_ts(&ctx->tcg->temps[i]); + reset_ts(ctx, &ctx->tcg->temps[i]); } } } /* Reset temp data for outputs. */ for (i = 0; i < nb_oargs; i++) { - reset_temp(op->args[i]); + reset_temp(ctx, op->args[i]); } /* Stop optimizing MB across calls. */ From patchwork Thu Aug 31 02:57:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718944 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp241353wrn; Wed, 30 Aug 2023 19:58:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzYJ534pzZv0uPjQzLZ6YZngMNx9K2XVPZ4FGB/6Ats3m85TTcnvLxuD4o/LOK1CTJ87yM X-Received: by 2002:a05:620a:198a:b0:76c:c636:4772 with SMTP id bm10-20020a05620a198a00b0076cc6364772mr1740227qkb.65.1693450729673; Wed, 30 Aug 2023 19:58:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693450729; cv=none; d=google.com; s=arc-20160816; b=ilCtGfHVBFlogh21CVVc/1ppmAdVh0aBU3YnGYUVwHPfbrjGHqYpEd+TlrrlVW/Hr9 53FJdgYWshC80l4dRt1l9fq/SbMd6WYUZfa8JTRiId+9XTfJ8Eojz7BCgXxJBMN6hSLn Bk41QHQRgRi6jZsB4tSD55NEzWLN5d/90vh7h5nwb+olDTI2GA31Hs2oRS2TVdUapacC CfMy2O3d6T1iTGWVVe2Kl4DHBFSeradhYHrQDXy5qvXWfaWuTPQD22daQxvk/7+iA1GC kRSeGd27TY8Sx1Wh5d03x8CBcm/ZRAz/xPuT1MVMJK5FHyCqaJjD6IteuxoDYTHB6Jqv /yTQ== 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:to:from :dkim-signature; bh=aChezhcTwmznOrUe1OvXxjCsUo8aXEzn0qJIindA1tY=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=oBNdGE3TLPkD8R1ykGr9hmY60NJ5JJGxwhduQ5QHJsMWkH3sp9a3fvBk/PKkQZCdrT CgB5zY2UmB35nl+v2tQvmeHtyA049H3lhHUIl0xfpxCDoSxCsU0q+APUbueS4WS8JRBj XSelDGH0oxuo+exjvT0YH7Dn4phQukgsgAZ4y//FsDsuZ5iB+2VOZTHkt4qhnVEZK0s+ YFQEFCNXYpfD04OSdp9NAX+x2nDL/uwK7WqjfhM1NflLAwvjL1hKPaJkhQMNuaD+e8Gr 6Myt1ubZNHnqzalr59LimLOkCQ1CRtCDFskfUuf5G65xDk1rD3h2nyUbeq4F1w2i0TO6 bkaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g2kNJu3i; 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 i4-20020a05620a404400b0076d7dc7fa90si404916qko.45.2023.08.30.19.58.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Aug 2023 19:58:49 -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=g2kNJu3i; 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 1qbXsL-0004tm-O7; Wed, 30 Aug 2023 22:57:41 -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 1qbXsI-0004t2-Hs for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:38 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbXsF-0007od-QX for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:38 -0400 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-269304c135aso273760a91.3 for ; Wed, 30 Aug 2023 19:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693450654; x=1694055454; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=aChezhcTwmznOrUe1OvXxjCsUo8aXEzn0qJIindA1tY=; b=g2kNJu3ihPIc0fdZJx8NXfgji8+VyiT0iLZIm/tw26KgdNO1gRENXjTcZKQw+fJwgj McDFJLOdtpf1cwe2LtKwmWrHneuE+RJE63U/KrMQPv5n+IZ8EO726U7ioct0FvPbRLw/ AjpKNp95HbFVHzhMY71dFe5iCLNU8c85uhravcO7lJWQyN0gN51kKpONRPN2LG+FMhrd cLm96IKMVTQjuDCogb4JNg0DN8kwBNhTESHcIuK8VBItER6+11D4uzmWoOiSGZbS9wh1 TTFDLh2zCTmBLa72bFOn08X8agliA6HxnklMWRSaNCRPZ+izqbfBXPyIJudCMJwxgmYt Fq3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693450654; x=1694055454; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aChezhcTwmznOrUe1OvXxjCsUo8aXEzn0qJIindA1tY=; b=ScQDOy2bmv8CitrnmAnwNJ74STLTyJCTpd6AitvyzlK4epanEAsZeOfjpHzJT86o0c 2YSniFBFJ8ipO0WlcudkPWEvrv7usYZiS6PMw4BxxYcQgBxFO+r+DJpiRupBaV1R2dgw V6230cCDh3uO1Jdfbuis8SVoWKkw6iicG6esMFtxgNHKFmkXs5Ev6JtXs54McENWCfyV SBGL0twEDggGCnK/hHBn/1brfqOmT5RdyyPkDr6Wk17oSLvQ7EIeTMZsAEl29cUzaD4u olwFkGTRcP39c+G4TbCJr/n85/fLZypEdDMDMbeG4RKRVUO94YTia/dCh+PTT+uZSr03 hK4w== X-Gm-Message-State: AOJu0Yyhq22M/lV+DltGfhekaJigcl+DzqFDbf58l+86BH/qyD5mwJTY sA1I5BPmLb1nc7+w7sEN/2S62e0CpkugFEed278= X-Received: by 2002:a17:90a:6945:b0:269:1d16:25fa with SMTP id j5-20020a17090a694500b002691d1625famr3934195pjm.12.1693450654044; Wed, 30 Aug 2023 19:57:34 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id dw24-20020a17090b095800b00265c742a262sm288142pjb.4.2023.08.30.19.57.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 19:57:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 3/4] tcg: Optimize env memory operations Date: Wed, 30 Aug 2023 19:57:28 -0700 Message-Id: <20230831025729.1194388-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831025729.1194388-1-richard.henderson@linaro.org> References: <20230831025729.1194388-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 Propagate stores to loads, loads to loads. Signed-off-by: Richard Henderson --- tcg/optimize.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/tcg/optimize.c b/tcg/optimize.c index f00db3aa38..51c4c61b9f 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "qemu/int128.h" +#include "qemu/interval-tree.h" #include "tcg/tcg-op-common.h" #include "tcg-internal.h" @@ -37,10 +38,18 @@ glue(glue(case INDEX_op_, x), _i64): \ glue(glue(case INDEX_op_, x), _vec) +typedef struct MemCopyInfo { + IntervalTreeNode itree; + QSIMPLEQ_ENTRY (MemCopyInfo) next; + TCGTemp *ts; + TCGType type; +} MemCopyInfo; + typedef struct TempOptInfo { bool is_const; TCGTemp *prev_copy; TCGTemp *next_copy; + QSIMPLEQ_HEAD(, MemCopyInfo) mem_copy; uint64_t val; uint64_t z_mask; /* mask bit is 0 if and only if value bit is 0 */ uint64_t s_mask; /* a left-aligned mask of clrsb(value) bits. */ @@ -51,6 +60,9 @@ typedef struct OptContext { TCGOp *prev_mb; TCGTempSet temps_used; + IntervalTreeRoot mem_copy; + QSIMPLEQ_HEAD(, MemCopyInfo) mem_free; + /* In flight values from optimization. */ uint64_t a_mask; /* mask bit is 0 iff value identical to first input */ uint64_t z_mask; /* mask bit is 0 iff value bit is 0 */ @@ -128,6 +140,7 @@ static void reset_ts(OptContext *ctx, TCGTemp *ts) TempOptInfo *ti = ts_info(ts); TempOptInfo *pi = ts_info(ti->prev_copy); TempOptInfo *ni = ts_info(ti->next_copy); + MemCopyInfo *mc; ni->prev_copy = ti->prev_copy; pi->next_copy = ti->next_copy; @@ -136,6 +149,11 @@ static void reset_ts(OptContext *ctx, TCGTemp *ts) ti->is_const = false; ti->z_mask = -1; ti->s_mask = 0; + + QSIMPLEQ_FOREACH(mc, &ti->mem_copy, next) { + interval_tree_remove(&mc->itree, &ctx->mem_copy); + } + QSIMPLEQ_CONCAT(&ctx->mem_free, &ti->mem_copy); } static void reset_temp(OptContext *ctx, TCGArg arg) @@ -162,6 +180,7 @@ static void init_ts_info(OptContext *ctx, TCGTemp *ts) ti->next_copy = ts; ti->prev_copy = ts; + QSIMPLEQ_INIT(&ti->mem_copy); if (ts->kind == TEMP_CONST) { ti->is_const = true; ti->val = ts->val; @@ -174,6 +193,68 @@ static void init_ts_info(OptContext *ctx, TCGTemp *ts) } } +static MemCopyInfo *mem_copy_first(OptContext *ctx, intptr_t s, intptr_t l) +{ + IntervalTreeNode *r = interval_tree_iter_first(&ctx->mem_copy, s, l); + return r ? container_of(r, MemCopyInfo, itree) : NULL; +} + +static MemCopyInfo *mem_copy_next(MemCopyInfo *mem, intptr_t s, intptr_t l) +{ + IntervalTreeNode *r = interval_tree_iter_next(&mem->itree, s, l); + return r ? container_of(r, MemCopyInfo, itree) : NULL; +} + +static void remove_mem_copy(OptContext *ctx, MemCopyInfo *mc) +{ + TCGTemp *ts = mc->ts; + TempOptInfo *ti = ts_info(ts); + + interval_tree_remove(&mc->itree, &ctx->mem_copy); + QSIMPLEQ_REMOVE(&ti->mem_copy, mc, MemCopyInfo, next); + QSIMPLEQ_INSERT_TAIL(&ctx->mem_free, mc, next); +} + +static void remove_mem_copy_in(OptContext *ctx, intptr_t s, intptr_t l) +{ + while (true) { + MemCopyInfo *mc = mem_copy_first(ctx, s, l); + if (!mc) { + break; + } + remove_mem_copy(ctx, mc); + } +} + +static void remove_mem_copy_all(OptContext *ctx) +{ + remove_mem_copy_in(ctx, 0, -1); + tcg_debug_assert(interval_tree_is_empty(&ctx->mem_copy)); +} + +static void record_mem_copy(OptContext *ctx, TCGType type, + TCGTemp *ts, intptr_t start, intptr_t last) +{ + MemCopyInfo *mc; + TempOptInfo *ti = ts_info(ts); + + mc = QSIMPLEQ_FIRST(&ctx->mem_free); + if (mc) { + QSIMPLEQ_REMOVE_HEAD(&ctx->mem_free, next); + } else { + mc = tcg_malloc(sizeof(*mc)); + } + + memset(mc, 0, sizeof(*mc)); + mc->type = type; + mc->ts = ts; + mc->itree.start = start; + mc->itree.last = last; + + interval_tree_insert(&mc->itree, &ctx->mem_copy); + QSIMPLEQ_INSERT_TAIL(&ti->mem_copy, mc, next); +} + static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts) { TCGTemp *i, *g, *l; @@ -226,6 +307,18 @@ static bool args_are_copies(TCGArg arg1, TCGArg arg2) return ts_are_copies(arg_temp(arg1), arg_temp(arg2)); } +static TCGTemp *find_mem_copy_for(OptContext *ctx, TCGType type, intptr_t s) +{ + MemCopyInfo *mc; + + for (mc = mem_copy_first(ctx, s, s); mc; mc = mem_copy_next(mc, s, s)) { + if (mc->itree.start == s && mc->type == type) { + return find_better_copy(ctx->tcg, mc->ts); + } + } + return NULL; +} + static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) { TCGTemp *dst_ts = arg_temp(dst); @@ -268,6 +361,7 @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) if (src_ts->type == dst_ts->type) { TempOptInfo *ni = ts_info(si->next_copy); + MemCopyInfo *mc; di->next_copy = si->next_copy; di->prev_copy = src_ts; @@ -275,6 +369,11 @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) si->next_copy = dst_ts; di->is_const = si->is_const; di->val = si->val; + + QSIMPLEQ_FOREACH(mc, &si->mem_copy, next) { + record_mem_copy(ctx, mc->type, dst_ts, + mc->itree.start, mc->itree.last); + } } return true; } @@ -693,6 +792,7 @@ static void finish_folding(OptContext *ctx, TCGOp *op) */ if (def->flags & TCG_OPF_BB_END) { memset(&ctx->temps_used, 0, sizeof(ctx->temps_used)); + remove_mem_copy_all(ctx); ctx->prev_mb = NULL; return; } @@ -1218,6 +1318,11 @@ static bool fold_call(OptContext *ctx, TCGOp *op) } } + /* If the function has side effects, reset mem data. */ + if (!(flags & TCG_CALL_NO_SIDE_EFFECTS)) { + remove_mem_copy_all(ctx); + } + /* Reset temp data for outputs. */ for (i = 0; i < nb_oargs; i++) { reset_temp(ctx, op->args[i]); @@ -2075,6 +2180,83 @@ static bool fold_tcg_ld(OptContext *ctx, TCGOp *op) return false; } +static bool fold_tcg_ld_memcopy(OptContext *ctx, TCGOp *op) +{ + TCGTemp *dst, *src; + intptr_t ofs; + TCGType type; + + if (op->args[1] != tcgv_ptr_arg(cpu_env)) { + return false; + } + + type = ctx->type; + ofs = op->args[2]; + dst = arg_temp(op->args[0]); + src = find_mem_copy_for(ctx, type, ofs); + if (src && src->base_type == type) { + return tcg_opt_gen_mov(ctx, op, temp_arg(dst), temp_arg(src)); + } + + reset_ts(ctx, dst); + record_mem_copy(ctx, type, dst, ofs, ofs + tcg_type_size(type) - 1); + return true; +} + +static bool fold_tcg_st(OptContext *ctx, TCGOp *op) +{ + intptr_t ofs = op->args[2]; + intptr_t lm1; + + if (op->args[1] != tcgv_ptr_arg(cpu_env)) { + remove_mem_copy_all(ctx); + return false; + } + + switch (op->opc) { + CASE_OP_32_64(st8): + lm1 = 0; + break; + CASE_OP_32_64(st16): + lm1 = 1; + break; + case INDEX_op_st32_i64: + case INDEX_op_st_i32: + lm1 = 3; + break; + case INDEX_op_st_i64: + lm1 = 7; + break; + case INDEX_op_st_vec: + lm1 = tcg_type_size(ctx->type) - 1; + break; + default: + g_assert_not_reached(); + } + remove_mem_copy_in(ctx, ofs, ofs + lm1); + return false; +} + +static bool fold_tcg_st_memcopy(OptContext *ctx, TCGOp *op) +{ + TCGTemp *src; + intptr_t ofs, last; + TCGType type; + + if (op->args[1] != tcgv_ptr_arg(cpu_env)) { + fold_tcg_st(ctx, op); + return false; + } + + src = arg_temp(op->args[0]); + ofs = op->args[2]; + type = ctx->type; + last = ofs + tcg_type_size(type) - 1; + remove_mem_copy_in(ctx, ofs, last); + record_mem_copy(ctx, type, src, ofs, last); + return false; +} + static bool fold_xor(OptContext *ctx, TCGOp *op) { if (fold_const2_commutative(ctx, op) || @@ -2098,6 +2280,8 @@ void tcg_optimize(TCGContext *s) TCGOp *op, *op_next; OptContext ctx = { .tcg = s }; + QSIMPLEQ_INIT(&ctx.mem_free); + /* Array VALS has an element for each temp. If this temp holds a constant then its value is kept in VALS' element. If this temp is a copy of other ones then the other copies are @@ -2219,6 +2403,21 @@ void tcg_optimize(TCGContext *s) case INDEX_op_ld32u_i64: done = fold_tcg_ld(&ctx, op); break; + case INDEX_op_ld_i32: + case INDEX_op_ld_i64: + case INDEX_op_ld_vec: + done = fold_tcg_ld_memcopy(&ctx, op); + break; + CASE_OP_32_64(st8): + CASE_OP_32_64(st16): + case INDEX_op_st32_i64: + done = fold_tcg_st(&ctx, op); + break; + case INDEX_op_st_i32: + case INDEX_op_st_i64: + case INDEX_op_st_vec: + done = fold_tcg_st_memcopy(&ctx, op); + break; case INDEX_op_mb: done = fold_mb(&ctx, op); break; From patchwork Thu Aug 31 02:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718943 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp241326wrn; Wed, 30 Aug 2023 19:58:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8UQDbnokoP0KdxLO48eC7euFv1mss7NEoBNUtN0bx7IRucPlej/WpQZyJwxpu1AjeDNgs X-Received: by 2002:a0c:cd0e:0:b0:649:831c:6bad with SMTP id b14-20020a0ccd0e000000b00649831c6badmr1639882qvm.57.1693450718971; Wed, 30 Aug 2023 19:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693450718; cv=none; d=google.com; s=arc-20160816; b=jpLndiATgr5TeERsTUALBWfs2SE04tjq9IcBU/59lmAPK6DAZ5Ia9H2cd2IL+MZC8t sn8+/Xk1st2kJKrK6ACb1NZ0xj0eIUEWhivYpOk5uAoaggRq9U3cQLXNsNWk/QqAUxvu oUs0ln8KW5EyCuXE1Rnsj8TsY25m/b8pmUFsxEb6O79cYGGSFQQYQFN8GTofOFc4kF7S mn8idZAbjacSR+7d0gOCeCTXIhhzWviwRgK77wfMiif23OdhWZoXAxLUyHhjSpMDYBlh LYaEk0+3u7lsaaVEoBua4D7RLbeLd0CpkajVVcIUmGWRgG4wUCU1BFFWq+tgdVmqaH8N kXyw== 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:to:from :dkim-signature; bh=4Bhbbu1kEgOjuWuUFXYYFqctaT2+nMVs+SHOqYCtseg=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=IRzJvTTiqTfNB4jPAHVMm7De9Pq7a29ZghtygCbEBgPO2EkpSqF4OkqoP/mJy6HNKk z3tGyZs2qawNQcA/uhgMywRsPm2j2daNN3dJ1NpnWORicizKCEUWzBY9M0J1G8/yepNJ MGo+WUnz1biBYtR3UYCPW8MRWeUe9m4t/HVUXkLB0O3ankSrSE4AiTs30HZs/pTLKExr YG6Z1oLIFF2Q3xpqqshJ/clJeXQ5RzZyjnvWGQBpwYyLqwdal2yk02Ep1QhFPCzRWObT KeQcJGP/oPY7zQRPPdrv7MtLApPEuQ8yfXPl9zdcQN+CaJCMx/CIPms+68Rs/1EU/CRE OCuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RW4ZdYT4; 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 t9-20020a0c8d89000000b0064f47cde8e0si299606qvb.381.2023.08.30.19.58.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Aug 2023 19:58:38 -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=RW4ZdYT4; 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 1qbXsL-0004tk-Iv; Wed, 30 Aug 2023 22:57:41 -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 1qbXsI-0004t6-OW for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:38 -0400 Received: from mail-vs1-xe30.google.com ([2607:f8b0:4864:20::e30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbXsG-0007op-AH for qemu-devel@nongnu.org; Wed, 30 Aug 2023 22:57:38 -0400 Received: by mail-vs1-xe30.google.com with SMTP id ada2fe7eead31-44ea1f87427so215509137.3 for ; Wed, 30 Aug 2023 19:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693450655; x=1694055455; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4Bhbbu1kEgOjuWuUFXYYFqctaT2+nMVs+SHOqYCtseg=; b=RW4ZdYT4UfTd72U949shH9/GcgYI9X7+tFFpBHoQVd674dmrvnuKzvH+OX1pS5pyqr G5gk1dLIy5PQUoNM4Lrxt+8+8c9e0308gHa77cEb35ew2BRD+BYh+25dwD/rJ8w6/a8V 7O9V8QjKsf5eCWlQjgpXd/Qr+DXGeja7HTsZZ6B0DmGIsDBcfPNZOPPb1gkbtJKAIl2/ 4cyi6id2RSayBCiBJFhf1gKCcyuFiklvO6iDwk5I+HC/Vi9ob6rAzugjwGslKx0bYLU/ D5mV7g/pSD3Vc+Aw0/Tjk6B+ivojn4y2FOmUMyyF/wybEjCH8Ixwja2SoYiggxIiCo/+ EIdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693450655; x=1694055455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Bhbbu1kEgOjuWuUFXYYFqctaT2+nMVs+SHOqYCtseg=; b=LkNngv/kXFDztEUOp8sZZ7/WXq9JCNU+GYHoRTBD0kpoRonB8tCwW/GOsLXRVGChFu 696XhdNshaAYYNVjaHlC0cDSkv4CQdmLRvjeC6tvkwcYO8wyWH/LBosgn2w8ZpwJamLu M5ugQCFpcdCZI+R30buuAW7dDo5aeHwlwuEc3kkvFz9xmGO5x3scrde0OOLZGEAPzKtR 3avoddII+h7bO3LgRfiHXzUQjbJWMKfrrCa6Q3dtotIFRCsWY67/kZn/mMTQGTB5nQGa miFnkmqK12+VN0hhF70bABE7KgR0u6bLa4FU8SPL/4MIrMcj+wtWlnuZDRENmYeeVFaG 3AVg== X-Gm-Message-State: AOJu0YzIalkXxZzETeVoO+f33p+eWC6yOkDAZJ1XI/zim60mtTQJjtfQ Eta7fq9I5uVdeiSjX4Kbc6WPht+g11zg4YGZVhg= X-Received: by 2002:a67:b302:0:b0:44d:5105:b146 with SMTP id a2-20020a67b302000000b0044d5105b146mr3995129vsm.23.1693450654959; Wed, 30 Aug 2023 19:57:34 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id dw24-20020a17090b095800b00265c742a262sm288142pjb.4.2023.08.30.19.57.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 19:57:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 4/4] tcg: Eliminate duplicate env store operations Date: Wed, 30 Aug 2023 19:57:29 -0700 Message-Id: <20230831025729.1194388-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831025729.1194388-1-richard.henderson@linaro.org> References: <20230831025729.1194388-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::e30; envelope-from=richard.henderson@linaro.org; helo=mail-vs1-xe30.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 Notice when a constant is stored to the same location twice. Signed-off-by: Richard Henderson --- tcg/optimize.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tcg/optimize.c b/tcg/optimize.c index 51c4c61b9f..6efc08f593 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -2251,6 +2251,19 @@ static bool fold_tcg_st_memcopy(OptContext *ctx, TCGOp *op) src = arg_temp(op->args[0]); ofs = op->args[2]; type = ctx->type; + + /* + * Eliminate duplicate stores of a constant. + * This happens frequently when the target ISA zero-extends. + */ + if (ts_is_const(src)) { + TCGTemp *prev = find_mem_copy_for(ctx, type, ofs); + if (src == prev) { + tcg_op_remove(ctx->tcg, op); + return true; + } + } + last = ofs + tcg_type_size(type) - 1; remove_mem_copy_in(ctx, ofs, last); record_mem_copy(ctx, type, src, ofs, last);