From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Maxim Kokryashkin <m.kokryashkin@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Optimize table.new() with constant args to (sinkable) IR_TNEW. Date: Wed, 31 Jan 2024 12:36:39 +0300 [thread overview] Message-ID: <ZboUpw78uofG_6Gu@root> (raw) In-Reply-To: <rsimxjijirspekk4yaxn7vl2rp67fgjqx57kihaj5uymopc76d@5khe4fysq724> 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 <mike> > > > > 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 > > <snipped> > > > 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 <lj_tab.h> 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
next prev parent reply other threads:[~2024-01-31 9:40 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-01-24 14:11 [Tarantool-patches] [PATCH luajit 0/2] Fix unsinking TNEW with huge asize Sergey Kaplun via Tarantool-patches 2024-01-24 14:11 ` [Tarantool-patches] [PATCH luajit 1/2] Optimize table.new() with constant args to (sinkable) IR_TNEW Sergey Kaplun via Tarantool-patches 2024-01-31 9:20 ` Maxim Kokryashkin via Tarantool-patches 2024-01-31 9:36 ` Sergey Kaplun via Tarantool-patches [this message] 2024-02-05 14:39 ` Sergey Bronnikov via Tarantool-patches 2024-01-24 14:11 ` [Tarantool-patches] [PATCH luajit 2/2] Only emit proper parent references in snapshot replay Sergey Kaplun via Tarantool-patches 2024-01-31 9:29 ` Maxim Kokryashkin via Tarantool-patches 2024-02-06 9:46 ` Sergey Bronnikov via Tarantool-patches 2024-02-06 10:07 ` Sergey Kaplun via Tarantool-patches 2024-02-06 11:07 ` Sergey Bronnikov via Tarantool-patches 2024-02-06 11:41 ` Sergey Kaplun via Tarantool-patches 2024-02-08 14:12 ` Sergey Bronnikov via Tarantool-patches 2024-02-15 13:45 ` [Tarantool-patches] [PATCH luajit 0/2] Fix unsinking TNEW with huge asize Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ZboUpw78uofG_6Gu@root \ --to=tarantool-patches@dev.tarantool.org \ --cc=m.kokryashkin@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 1/2] Optimize table.new() with constant args to (sinkable) IR_TNEW.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox