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 CB011A4A101; Wed, 31 Jan 2024 12:40:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CB011A4A101 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706694036; bh=Y9+fh18az81JA/Q41m3Am+QcqSmiGEV0qnLpwbGVRTs=; 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=cVvvlXLsIBcOJxf5ezq1RFnI5pfJu16iexw/3rqEz1gFPl1/DgukMx3e3Fp8LTqxf DM20OtEjyPpuYwBZRysO0AUoq81ULGbhxywybwel9b6URHqG95rQIWV4I2Oxn0EOYN 33et2tHupoTNwu2S+BLxsn7SF5s3csKySsmmiboE= Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [95.163.41.81]) (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 99E82A4A112 for ; Wed, 31 Jan 2024 12:40:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 99E82A4A112 Received: by smtp40.i.mail.ru with esmtpa (envelope-from ) id 1rV757-00000004zxI-2SFG; Wed, 31 Jan 2024 12:40:34 +0300 Date: Wed, 31 Jan 2024 12:36:39 +0300 To: Maxim Kokryashkin Message-ID: References: <8abb9f75b9f4b8459a6495fedb40da7da5334c9c.1706104777.git.skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD93C58C36AA2E996499EFE771C80A3C579767E15D2D4E86957182A05F5380850404C228DA9ACA6FE27775F00FE0212C4EFD4FF92D56319F19799D999716E7B0848B7E981CA8D6799F21AD6A186BD11839C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE757F64E7FD849EB4FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063764FE777F378F21448638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8DB6AA423DB7B17B5EDEF27999913E80954BDB49BEFA900A3CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F3E38EE449E3E2AE389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8062BEEFFB5F8EA3EF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CF8BD4E506CFA3D88C0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3D8561A2FEC730ACEBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF17B107DEF921CE791DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C3483320834B361D1F089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A50EADE9E3D1D3B3175002B1117B3ED69669DE57A7DC48CA72219207EC0A953D2C823CB91A9FED034534781492E4B8EEADA7AC412AE061D850BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF6D2DC6529A755382C518779F7B23847C9575624A3727BC5818BC2D9626484BB6BA297A5F7262141FBAF4CF3B87E910B18872AA02B0CEFE03CA69B38C212BCFA111292F91683552145F4332CA8FE04980913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojHUK3TkZYwr/pBW9wG0LTGQ== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7691B6803906B22FD4AD4FF92D56319F19799D999716E7B0848B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Optimize table.new() with constant args to (sinkable) IR_TNEW. 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! Fixed your comment and force-pushed the branch. On 31.01.24, Maxim Kokryashkin wrote: > Hi, Sergey! > Thanks for the patch! > > Very thorough testing! > > LGTM, except for a minor comment below. > > On Wed, Jan 24, 2024 at 05:11:08PM +0300, Sergey Kaplun wrote: > > From: Mike Pall > > > > Thanks to Peter Cawley. > > > > (cherry picked from commit d1236a4caa999b29e774ef5103df3b424d821d9b) > > > > This patch adds optimization for calls of `table.new()` with constant > > argument refs when asize is in the proper range (i.e., is less than IR > > operand width). The call is replaced with IR TNEW. This opens up > > opportunities for other optimizations in the pipeline. > > > > Sergey Kaplun: > > * added the description and the test for the feature > > > > Part of tarantool/tarantool#9595 > > > > > diff --git a/test/tarantool-tests/lj-1128-table-new-opt-tnew.test.lua b/test/tarantool-tests/lj-1128-table-new-opt-tnew.test.lua > > new file mode 100644 > > index 00000000..805e6de6 > > --- /dev/null > > +++ b/test/tarantool-tests/lj-1128-table-new-opt-tnew.test.lua > > @@ -0,0 +1,112 @@ > > +local tap = require('tap') > > +local test = tap.test('lj-1128-table-new-opt-tnew'):skipcond({ > > + ['Test requires JIT enabled'] = not jit.status(), > > + ['Disabled on *BSD due to #4819'] = jit.os == 'BSD', > > +}) > > + > > +-- Test LuaJIT optimization when a call to the `lj_tab_new_ah()` > > +-- is replaced with the corresponding TNEW IR. > > +-- See also https://github.com/LuaJIT/LuaJIT/issues/1128. > > + > > +local jparse = require('utils').jit.parse > > + > > +-- API follows the semantics of `lua_createtable()`. > > +local table_new = require('table.new') > > + > > +-- `hbits` for different `hsizes`, see for details. > > +local HBITS = { > > + [1] = 1, > > + [3] = 2, > > +} > > + > > +-- XXX: Avoid any other traces compilation due to hotcount > > +-- collisions for predictable results. > > +jit.off() > > +jit.flush() > > + > > +test:plan(10) > > + > > +jit.on() > > +jit.opt.start('hotloop=1') > > +jparse.start('i') > > + > > +local anchor > > + > > +for _ = 1, 4 do > > + anchor = table_new(1, 1) > > +end > > + > > +local traces = jparse.finish() > > +jit.off() > > + > > +test:ok(type(anchor) == 'table', 'base result') > I would prefer the assertions for the type to have different > descritions for each test case. This way it is easier to tell > which test you need to focus on, if one of them fails. Here > and below. Yes, sure! See the iterative patch below. Branch is force-pushed. =================================================================== diff --git a/test/tarantool-tests/lj-1128-table-new-opt-tnew.test.lua b/test/tarantool-tests/lj-1128-table-new-opt-tnew.test.lua index 805e6de6..bba160ea 100644 --- a/test/tarantool-tests/lj-1128-table-new-opt-tnew.test.lua +++ b/test/tarantool-tests/lj-1128-table-new-opt-tnew.test.lua @@ -39,7 +39,7 @@ end local traces = jparse.finish() jit.off() -test:ok(type(anchor) == 'table', 'base result') +test:ok(type(anchor) == 'table', 'type check base result') test:ok(traces[1]:has_ir(('TNEW.*#2.*#%d'):format(HBITS[1])), 'base IR value') jit.flush() @@ -55,7 +55,7 @@ end traces = jparse.finish() jit.off() -test:ok(type(anchor) == 'table', 'base result') +test:ok(type(anchor) == 'table', 'type check 0 asize, 0 hsize') test:ok(traces[1]:has_ir('TNEW.*#0.*#0'), '0 asize, 0 hsize') jit.flush() @@ -71,7 +71,7 @@ end traces = jparse.finish() jit.off() -test:ok(type(anchor) == 'table', 'base result') +test:ok(type(anchor) == 'table', 'type check 3 hsize -> 2 hbits') test:ok(traces[1]:has_ir(('TNEW.*#0.*#%d'):format(HBITS[3])), '3 hsize -> 2 hbits') @@ -88,7 +88,7 @@ end traces = jparse.finish() jit.off() -test:ok(type(anchor) == 'table', 'base result') +test:ok(type(anchor) == 'table', 'type check negative asize') test:ok(traces[1]:has_ir('TNEW.*#0.*#0'), 'negative asize') jit.flush() @@ -104,7 +104,7 @@ end traces = jparse.finish() jit.off() -test:ok(type(anchor) == 'table', 'base result') +test:ok(type(anchor) == 'table', 'type check asize out of range') -- Test that TNEW isn't emitted for `asize` bigger than the IR -- operand width (>0x8000). test:ok(not traces[1]:has_ir('TNEW'), 'asize out of range') =================================================================== > > +test:ok(traces[1]:has_ir(('TNEW.*#2.*#%d'):format(HBITS[1])), 'base IR value') > > + > > +jit.flush() > > +jit.on() > > +-- XXX: Reset hotcounters. > > +jit.opt.start('hotloop=1') > > +jparse.start('i') > > + > > +for _ = 1, 4 do > > + anchor = table_new(0, 0) > > +end > > + > > +traces = jparse.finish() > > +jit.off() > > + > > +test:ok(type(anchor) == 'table', 'base result') > > +test:ok(traces[1]:has_ir('TNEW.*#0.*#0'), '0 asize, 0 hsize') > > + > > +jit.flush() > > +jit.on() > > +-- XXX: Reset hotcounters. > > +jit.opt.start('hotloop=1') > > +jparse.start('i') > > + > > +for _ = 1, 4 do > > + anchor = table_new(0, 3) > > +end > > + > > +traces = jparse.finish() > > +jit.off() > > + > > +test:ok(type(anchor) == 'table', 'base result') > > +test:ok(traces[1]:has_ir(('TNEW.*#0.*#%d'):format(HBITS[3])), > > + '3 hsize -> 2 hbits') > > + > > +jit.flush() > > +jit.on() > > +-- XXX: Reset hotcounters. > > +jit.opt.start('hotloop=1') > > +jparse.start('i') > > + > > +for _ = 1, 4 do > > + anchor = table_new(-1, 0) > > +end > > + > > +traces = jparse.finish() > > +jit.off() > > + > > +test:ok(type(anchor) == 'table', 'base result') > > +test:ok(traces[1]:has_ir('TNEW.*#0.*#0'), 'negative asize') > > + > > +jit.flush() > > +jit.on() > > +-- XXX: Reset hotcounters. > > +jit.opt.start('hotloop=1') > > +jparse.start('i') > > + > > +for _ = 1, 4 do > > + anchor = table_new(0xffff, 0) > > +end > > + > > +traces = jparse.finish() > > +jit.off() > > + > > +test:ok(type(anchor) == 'table', 'base result') > > +-- Test that TNEW isn't emitted for `asize` bigger than the IR > > +-- operand width (>0x8000). > > +test:ok(not traces[1]:has_ir('TNEW'), 'asize out of range') > > + > > +test:done(true) > > -- > > 2.43.0 > > -- Best regards, Sergey Kaplun