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 5EB8F215DEA; Thu, 30 Mar 2023 20:46:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5EB8F215DEA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1680198362; bh=XXliWaCP8MONLJLTx/nRHfz+eggo2DbGpdOnbRhvSjY=; 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=UfRFIytqoHmL9B8fwtqgh643shx6HVcdqNIU5sscDkUQzXzqO/T2tHvZNFSCvXRFv 8mETUE6Pbz6ASICZY0OpgaYg0McScNgDkDcHGptpIZJIhGxfmQrgPxRIDQITZHD0Qg wb+pj2Aq15f95ZPeBsrXhMbtSl6qkfP5vOMBbjUQ= Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [95.163.41.72]) (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 04373215DEA for ; Thu, 30 Mar 2023 20:45:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 04373215DEA Received: by smtp31.i.mail.ru with esmtpa (envelope-from ) id 1phwLO-00BtNn-Vn; Thu, 30 Mar 2023 20:45:51 +0300 Date: Thu, 30 Mar 2023 17:38:36 +0000 To: Sergey Kaplun Message-ID: References: <20220831095237.18440-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220831095237.18440-1-skaplun@tarantool.org> X-Clacks-Overhead: GNU Terry Pratchett X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9F8F06A4ADC2A029ED392DF46D9BBD91993351BDDA8FBAA571313CFAB8367EF908E2BE116634AD74D5810AAEB7A2BB915D2FD7C975B152C8061083FF6DCA8A41587CACECC26227EC5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7370F4F695FFFC24BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F832FB01FC7F589C8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8AD266D45FF0AF6B73A365E6F5B8EF5F7117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCB816BE3345416868389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8632EDEA9CD5989A3F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C706E30CA5231861903F1AB874ED890284AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3E48ED49A73D2AC8FBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE75B51C8FB0C3E748C731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A57E78B62C7034EDEACD1486D4D3838E6322861DBA94C49A88F87CCE6106E1FC07E67D4AC08A07B9B013BDA61BF53F5E1DCB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D342B8615F5CFAD9D0269965D32070DA4B706271D9167DEC63559A587B1D974C3CFEE9F16E1E39DD1AC1D7E09C32AA3244C341A09473AF15A3E61B07D37A5A6DBF64DBEAD0ED6C55A80927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojiHgmeVjUOtIYA3xzpTvCWA== X-Mailru-Sender: 2FEBA92C8E508479FE7B9A1DF348D531DD6514AB886B782A0E8F46BF97849FC8F7DAEAD609D3F3182326FE6F2A341ACE0FB9F97486540B4CD9E8847AB8CFED4D9ABF8A61C016C2CFB0DAF586E7D11B3E67EA787935ED9F1B 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: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sergey, I've checked the patchset into all long-term branches in tarantool/luajit and bumped a new version in master, 2.11 and 2.10. On 31.08.22, 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 > 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 > 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 > `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 > for cases when this value holds `ir->op2` operand register allocator > 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 > > -- > 2.34.1 > -- Best regards, IM