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 70D35440F5A; Wed, 10 May 2023 15:40:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 70D35440F5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1683722405; bh=3uVRXCB+XTeT5lG+C51hXQbxWKQo+uoAvpJ5oWn6mpw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=bkcmuEkrhgtd454kqcZdjO0Ayvt16QdhkBRe/thXSQFfpEQTZSXHtlTv9A0R5dpXW Jda+4kHALJkftIDZoDqbBHktxWbl2bFNT5iInrRkbQEfCHCgp8wjik8G2ZYwSe6/92 LCBesSXc5odeGJEKv6wZ15doTmrQxTtY2aJ40H6g= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4F747440F60 for ; Wed, 10 May 2023 15:39:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F747440F60 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1pwj61-0007mJ-5W; Wed, 10 May 2023 15:39:05 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Wed, 10 May 2023 15:34:59 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9EB47717F7D295292D67C76A64B1B07133F10B2F7B0DD9258182A05F538085040F4883EB25B1E39EB12CE7A47A1E6C514B09C8EE879148F3B87E9E0E27295AF6F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AF18881564A951B9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D0C488966F20D4908638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8662F722A1C495EECEB35BAF3BC6BBFB7117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCC8B02E85A1983BE4A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735200AC5B80A05675ACDF04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6B1CFA6D474D4A6A4089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A576D39EE557A767509AF4754A0BA323D85B5D7D215EBF1830F87CCE6106E1FC07E67D4AC08A07B9B0DB8A315C1FF4794DC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34E420FF71F2F0FE030DD8E26E5B4534481F8E248AB5D8A37758272FF71C9243B5BFB3FC4C1393AF031D7E09C32AA3244C8043EF3F179A4D39BC5F1A0A192A300CE646F07CC2D4F3D8927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj6KE94DszzarmngHubTQWrg== X-DA7885C5: B62C0122E4E429B7427A1874C577093131E3A3EBE881239CDFEE35B219EF1781262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73933AF1F914F131DBF52187ABC8297B6EA42242B099488A2D630FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/2] Fix canonicalization of +-0.0 keys for IR_NEWREF. 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 Reported by Sergey Kaplun. (cherry picked from commit 96fc114a7a3be3fd2c227d5a0ac53aa50cfb85d1) This commit is a follow-up for the commit f067cf638cf8987ab3b6db372d609a5982e458b5 ("Fix narrowing of unary minus."). Since this commit -0 IR constant is stored as well as +0 constant on the trace. Since IR NEWREF keys don't canonicalizied for -0 opposed of IR HREFK, it may lead to inconsistencies during trace recording. In particular, since -0 and 0 are different IR constants, alias analysis declares that they can't be aliased during folding optimization. Therefore: 1) For the IR TNEW we have non-nil value to lookup from the table via HLOAD, when only nil lookup is expected due to alias analysis. 2) For the IR TDUP we have non-nil value to lookup from the table via HLOAD, but the template table has no 0 field initiated as far as -0 isn't folding to 0 during parsing (see `bcemit_unop()` in ). These cases lead to the assertion failures in `fwd_ahload()`. This patch adds the aforementioned canonicalization. Sergey Bronnikov: * reported the original issue for the TDUP IR Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#8516 --- Side note: I don't mention the 981 issue by intend -- I don't want to bother Mike with force pushes:). I suppose Igor should add this line (if he wants) went this commit will be cherry-picked to our master branch (a.k.a. tarantool). src/lj_record.c | 2 + .../tarantool-tests/lj-981-folding-0.test.lua | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test/tarantool-tests/lj-981-folding-0.test.lua diff --git a/src/lj_record.c b/src/lj_record.c index 9e2e1d9e..cc44db8d 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -1474,6 +1474,8 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix) TRef key = ix->key; if (tref_isinteger(key)) /* NEWREF needs a TValue as a key. */ key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT); + else if (tref_isnumber(key) && tref_isk(key) && tvismzero(&ix->keyv)) + key = lj_ir_knum_zero(J); /* Canonicalize -0.0 to +0.0. */ xref = emitir(IRT(IR_NEWREF, IRT_PGC), ix->tab, key); keybarrier = 0; /* NEWREF already takes care of the key barrier. */ #ifdef LUAJIT_ENABLE_TABLE_BUMP diff --git a/test/tarantool-tests/lj-981-folding-0.test.lua b/test/tarantool-tests/lj-981-folding-0.test.lua new file mode 100644 index 00000000..251da24d --- /dev/null +++ b/test/tarantool-tests/lj-981-folding-0.test.lua @@ -0,0 +1,57 @@ +local tap = require('tap') +local test = tap.test('lj-981-folding-0'):skipcond({ + ['Test requires JIT enabled'] = not jit.status(), + ['Disabled on *BSD due to #4819'] = jit.os == 'BSD', +}) + +-- Test file to demonstrate LuaJIT misbehaviour on load forwarding +-- for -0 IR constant as table index. +-- See also, https://github.com/LuaJIT/LuaJIT/issues/981. + +local jparse = require('utils.jit_parse') + +jit.opt.start('hotloop=1') + +test:plan(4) + +-- Reset traces. +jit.flush() + +jparse.start('i') +local result +local expected = 'result' +-- TNEW: +-- -0 isn't folded during parsing, so it will be set with KSHORT, +-- UNM bytecodes. See and bytecode listing +-- for details. +-- Because of it, empty table is created via TNEW. +for _ = 1, 4 do + result = ({[-0] = expected})[0] +end + +local traces = jparse.finish() + +-- Test that there is no any assertion failure. +test:ok(result == expected, 'TNEW and -0 folding') +-- Test that there is no NEWREF -0 IR. +test:ok(not traces[1]:has_ir('NEWREF.*-0'), '-0 is canonized for TNEW tab') + +-- Reset traces. +jit.flush() + +jparse.start('i') +-- TDUP: +-- Now just add a constant field for the table to use TDUP with +-- template table instead TNEW before -0 is set. +for _ = 1, 4 do + result = ({[-0] = expected, [1] = 1})[0] +end + +traces = jparse.finish() + +-- Test that there is no any assertion failure. +test:ok(result == expected, 'TDUP and -0 folding') +-- Test that there is no NEWREF -0 IR. +test:ok(not traces[1]:has_ir('NEWREF.*-0'), '-0 is canonized for TDUP tab') + +os.exit(test:check() and 0 or 1) -- 2.34.1