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 5E3D5F1A9B1; Fri, 10 Jan 2025 16:08:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5E3D5F1A9B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1736514533; bh=7btCZfkQr56PKdH/xuszZR28fgCHSQRBssi8gzKWxKE=; 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=CaUDnnSfqkyZsyFzZ2zycPDugfz2P4d0mG67AnUQq6C2BibIhlFOrwduwyFD2R7Yp DcU1oUZVm5BIxb4l7+VmUdJDFhBJEBPB4RtW6CCccEn2pJU88i2l/hfiFBbbUQ0FVi Yy0R9Vh9O6ospoNB1lCPQTZCnS1Kkd+fn2yHWFUg= Received: from send242.i.mail.ru (send242.i.mail.ru [95.163.59.81]) (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 6CA4FF1A99F for ; Fri, 10 Jan 2025 16:08:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6CA4FF1A99F Received: by exim-smtp-bcf9586c5-mw6cv with esmtpa (envelope-from ) id 1tWEkP-00000000Ued-23Na; Fri, 10 Jan 2025 16:08:21 +0300 To: Sergey Bronnikov Date: Fri, 10 Jan 2025 16:07:44 +0300 Message-ID: <9ac2f3e63dc202d948d8b7f38ac3540682fc398b.1736509260.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD97C62A2C8925CC647404788BFDB7838E742B8BAB015971D55182A05F538085040EF404EAD70D217073DE06ABAFEAF670525E065DB88D01CD9D3E5D342215B9A648CF6EBAD94FE6CB9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73B44982FA5E78411EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637FBDDB35DE4C816078638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BB9CBE9F2EBA8E303BDF672ABC45C8FE5BFDB0333DFD93C8CC7F00164DA146DAFE8445B8C89999728AA50765F79006370D9A29B7FD16D1239FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C390D92131081DE748117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006371F24DFF1B2961425731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5D7622262CFE2B36C5002B1117B3ED6964D07A8EB2DEE903C250A03108B67251B823CB91A9FED034534781492E4B8EEAD2B25D9E4C92BC8ACC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFF8ABFA1A0ED400890AF06C72E8409DF5FB72AC13DF0C134104A30BE7FA1E5CAD6238D603D2F19CCF6BAACDEF235ECA6E567C46FF46D19DD5D7101C3931F3FA3CCC4A8C0A329609A95F4332CA8FE04980913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojXhNIkWce4y3QkaY8dgWecw== X-DA7885C5: 23DCE12391D6BE24F255D290C0D534F95C35CEB25D7A8794D4C8C4FF4DA9534885D9A7131FCD11995B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F739381B31377CF4CA219A63A19342FC5EF91DFCB6B24D75F5A4ECA83B518996DB1A0E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/4] x86/x64: Don't fuse loads across table.clear. 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 Peter Cawley. (cherry picked from commit 45c88b7963de2969a9a656c03ba06ad995d7fd5f) Load fusing optimization takes into account only the presence of the corresponding stores, but not any calls that may affect the table content. This may lead to the incorrect stores if the fusing optimization occurs across the `table.clear()` call, leading to inconsistent behaviour between the JIT and the VM. This patch adds the corresponding check. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#10709 --- src/lj_asm_x86.h | 1 + .../lj-1117-fuse-across-table-clear.test.lua | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/tarantool-tests/lj-1117-fuse-across-table-clear.test.lua diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index 86ce3937..f47c460a 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h @@ -465,6 +465,7 @@ static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow) } } else if (ir->o == IR_ALOAD || ir->o == IR_HLOAD || ir->o == IR_ULOAD) { if (noconflict(as, ref, ir->o + IRDELTA_L2S, 0) && + noconflict(as, ref, IR_CALLS, 0) && /* Don't cross table.clear. */ !(LJ_GC64 && irt_isaddr(ir->t))) { asm_fuseahuref(as, ir->op1, xallow); return RID_MRM; diff --git a/test/tarantool-tests/lj-1117-fuse-across-table-clear.test.lua b/test/tarantool-tests/lj-1117-fuse-across-table-clear.test.lua new file mode 100644 index 00000000..2f7c91d1 --- /dev/null +++ b/test/tarantool-tests/lj-1117-fuse-across-table-clear.test.lua @@ -0,0 +1,36 @@ +local tap = require('tap') +-- Test file to demonstrate LuaJIT's incorrect fusion across +-- `table.clear()`. +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1117. +local test = tap.test('lj-1117-fuse-across-table-clear'):skipcond({ + ['Test requires JIT enabled'] = not jit.status(), +}) + +local ffi = require('ffi') +local table_clear = require('table.clear') + +test:plan(1) + +local tab = {0} +local alias_tab = tab +local result_tab = {} + +jit.opt.start('hotloop=1') + +for i = 1, 4 do + -- Load to be fused. + local value = tab[1] + -- Clear the alias table to trick the code flow analysis. + table_clear(alias_tab) + -- Need this cast to trigger load fusion. See `asm_comp()` for + -- the details. Before the patch, this fusion takes the + -- incorrect address of the already cleared table, which leads + -- to the failure of the check below. + result_tab[i] = ffi.cast('int64_t', value) + -- Revive the value. + tab[1] = 0 +end + +test:samevalues(result_tab, 'no fusion across table.clear') + +test:done(true) -- 2.47.1