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 6FD96A126F8; Wed, 31 Jan 2024 12:21:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6FD96A126F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706692870; bh=HyrqK0w5Hp8Yx7ujmwFd11kVZ23YSKE2OqLKl9MztYo=; 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=Qf+gmwzoCcd6rY7hQ75nixQc19OPWhWVgJzvjSsbldSZXCiuxBWOL/Ni2b0b5yMPS wOha7zPQcRTFynxPnqd4GWURs8POck8pKsqJNkFjvdLJBYRFD6UKaTHn2khA0imYMo umbOI+mzMzf62FcaGWSd8TITVRDsnkIbz/T4JNE4= Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [95.163.41.66]) (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 8B42B73B6FB for ; Wed, 31 Jan 2024 12:21:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8B42B73B6FB Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1rV6mJ-00000005Bfw-2s8t; Wed, 31 Jan 2024 12:21:08 +0300 Date: Wed, 31 Jan 2024 12:20:37 +0300 To: Sergey Kaplun 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: <8abb9f75b9f4b8459a6495fedb40da7da5334c9c.1706104777.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9DF1FFD52FB7F4A950B941F2BA89398A05886C6D8E2B7214600894C459B0CD1B9ED355243787E81937CA1AD9DD96B4DC9F887BF9AE1501B1652BDC463FA59D0A5DA9381C6EE66F9EA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE735102D6D0BF494F7EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EEA194BB48C104EF8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D869AAC848E4987A95C5EAE5D0C0E2D028855A0C8DECF7E214CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F3E38EE449E3E2AE389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D2DCF9CF1F528DBCF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C67F1C1C3ABB44F3A6E0066C2D8992A164AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3302A61B22DEE7324BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFED8438A78DFE0A9E1DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C3EBF4D8D28E8B690335872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A58804814D5EB0E9E15002B1117B3ED696F25A9550036B1FDB19AC5B239BAD4335823CB91A9FED034534781492E4B8EEAD1247ADC107F68C7B X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF1F058CB472FF115ABB7D38A2B5AE99E9BEC5F94E9920BB63BB6EE6F0295A906B182FB9261F6240E8BAF4CF3B87E910B1AECABB2E3119F597E17A4FE60FCD6ED83E5851ADFB25163B5F4332CA8FE04980913E6812662D5F2A54F6898A6FDCBDC72A617DFBE5FEC2C6383653B6C8D9AE0FD16FCAA6493B703A X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojHUK3TkZYwr+SOtEyWgAD8g== X-Mailru-Sender: 7940E2A4EB16C9970E7603824FE97C20ED355243787E81937CA1AD9DD96B4DC948EB99357ABFCBD4B6F7D78CE1F58EAD61AD1BC23DFB21333DDE9B364B0DF289BB83A8C3DAEBA78A61AAEF30F77CACB9EAB4BC95F72C04283CDA0F3B3F5B9367 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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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. > +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 >