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 BCDD86ECE2; Thu, 26 Nov 2026 11:39:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BCDD86ECE2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795682368; bh=KNOSvApxYwS9oqED4rbxmDKWt9I3CdypDRR8ywrTf58=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=dFMGNzV7EWhwBNMbAoda86r9XA2T1EBmL+gV95W5jww25JiPUXQh1jcNv2bJ0EU3a jktQmOkj9JPGUS/mOqO896VuZkT2VHMEMjTfwY4Kkb/ftbLUIIlRQk3TFUrCr4Sgs7 La5tol11ysdihL5ppr+Oy8JW9ijb6+2NG2kUBwfQ= Received: from send35.i.mail.ru (send35.i.mail.ru [89.221.237.130]) (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 7184D6ECE2 for ; Thu, 26 Nov 2026 11:39:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7184D6ECE2 Received: by exim-smtp-canary-30-77684c7744-v2cml with esmtpa (envelope-from ) id 1xWV0o-000000000qJ-0PDm; Thu, 26 Nov 2026 11:39:26 +0300 To: Evgeniy Temirgaleev , Sergey Bronnikov Date: Thu, 26 Nov 2026 11:41:42 +0300 Message-ID: <20261126084142.2217311-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.56.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9FEBD707FEFA486A941E6196853E2486657F21DD43821BAF2CD62213F67905E7A29DCA11868768C86E52BE880F0397792250573C3F91D2D753C9C5F1433576771C5C7FD16981B76AE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE741DC22BF90A736D8EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566597B7DDA0B2A6E4BAE3C8169E9BEC6C04853AA7E0A4D20EE4ED3C1D325EEC547389733CBF5DBD5E9D5E8D9A59859A8B6AEEA5BB16A939343CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE74F0F518E68DBD4F843847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A5073794C248FCB7085002B1117B3ED6969DCEC216ACEB4C2E33EE06AFCD964888823CB91A9FED034534781492E4B8EEAD2F8D89FC5850081EC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F9677DD89D51EBB774225B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659457E7AF9D36E56115899A72937FA24E92F87DD1F2FDB23CEC8049E675C7FB02572B9C08DF4CB53E3B8341EE9D5BE9A0A31D2AA28C501367A1DF7A5010E99F566334993D7A89A1F4DC7CEAA0681F5848F4C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWDPBDndPPTPAl/VZul3y37o= X-Mailru-Sender: 689FA8AB762F73937C9FA53A4753B31337F5C47EA0E0915AA84362E38C411943C7C1C41E7D8122EAE49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] ARM64: Fix BC_JFORI on empty FP range. 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 denesik. (cherry picked from commit 2c9f5cf62ca9232d1aa3271f8e9c1799dd0f63d3) `BC_JFORI` bytecode either jumps to the trace (`BC_JLOOP`) or should proceed to the next instruction for the empty range. For this the integer variant of the instruction moves to the `PC` (next bytecode to be executed) the adjusted bytecode position after jump, which is stored in `RC`. The floating point path of the instruction misses this fixup, so the FP loop variant executes the loop body 1 time instead of 0 for an empty range. This patch fixes this by adding the missing fixup. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#13442 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1530-fix-jfori-empty-step Related issues: * https://github.com/LuaJIT/LuaJIT/issues/1530 * https://github.com/tarantool/tarantool/issues/13442 src/vm_arm64.dasc | 1 + .../lj-1530-fix-jfori-empty-step.test.lua | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/tarantool-tests/lj-1530-fix-jfori-empty-step.test.lua diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc index 4ffd7378..41688252 100644 --- a/src/vm_arm64.dasc +++ b/src/vm_arm64.dasc @@ -3650,6 +3650,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) if (op == BC_FORI) { | csel PC, RC, PC, hi } else if (op == BC_JFORI) { + | mov PC, RC | ldrh RCw, [RC, #-4+OFS_RD] | bls =>BC_JLOOP } else if (op == BC_IFORL) { diff --git a/test/tarantool-tests/lj-1530-fix-jfori-empty-step.test.lua b/test/tarantool-tests/lj-1530-fix-jfori-empty-step.test.lua new file mode 100644 index 00000000..a91780ec --- /dev/null +++ b/test/tarantool-tests/lj-1530-fix-jfori-empty-step.test.lua @@ -0,0 +1,38 @@ +local tap = require('tap') + +-- The test file to demonstrate an incorrect LuaJIT handling of +-- JFORI loop setup for the empty numeric loops. This test fails +-- on ARM64 in particular, but it is worth checking for all +-- architectures. +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1530. +local test = tap.test('lj-1530-fix-jfori-empty-step'):skipcond({ + ['Test requires JIT enabled'] = not jit.status(), +}) + +test:plan(2) + +-- Function to wrap the recorded FORI instruction. +local function loop_fori(limit) + local cnt = 0 + -- Use `1.1` to force a numeric loop. We may use a non-integer + -- limit for this, and then we end up on the same path after + -- `lj_meta_for()` casting the loop start index from integer to + -- double. But the current path is just simpler. + -- The loop body shouldn't be taken due to the empty range in + -- this test. + for _ = 1.1, limit do cnt = cnt + 1 end + return cnt +end + +-- Check the interpreter just in case. +test:is(loop_fori(0), 0, 'correct interpreter FORI loop skip') + +jit.opt.start('hotloop=1') + +-- Compile the loop. +loop_fori(4.1) + +-- Run the empty loop range with the compiled instruction. +test:is(loop_fori(0), 0, 'correct JFORI loop skip') + +test:done(true) -- 2.56.0