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 B907E96BF5F; Mon, 22 Jan 2024 14:08:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B907E96BF5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1705921682; bh=enLobqvY0NyMloz24P9ko+/bVk2cuFhTx/bg4DSG760=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uKK4ReapvwGLpDd+IefKD20cKLIUku4ATt3ADs1Kbj8FladT0xUhTfVnz++w3gybL kVvHYMFDqzsqofb5uv9hBkmqp+NkQvmXQLt9FKVqR8/wsz7pfjc6hycBrkq/N6uGq4 3WwBADW3VMwzvdpoxPCRFD3RFo73Qab0M+wKkk+8= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [95.163.41.85]) (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 9FA5796BF5F for ; Mon, 22 Jan 2024 14:08:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9FA5796BF5F Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1rRs9o-001XnQ-0N; Mon, 22 Jan 2024 14:08:00 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 22 Jan 2024 14:03:44 +0300 Message-ID: <20240122110344.5401-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9AE5B4AFB3AE2A590AC49F3668DF3AF4BBF6B994171853288182A05F538085040FA4F8A81290A4F0BA5A9EC6A25DC1B9D6AD93FC712BE19E04CDD8FF2A4A7AFFA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C6068CE86C2B75F5EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748E7A03516F25E8E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82D9DE876C3F620C42C8E1FE2F9EA76B9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE26055571C92BF10F098B145E00970258D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE32D01283D1ACF37BAC0837EA9F3D19764C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CD2DCF9CF1F528DBC2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FB26E97DCB74E6252CE5475246E174218B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A551774EE9FB1A7702BE55FA762D10D865D532CED00A8A2ACDF87CCE6106E1FC07E67D4AC08A07B9B0E753FA5741D1AD029C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF77DD89D51EBB7742D3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF81F4A6A9305A64E5586ED6C560D57D010C1E6B2C07EDB29AD648C9E5D949DCB708FC8DA71D385488E78510D816E477F336CFF70DFF32D756077257AA26E855D7A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojI4eqBx/cvLmkqtQGVqpjjw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7694C208110E30B9A87A5A9EC6A25DC1B9DB9A8FEFFB5F7F2D5DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: [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 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" 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) -- 2.43.0