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 120B86E6F09; Mon, 20 Nov 2023 14:16:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 120B86E6F09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700479012; bh=Hcd3M7jPoZSkvfHRhNfCljx3Nbq8yNhhGRB/Bj7iOto=; 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=foxDwTtzKKwMzECF+b9uf7SQbFZJThsr220b6+jEBpe4yD8A4tMudiNI8SDRwV66f GqQ4OcSNjdh/TPXV9t/6iIDFQ1oU7ifZPChOjy6afDx7hsykwgmba+b9lMZoJV3a/K hnIGnypRyRoDY++5nBvWvBX8x+MNheamPia6Cs0c= Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [95.163.41.96]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E56936D69C2 for ; Mon, 20 Nov 2023 14:16:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E56936D69C2 Received: by smtp58.i.mail.ru with esmtpa (envelope-from ) id 1r52Gn-002t7o-0M; Mon, 20 Nov 2023 14:16:49 +0300 Date: Mon, 20 Nov 2023 14:12:16 +0300 To: Sergey Bronnikov Message-ID: References: <20231113150501.28143-1-skaplun@tarantool.org> <53dc17fe-77c9-412f-952a-32f519277b93@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <53dc17fe-77c9-412f-952a-32f519277b93@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD93F1575C7510F5547D25917A9C8A3601FF489A39E1D724A1300894C459B0CD1B9E98298E34961BBD022C6FCD427F8F1ED02C5EBA1E18267CA95D00E53B9AD7CA1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7956F10FFCC7409BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D81244D2CF6B2D5F8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81B5369C96BD53B850F9C1F5C7E848963117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAE9A1BBD95851C5BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE0AC5B80A05675ACD4DC33E588678F033D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3093C2F12201C912AC0837EA9F3D19764C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CD2DCF9CF1F528DBC2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F0A35B161A8BF67C142539A7722CA490CB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A50E0A98926CAB195B6B6921C328781ADFEAF0B08A1BD6E2FEF87CCE6106E1FC07E67D4AC08A07B9B0735DFC8FA7AC1207CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF1023896D9CB06205FC7F28FAB9B7CEB2BF10BD51F648928BA28D67138BE8E20F9DCE6E1EBC7C769E88AD3775A6B0C8348FDF4DA28860CDA7989502F1DBCC87ABE48CAC7CA610320002C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojmRIjd71J0y28vjIacSDm4Q== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769F7AF95547D045B4DD5B5E02265FCE2C0009DB4CE3002C7DBDEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix ABC FOLD rule with constants. 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" Hello, Sergey! Thanks for the review! Please consider my answers below. On 18.11.23, Sergey Bronnikov wrote: > Hello, Sergey! > > thanks for the patch! LGTM, see minor comments below. > > Sergey > > On 11/13/23 18:05, Sergey Kaplun wrote: > > From: Mike Pall > > > > Reported by XmiliaH. > > > > (cherry-picked from commit c8bcf1e5fb8eb72c7e35604fdfd27bba512761bb) > > > > `fold_abc_k()` doesn't patch the first ABC check when the right constant > > operand is negative. This leads to out-of-bounds access from the array > > on a trace. This patch casts to uint32_t the operands to compare. If the > > right IR contains a negative integer, the second IR will always be > > patched. Also, because the ABC check on the trace is unordered, this > > guard will always fail. > > > > Also, this fold rule creates new instructions that reference operands > IR output would be useful in a test, what do you think? I am not really sure about that (if I did, I would add it). The mention of missed IRs sounds like a good compromise. Anyone interested in the output dump can observe it by running test from the command line. > > across PHIs. This opens the room for other optimizations (like DCE), so > > some guards become eliminated, and we use out-of-bounds access from the > > array part of the table on trace. This patch adds the missing > > `PHIBARRIER()` check. > > > > Sergey Kaplun: > > * added the description and the test for the problem > > > > Part of tarantool/tarantool#9145 > > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-794-abc-fold-constants > > Tarantool PR: https://github.com/tarantool/tarantool/pull/9364 > > Related issues: > > * https://github.com/LuaJIT/LuaJIT/issues/794 > > * https://github.com/tarantool/tarantool/issues/9145 > > > > src/lj_opt_fold.c | 5 +- > > .../lj-794-abc-fold-constants.test.lua | 85 +++++++++++++++++++ > > 2 files changed, 88 insertions(+), 2 deletions(-) > > create mode 100644 test/tarantool-tests/lj-794-abc-fold-constants.test.lua > > diff --git a/test/tarantool-tests/lj-794-abc-fold-constants.test.lua b/test/tarantool-tests/lj-794-abc-fold-constants.test.lua > > new file mode 100644 > > index 00000000..f8609933 > > --- /dev/null > > +++ b/test/tarantool-tests/lj-794-abc-fold-constants.test.lua > > @@ -0,0 +1,85 @@ > > +local tap = require('tap') > > + > > +-- Test file to demonstrate LuaJIT's incorrect fold optimization > > +-- for Array Bound Check for constants. > > +-- ABC(asize, k1), ABC(asize k2) ==> ABC(asize, max(k1, k2)). > > +-- See also https://github.com/LuaJIT/LuaJIT/issues/794. > > + > > +local test = tap.test('lj-794-abc-fold-constants'):skipcond({ > > + ['Test requires JIT enabled'] = not jit.status(), > > +}) > > + > > +local MAGIC_UNUSED = 42 > > AFAIK we put all test-related stuff after "test:plan". > > Feel free to ignore. Fixed, thanks! See the iterative patch below. =================================================================== diff --git a/test/tarantool-tests/lj-794-abc-fold-constants.test.lua b/test/tarantool-tests/lj-794-abc-fold-constants.test.lua index c69d395b..53e4d2eb 100644 --- a/test/tarantool-tests/lj-794-abc-fold-constants.test.lua +++ b/test/tarantool-tests/lj-794-abc-fold-constants.test.lua @@ -9,9 +9,10 @@ local test = tap.test('lj-794-abc-fold-constants'):skipcond({ ['Test requires JIT enabled'] = not jit.status(), }) -local MAGIC_UNUSED = 42 test:plan(2) +local MAGIC_UNUSED = 42 + local function abc_check_sign() local tab = {MAGIC_UNUSED} local return_value = 0 =================================================================== Branch is force-pushed. > > > +test:plan(2) > > + > > +local function abc_check_sign() > > + local tab = {MAGIC_UNUSED} > > + local return_value = 0 > > + local abc_limit = 1 > > + -- No need to run the loop on the first call. We will take > > + -- the side exit anyway. > > + for i = 1, 3 do > > + -- Add an additional ABC check to be merged with. > > + if i > 1 then > > + -- luacheck: ignore > > + return_value = tab[1] > > + return_value = tab[abc_limit] > > + -- XXX: Just use some negative number. > > + abc_limit = -1000000 > > With -1 works too, I would replace -10^6 with -1 for simplification. Not always (I tried). I prefer to use the value from the reproducer that fails stable. Ignore for now. > > > > > -- Best regards, Sergey Kaplun