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 EC2494B9FAF; Wed, 21 Jun 2023 11:56:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EC2494B9FAF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1687337813; bh=+itQoceTzYYvIKEfeA+q+7cxyB68BdMxPG1Vnkjgy5A=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jFotITtmYfrkdg89PGyP8jZU6QFWdsUWEsV/E/UEO/9d/Efu5wWruKG5m2kxsJJ9W ihelrNfxIWiu7GV7HD+NepJvWJn72g6J8hMJ3u9XPBrrskJf0we/P0Bi+1IPf1/E4+ aoAAyZeY2OPQ7tgKQCvPgA6wM0Frp9ZlvzyJm0po= Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [95.163.41.66]) (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 1B93E4B9FAF for ; Wed, 21 Jun 2023 11:56:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1B93E4B9FAF Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1qBtdz-00GgWB-Az; Wed, 21 Jun 2023 11:56:51 +0300 Date: Wed, 21 Jun 2023 11:52:36 +0300 To: Maxim Kokryashkin , tarantool-patches@dev.tarantool.org Message-ID: References: <2e92221ec1d4e8222be8cbd89b4d0e047bc9b795.1686299850.git.skaplun@tarantool.org> <1686753984.760025901@f390.i.mail.ru> 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: 4F1203BC0FB41BD95D99986233CC4DDC4468B86CD3C8787546E8D189E2EBE9EA182A05F53808504073F80CF7DCAF19E2EE62A27994DEB3A255E9D41CCC2F89CC29E7E9DE7D9609C9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74EC61905B8C6A847EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CDA089757FB31C668638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82EAF1191C083811B0C0FC20AD1A1D627117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735200AC5B80A05675ACD28451B159A507268D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE0AC5B80A05675ACD452896749CDDA0A6D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE32A336C651863509103F1AB874ED89028C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006379FC65886B7F75608EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A52FF57B3A5DBE373E74BA2BEB2E80BE2BF12AA767FF145DA5F87CCE6106E1FC07E67D4AC08A07B9B0DB8A315C1FF4794DBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF78E023BB1DD2B4D74954D8B91F49282F8B55D36DC25911EA9F6A282E8810791FF62474FBACD619B0C17492877F82D9B8E23B365A0940983CA27F9A7571F9521F40B08DDBC5CE87D002C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojw7uTMtz3/ly8k+dsArq1Jw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769BC88D708D518333AEE62A27994DEB3A21442BDFAA4939184DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix use-def analysis for BC_VARG. 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 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On 21.06.23, Sergey Kaplun via Tarantool-patches wrote: > Hi, Maxim! > Thanks for the review! > > On 14.06.23, Maxim Kokryashkin wrote: > > > > Hi, Sergey! > > Thanks for the patch! > > Please consider my comments below. > >   > > >  > > >>From: Mike Pall > > >> > > >>Reported by Ryan Lucia. > > >> > > >>(cherry-picked from commit 2801500a26084491ae035170cad4700513790890) > > >> > > >>Use-def analizis for BC_VARG has to strong limit for the top/maxslot, so > > >Typo: s/analizis/analysis/ > > Fixed! Thanks! > > > >>no slots may considered as used. This leads to addititional SLOAD on > > >Typo: s/may/may be/ > > >Typo: s/to additional/to an additional/ > > Fixed. > > > >>trace with incorrect value used later. This patch disables the use-def > > >Typo: s/trace with/the trace with an/ > > Fixed. > > > >>analisis for BC_VARG as NIY. > > >Typo: s/analisis/analysis/ > > Fixed, thanks! > > > >> > > >>Sergey Kaplun: > > >>* added the description and the test for the problem > > >> > > >>Part of tarantool/tarantool#8516 > > >>Relates to tarantool/tarantool#8718 > > >>--- > > >> src/lj_snap.c | 4 +- > > >> .../lj-704-bc-varg-use-def.test.lua | 65 +++++++++++++++++++ > > >> 2 files changed, 68 insertions(+), 1 deletion(-) > > >> create mode 100644 test/tarantool-tests/lj-704-bc-varg-use-def.test.lua > > >> > > > > > >>diff --git a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua > > >>new file mode 100644 > > >>index 00000000..c3ba65dd > > >>--- /dev/null > > >>+++ b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua > > >>@@ -0,0 +1,65 @@ > > >>+local tap = require('tap') > > >>+-- Test file to demonstrate LuaJIT misbehaviour in use-def > > >>+-- snapshot analysis for BC_VARG. > > >>+-- See also https://github.com/LuaJIT/LuaJIT/issues/704 . > > >>+local test = tap.test('lj-704-bc-varg-use-def'):skipcond({ > > >>+ ['Test requires JIT enabled'] = not jit.status(), > > >>+}) > > >>+ > > >>+test:plan(1) > > >>+ > > >>+-- XXX: we don't really need to store this builtins, but this is > > >Typo: s/this/these/ > > Fixed, thanks! > > > >>+-- reduces `jitdump()` output for reader significantly. > > >>+local fmod = math.fmod > > >>+local pcall = pcall > > >>+ > > >>+-- Use the 2 values for `fmod()` to produce non-zero value for > > >>+-- the call on trace (the last one call). > > >>+local ARG_ON_RECORDING = 6 > > >>+local ON_TRACE_VALUE = ARG_ON_RECORDING + 1 > > >Why are they exactly 6 and 7? Please drop a comment. > > No special meaning, added a comment. > > > >>+ > > >>+-- The `jitdump()` output was like the following before the patch: > > >>+-- 0003 > num SLOAD #1 T > > >>+-- .... SNAP #1 [`wrap()`|---- pcall|`varg()`|----] > > >>+-- 0004 } tab TNEW #3 #0 > > >>+-- 0005 > num SLOAD #4 T > > >>+-- 0006 p32 FLOAD 0004 tab.array > > >>+-- 0007 p32 AREF 0006 +1 > > >>+-- 0008 } num ASTORE 0007 0005 > > >>+-- .... SNAP #2 [`wrap()`|---- pcall|math.fmod|+6 0005] > > >>+-- > > >>+-- The first snapshot misses the 0003 IR in the last slot to be > > >>+-- used in the `fmod()` later, so it leads to the additional > > >>+-- 0005 SLOAD #4, and storing it in the second snapshot. > > >>+-- > > >>+-- The correct snapshot content after the patch is the following: > > >>+-- .... SNAP #1 [`wrap()`|---- pcall|`varg()`|0003] > > >>+-- .... > > >>+-- .... SNAP #2 [`wrap()`|---- pcall|math.fmod|+6 0003] > > >>+local function varg(...) > > >>+ -- Generate snapshot after `pcall()` with missing slot. > > >>+ -- The snapshot is generated before each TNEW after the commit > > >>+ -- 7505e78bd6c24cac6e93f5163675021734801b65 ("Handle on-trace > > >>+ -- OOM errors from helper functions.") > > >>+ local slot = ({...})[1] > > >>+ -- Forcify stitch and usage of vararg slot. > > >>+ return fmod(ARG_ON_RECORDING, slot) > > >Are there any reasons behind the `fmod` choice? If so, please drop a comment. > > No, added the comment. > > > >>+end > > >>+ > > >>+jit.opt.start('hotloop=1') > > >>+ > > >>+local _, result > > >>+local function wrap(arg) > > >>+ -- `pcall()` is needed to emit snapshot to handle on-trace > > >>+ -- errors. > > >Maybe it is worth mentioning Mike’s original comment[1] here. > > >Feel free to ignore. > > I just added the reference to the issue in the header, the comment above > is about the same as Mike's but more verbose. > > =================================================================== > diff --git a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua > index c3ba65dd..3608ea4e 100644 > --- a/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua > +++ b/test/tarantool-tests/lj-704-bc-varg-use-def.test.lua > @@ -8,13 +8,13 @@ local test = tap.test('lj-704-bc-varg-use-def'):skipcond({ > > test:plan(1) > > --- XXX: we don't really need to store this builtins, but this is > +-- XXX: we don't really need to store these builtins, but this is > -- reduces `jitdump()` output for reader significantly. > local fmod = math.fmod > local pcall = pcall > > -- Use the 2 values for `fmod()` to produce non-zero value for > --- the call on trace (the last one call). > +-- the call on trace (the last one call). No special meaning. > local ARG_ON_RECORDING = 6 > local ON_TRACE_VALUE = ARG_ON_RECORDING + 1 > > @@ -42,23 +42,23 @@ local function varg(...) > -- 7505e78bd6c24cac6e93f5163675021734801b65 ("Handle on-trace > -- OOM errors from helper functions.") > local slot = ({...})[1] > - -- Forcify stitch and usage of vararg slot. > + -- Forcify stitch and usage of vararg slot. Any NIY is OK here. > return fmod(ARG_ON_RECORDING, slot) > end > > jit.opt.start('hotloop=1') > > local _, result > -local function wrap(arg) > +local function wrap(func, arg) > -- `pcall()` is needed to emit snapshot to handle on-trace > -- errors. > - _, result = pcall(varg, arg) > + _, result = pcall(func, arg) > end > -- Record trace with the 0 result. > -wrap(ARG_ON_RECORDING) > -wrap(ARG_ON_RECORDING) > +wrap(varg, ARG_ON_RECORDING) > +wrap(varg, ARG_ON_RECORDING) > -- Record trace with the non-zero result. > -wrap(ON_TRACE_VALUE) > +wrap(varg, ON_TRACE_VALUE) Brr, acturally, we need to separate two `wrap()` functions - to prevent compilation for the `wrap()` itself as non pcall-ed fixed-arg function. Added the comment. > > test:ok(result ~= 0, 'use-def analysis for BC_VARG') > =================================================================== > > I also modify `wrap()` function to get the function to call considering > your comments in the next patch. > > > >>+ _, result = pcall(varg, arg) > > >>+end > > >>+-- Record trace with the 0 result. > > >>+wrap(ARG_ON_RECORDING) > > >>+wrap(ARG_ON_RECORDING) > > >>+-- Record trace with the non-zero result. > > >>+wrap(ON_TRACE_VALUE) > > >>+ > > >>+test:ok(result ~= 0, 'use-def analysis for BC_VARG') > > >>+ > > >>+os.exit(test:check() and 0 or 1) > > >>-- > > >>2.34.1 > > >[1]:  https://github.com/LuaJIT/LuaJIT/issues/704 > > >-- > > >Best regards, > > >Maxim Kokryashkin > > -- > Best regards, > Sergey Kaplun -- Best regards, Sergey Kaplun