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 32D869ABE9B; Thu, 25 Jan 2024 10:57:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 32D869ABE9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706169446; bh=frtOIkan8eRYwBWYuRVIiCb5SeSiI8xl/I5/DzjvNDo=; 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=vds4IHG8Lud3dlnXaudgGhony9S1GmW73RPYIEx/WeyR8Nb1l/b955CsrdluV22Lh lELWorsIPxlP4iqI6rZb1a7omOP49YUed9Jz8TdhlNEtXOPqE1f8ks9aslhCrrUbtg RtE27RfMSUXQSy3xKZf+6lapCFfVieTqmf2nLC64= Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [95.163.41.89]) (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 54AC59ABEA0 for ; Thu, 25 Jan 2024 10:57:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 54AC59ABEA0 Received: by smtp54.i.mail.ru with esmtpa (envelope-from ) id 1rSubo-00C8be-2x; Thu, 25 Jan 2024 10:57:13 +0300 Message-ID: <0f39d994-a308-4c35-9bc2-3405fedd5072@tarantool.org> Date: Thu, 25 Jan 2024 10:57:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <20240122110344.5401-1-skaplun@tarantool.org> In-Reply-To: <20240122110344.5401-1-skaplun@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9E62ABF8986B18E620EA089B3A140F95D2C784B27FED6762D1313CFAB8367EF908E2BE116634AD74D049BAB636DC76D5B52BC57A1C1C704B302DA2C1D243E3C51BDDA091DB0BAA87C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE742D9BD90C58D50E0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378BCFB34D7DDF138E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D86FBA54110327527D035A1D02B63BD985117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE26055571C92BF10F7B089FF177BE8049D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE32D01283D1ACF37BAAD7EC71F1DB88427C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947C062BEEFFB5F8EA3E2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F9FFED5BD9FB4175535872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A54D44DC1C8FB13BC8DBFC865278AE308EA7897EBE7B5906A9F87CCE6106E1FC07E67D4AC08A07B9B0BC0ADEB1C81BB362CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFD36C4B96B1A0F568153ACDEED881AF604628D6FFE5A0A9DE64E4393D005D13E71230ACE34F2D113D4BEAD515961AA0A7525CCADE9157329EEB30DF24FE5E2EEAE48CAC7CA610320002C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojjPo90oGNxwJRIc41Him3qA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7693F34F730FBCD92E739B91EE879628DBDBA0848438379BFCEEBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF 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! LGTM 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)