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 9177E4EC2A9; Wed, 21 Jun 2023 11:44:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9177E4EC2A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1687337068; bh=wE83buFY9E5IbpIu5WeczJUzjEx8WwK7ZBMIy+EJtVU=; 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=EhPJW1k7j1y0Dqm1cqVvf7w4IRmqszAUkHrkmhYkcDD/HAzEMaH+DbQp5opZeWiLY 6P6O5Bk9Vs7/gX6UnHjnmdTeeHy8HNWcENuWUcCixkc9drLY6Xc580gdO58RkeDlsv xc2iUJ7+/C6LBMDfKnWqoLlIgDwQXV45eis8bjsI= Received: from smtp17.i.mail.ru (smtp17.i.mail.ru [95.163.41.70]) (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 F1BCE6ECCD for ; Wed, 21 Jun 2023 11:44:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F1BCE6ECCD Received: by smtp17.i.mail.ru with esmtpa (envelope-from ) id 1qBtRx-00FLAr-Oj; Wed, 21 Jun 2023 11:44:26 +0300 Date: Wed, 21 Jun 2023 11:40:11 +0300 To: Maxim Kokryashkin 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: <1686753984.760025901@f390.i.mail.ru> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95D99986233CC4DDCFB14F17D0E9EAA49C0FEF2B22CA0AFAD182A05F538085040F5EC7C6889A14EA332835E89D96B608E3D9C74CBE742A8007B82FE6F12DAEBD3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74D0D2DEF2EB846B0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063719899BAB9B61B3948638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D87E2B55E7C4E4A89B7C4860AEBAC9A5A3117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735200AC5B80A05675ACDC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEFAD5A440E159F97D6136E347CC761E074AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3FB892369DDD87097BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE75B51C8FB0C3E748C731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A53F2D5452ECB33D6E312196B545C77B662F37A04BC42454F9F87CCE6106E1FC07E67D4AC08A07B9B0CE135D2742255B35CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF3E041167C28098019A01B0D75F976FEC3F96EB1D4C6D20DFB5BFC1F89249F2CFCCDF2CE9FE05F2E7C17492877F82D9B8E69D9E5BAF40779DA45629587F42AFB6E48CAC7CA610320002C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojw7uTMtz3/lzB9KkKRFJppg== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A76969E9F4F2DC02E16632835E89D96B608E7AD558DE3329E344DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF 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 Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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) 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