From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 7FB4D6F3C8; Wed, 28 Sep 2022 11:47:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7FB4D6F3C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1664354836; bh=Grm1Pplyzrpb3QRgGh1uZOFiU2Yvi/Qo10V5d6COBo4=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=MhbhEmM7f6LJojSU8SMwe6zRFJl+KoYwODwzxDjmSolJkEGo++9wp7ke3FLy72KFX supawxiN4blYzfWiai19LNXCs3LGH5rYS+W8HSy3nhA/1ADFLqr3HMYp5bjNln/e2H OKK0dkunVoNWK+0Z5AAeEfbv4KJhu6kVY+95Cahs= Received: from smtp60.i.mail.ru (smtp60.i.mail.ru [217.69.128.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 12A466F3C8 for ; Wed, 28 Sep 2022 11:47:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 12A466F3C8 Received: by smtp60.i.mail.ru with esmtpa (envelope-from ) id 1odSin-0004Up-FL; Wed, 28 Sep 2022 11:47:14 +0300 Date: Wed, 28 Sep 2022 11:44:22 +0300 To: sergos Message-ID: References: <20220831095237.18440-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD99929F1169E77FC7A014CAC533ECCE513DEDBE916EB09BB64182A05F538085040EE327969D4860AA1CD4629D4EB7FA2583212D8B920173ADFAE12BC40AB67052B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C6068CE86C2B75F5EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377F69ABDCCC31D2058638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8A37E35CF90DD8AD843E4D9D380481223117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCC0EC8C44E4C1BEE2A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE652FD71AFB96DC7D7AAF5A6EB0CB4C2AD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE35E3BF8C76DC23F746136E347CC761E07C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BB662CFBDBA8F60F475ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B0C7A0BC55FA0FE5FCF6F41DE083C8BA39B6D83D641E85FF30ADE5B93E9D305DB9B1881A6453793CE9C32612AADDFBE06133F7A9E5587C79A693EDB24507CE13387DFF0A840B692CF8 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F6CC1FD3366963362E0E2EB6D86F808E99119BF3BA3DA4106E33AB7E057629A0DEDA680B4D430F861D7E09C32AA3244C88D3523C8BD20660D906342F8A22120524AF4FAF06DA24FDFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojVySwzd+bxOfZnrmM7jtf9Q== X-Mailru-Sender: 11ABF2DAD5F2676891056722DE4A719E11F6B6298A9BDA72CD4629D4EB7FA258825871508D9F3970DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] ARM64: Avoid side-effects of constant rematerialization. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergos! Thanks for the review! On 06.09.22, sergos wrote: > Hi! > > Thanks for the patch! > As I can’t say much about the patch from Mike, LGTM. > Just some nits in the comment. > > Sergos > > > > On 31 Aug 2022, at 12:52, Sergey Kaplun wrote: > > > > From: Mike Pall > > > > Thanks to Patrick Galizia. > > > > (cherry picked from commit b33e3f2d441590f4de0d189bd9a65661824a48f6) > > > > Constant rematerialization must not use other registers that contain > > constants, if the register is in-flight. When we have the high > ^^^^^^ > in use? Fixed. > > regitster pressure we can face the following issue: > > > > The assembly of an IR instruction allocates a constant into a free > > register. Then it spills another register (due to high register > > pressure), which is rematerialized using the same constant (which it > > assumes is now in the allocated register). In case when the first > > register also happens to be the destination register, the constant value > > is modified before the rematerialization. > > > > For the code in the test for this commit we get the following register > > allocation order (read from top to bottom (DBG RA reversed)): > > | current IR | operation | IR ref | register > > | 0048 alloc 0038 x0 > > | 0048 remat K038 x0 > > | 0048 alloc K023 x4 > > > > Which leads to the following asembly: > > | ... > > | add x4, x4, x0 # x4 modified before x0 rematerialization > > | ldrb w4, [x4, #24] > > | add x0, x4, #24 # constant x0 rematerialization > > | ... > > As a result, the value register x0 holding is incorrect. > > > > This patch moves allocation of constants for earlier to be sure that the > ^^^ remove it Fixed, thanks! > > > rematerialization can not make use of the same constant as one of the > > sources of the IR instruction. > > > > After the patch register allocation order is the following: > > | current IR | operation | IR ref | register > > | 0048 alloc K023 x4 > > | 0048 alloc 0038 x0 > > | 0048 remat K038 x0 > > > > Also, this patch fixes the `asm_fusexref()` logic for the `IR_STRREF` in > > case, when both operands don't fit in 32-bit constants (`asm_isk32()` > > fails). We want to use the IR operand holds the referenced value in > holding Fixed, thanks! > > > `ra_alloc1()` as one having the hint set (`ra_hashint()` check passes). > > It is set for the operand with a non constant value (`irref_isk()` > > fails). The code assumes that this is always the `ir->op1` operand, so > it Fixed. > > > for cases when this value holds `ir->op2` operand register allocator > the case the Fixed, thanks! Branch is force-pushed. > > > misses the aforementioned hint in `ir->op2`. As the result the wrong > > register is selected. This patch adds the corresponding `irref_isk()` > > check for the `ir->op1` to detect which operand contains the value with > > the hint. > > > > After the patch the resulting assembly is the following: > > | ... > > | add x4, x0, x4 > > | ldrb w4, [x4, #24] > > | add x0, x1, #112 > > | ... > > > > As we can see the constant is rematerialized from another, non-modified > > register. > > > > Sergey Kaplun: > > * added the description and the test for the problem > > > > Part of tarantool/tarantool#7230 > > --- > > > > The test case leads to the coredump when compile with > > -DCMAKE_BUILD_TYPE=[Release, RelWithDebInfo]. > > > > Issue: https://github.com/tarantool/tarantool/issues/7230 > > PRs: > > * https://github.com/LuaJIT/LuaJIT/pull/438 > > * https://github.com/LuaJIT/LuaJIT/pull/479 > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-438-arm64-constant-rematerialization-full-ci > > Tarantool PR: https://github.com/tarantool/tarantool/pull/7628 > > > > src/lj_asm_arm64.h | 46 +++++--- > > ...-arm64-constant-rematerialization.test.lua | 102 ++++++++++++++++++ > > 2 files changed, 131 insertions(+), 17 deletions(-) > > create mode 100644 test/tarantool-tests/lj-438-arm64-constant-rematerialization.test.lua > > > > diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h > > index da0ee4bb..a4de187f 100644 > > --- a/src/lj_asm_arm64.h > > +++ b/src/lj_asm_arm64.h > > diff --git a/test/tarantool-tests/lj-438-arm64-constant-rematerialization.test.lua b/test/tarantool-tests/lj-438-arm64-constant-rematerialization.test.lua > > new file mode 100644 > > index 00000000..ffc449bc > > --- /dev/null > > +++ b/test/tarantool-tests/lj-438-arm64-constant-rematerialization.test.lua > > @@ -0,0 +1,102 @@ > -- Best regards, Sergey Kaplun