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 2500697D2CC; Tue, 23 Jan 2024 11:04:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2500697D2CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1705997063; bh=EGTAGdlhqQm4damqZdmAoX58OxusZeTdherHeNIngRM=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=JCkYtsaTCzuHVPTrX+7PaYPz05MdMxXM6ySHR7UUTIFJOACvltZVU7ED+HvtYh1j1 x219PO/xge5f07iZ4+I0VGHIoNzz8ZlvTuHWzG5H53zIxIyXuN1DIgARGuOxGyIJ2/ d+RAjKfHT4EsE+YDSDKjRoguYA44JRyT4yRuYso4= Received: from smtp59.i.mail.ru (smtp59.i.mail.ru [95.163.41.97]) (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 B78AF6DDCEE for ; Tue, 23 Jan 2024 11:04:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B78AF6DDCEE Received: by smtp59.i.mail.ru with esmtpa (envelope-from ) id 1rSBlc-00FBAH-1Z; Tue, 23 Jan 2024 11:04:20 +0300 Message-ID: Date: Tue, 23 Jan 2024 11:04:20 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <20240122110344.5401-1-skaplun@tarantool.org> Content-Language: en-US In-Reply-To: <20240122110344.5401-1-skaplun@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9AE5B4AFB3AE2A5904EC891EEB881DF0AF65B18B424229B5F182A05F5380850406623F26B501799040F4D8FCE78F0F357966A124C54052484AD281285CFA7F5A9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AD2F2D6F6013FF7FC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE76AB1B6FB25ACEDC9EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B73AB1701401CD871BBEC3E6906518CAD963D72C34D218320CC7F00164DA146DAFE8445B8C89999728AA50765F7900637D0FEED2715E18529389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC81D471462564A2E19F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C86A7C529F68B8E5CC0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3E9BD6149E9909983BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFED8438A78DFE0A9E1DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C3EB9EA62DB0D2896935872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5EA165D6D1F454A8893C896B22E6AD1CFBC9D70AD38F4B40CF87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FACB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF2EDE8696AD8E88CB1ADC3DB876BB993500F83E35E9110503834480E14EAAD67C3066587AC4ADAE824BEAD515961AA0A75A6826990AEBAE2814061DBCFD905C85E48CAC7CA610320002C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojI4eqBx/cvLm7oMPIbgEUeg== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458273DFBF3719768617E42BD1670C699C0E7D750CB4E4087D8282EC151BADDC1D3523A6D01B4765B2DFB59E2DDD9FE06B14FA522850F29BC30B0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Simplify handling of instable types in TNEW/TDUP load forwarding. 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! thanks for the patch! Everything is fine, but a have a question - test reproduces a problem with GC32 only, I couldn't reproduce it with GC64. Is it expected? As I got it right, the problem is not GC-specific. Used CMake options: CMAKE_BUILD_TYPE="Debug" CMAKE_C_COMPILER="clang" CMAKE_EXPORT_COMPILE_COMMANDS:BOOL="TRUE" LUAJIT_ENABLE_COVERAGE:BOOL="TRUE" LUAJIT_ENABLE_GC64:BOOL="TRUE" LUAJIT_USE_ASAN:BOOL="TRUE" LUAJIT_USE_SYSMALLOC:BOOL="TRUE" LUA_USE_APICHECK:BOOL="TRUE"   LUA_USE_ASSERT:BOOL="TRUE" Sergey On 1/22/24 14:03, Sergey Kaplun wrote: > From: Mike Pall > > Thanks to Peter Cawley. > > (cherry picked from commit c42c62e71a45a677b8b1cbf749bd33cf4d5918ff) > > This patch is a follow-up for the commit > b89186cb03e79359847cdbeb000a830cc464db35 ("Fix handling of instable > types in TNEW/TDUP load forwarding."). The problem still occurs when > TDUP load forwarding is performed for the boolean value. The > `fwd_ahload()` always takes the type of IR without checking the type of > the TValue for this iteration. > > This patch solves the issue by returning the expected type of the TValue > from the constant table (or `nil` for TNEW IR) instead. In the case of > type instability, the error in `loop_unroll()` will be raised, and the > loop will be unrolled for one more iteration to prevent inconsistencies. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9595 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-994-instable-pri-types > Tarantool PR: https://github.com/tarantool/tarantool/pull/9608 > Related issues: > * https://github.com/tarantool/tarantool/issues/9595 > * https://github.com/LuaJIT/LuaJIT/issues/994 > > src/lj_opt_mem.c | 20 +++++++++---------- > ...instable-types-during-loop-unroll.test.lua | 15 +++++++++++++- > 2 files changed, 23 insertions(+), 12 deletions(-) > > diff --git a/src/lj_opt_mem.c b/src/lj_opt_mem.c > index 24a490d5..9044f09a 100644 > --- a/src/lj_opt_mem.c > +++ b/src/lj_opt_mem.c > @@ -217,25 +217,23 @@ static TRef fwd_ahload(jit_State *J, IRRef xref) > } > ref = store->prev; > } > - if (ir->o == IR_TNEW && !irt_isnil(fins->t)) > - return 0; /* Type instability in loop-carried dependency. */ > - if (irt_ispri(fins->t)) { > - return TREF_PRI(irt_type(fins->t)); > - } else if (irt_isnum(fins->t) || (LJ_DUALNUM && irt_isint(fins->t)) || > - irt_isstr(fins->t)) { > + /* Simplified here: let loop_unroll() figure out any type instability. */ > + if (ir->o == IR_TNEW) { > + return TREF_NIL; > + } else { > TValue keyv; > cTValue *tv; > IRIns *key = IR(xr->op2); > if (key->o == IR_KSLOT) key = IR(key->op1); > lj_ir_kvalue(J->L, &keyv, key); > tv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv); > - if (itype2irt(tv) != irt_type(fins->t)) > - return 0; /* Type instability in loop-carried dependency. */ > - if (irt_isnum(fins->t)) > + if (tvispri(tv)) > + return TREF_PRI(itype2irt(tv)); > + else if (tvisnum(tv)) > return lj_ir_knum_u64(J, tv->u64); > - else if (LJ_DUALNUM && irt_isint(fins->t)) > + else if (tvisint(tv)) > return lj_ir_kint(J, intV(tv)); > - else > + else if (tvisgcv(tv)) > return lj_ir_kstr(J, strV(tv)); > } > /* Othwerwise: don't intern as a constant. */ > diff --git a/test/tarantool-tests/lj-994-instable-types-during-loop-unroll.test.lua b/test/tarantool-tests/lj-994-instable-types-during-loop-unroll.test.lua > index f240bdd2..a0cc8487 100644 > --- a/test/tarantool-tests/lj-994-instable-types-during-loop-unroll.test.lua > +++ b/test/tarantool-tests/lj-994-instable-types-during-loop-unroll.test.lua > @@ -10,7 +10,7 @@ local test = tap.test('lj-994-instable-types-during-loop-unroll'):skipcond({ > > -- TODO: test that compiled traces don't always exit by the type > -- guard. See also the comment for the TDUP test chunk. > -test:plan(2) > +test:plan(3) > > -- TNEW. > local result > @@ -46,4 +46,17 @@ for _ = 1, 5 do > end > test:is(result, true, 'TDUP load forwarding was successful') > > +-- TDUP, primitive types. > +for i = 1, 5 do > + local t = slot > + -- Now use constant key slot to get necessary branch. > + -- LJ_TRERR_GFAIL isn't triggered here. > + -- See `fwd_ahload()` in for details. > + result = t[1] > + -- The constant tables should contain different booleans > + -- (primitive types). > + slot = i % 2 ~= 0 and {false} or {true} > +end > +test:is(result, true, 'TDUP load forwarding (primitive types) was successful') > + > test:done(true)