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 053EF6E1EA; Mon, 23 Nov 2026 18:26:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 053EF6E1EA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795447575; bh=+vYl3BdJqipglTe+XOkSuNQS1CGPSdqcwEmfr5I2TJk=; 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=BpNpGKMqkx86ET0u6CXuxWU50bshfW9QqaOPdLl954C8YvQ9XM72V2Jk05sOX4akW HFlOC0bmcdZI7CH4HFPmQxoGRxLToa+huIPr3f2k6/FS85YmOmzbCD3azVxvFNhFmh sEh4CIV3MY5oiV/HFpHNvh/tDPVasSxzvHzVDIzk= Received: from send279.i.mail.ru (send279.i.mail.ru [95.163.59.118]) (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 0C40C6E1EA for ; Mon, 23 Nov 2026 18:26:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0C40C6E1EA Received: by exim-smtp-canary-10-7cf57c478c-lmgt2 with esmtpa (envelope-from ) id 1xVVvo-00000000Keq-3HQq; Mon, 23 Nov 2026 18:26:13 +0300 Message-ID: <540be66d-e2bc-482a-a249-272713f9f093@tarantool.org> Date: Mon, 23 Nov 2026 18:26:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun , Evgeniy Temirgaleev Cc: tarantool-patches@dev.tarantool.org References: <20261118142242.3718800-1-skaplun@tarantool.org> Content-Language: en-US In-Reply-To: <20261118142242.3718800-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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9DFC18640EC98209703E8B5906970944D8A471D4BE3ED6CA7182A05F538085040A4F275CD7D518E753DE06ABAFEAF670514A60F74C47B6B31D7E95FB67D542C5C0168CBECDA868FB9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AED985C8E545F588EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756603DA5D6BE41EFC0D74689662A7C53AB8843FDC03B781ABE207B81AADAEF5D11E389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE75B51C8FB0C3E748C731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5A767D21D642E80325002B1117B3ED6967380320B4EB113B447A99E6294EE8661823CB91A9FED034534781492E4B8EEADD0953842B444AAC3BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F96AB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D65966911F3BB53CAC76958D4A5D9BC98A7FE645894FFB0EE27E24D94F8A05DF5D4C79DB63267256701DB8341EE9D5BE9A0AAE820DE6850DC96F933C7E3E924A3A487AC07336242F58776536EB022892E5344C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWBNtEsqrCpTa3KofJT2Itw4= X-Mailru-Sender: 689FA8AB762F73937C9FA53A4753B31341F61B2FADB05420973E936DE4F4ADE3F651947665AE9741EF86D5F70DA33880E41E8EF7A07863ECB274557F927329BE2DDF8182D28ACDB545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] x86/x64: Don't sink IR_CONV num.int with -O-dce. 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 Sergey On 11/18/26 17:22, Sergey Kaplun wrote: > From: Mike Pall > > Reported by aleksisch. Thanks to Sergey Kaplun. > > (cherry picked from commit 592f9e3f549c7f176a9a7a0d70189559305f2eda) > > The CONV num.int is sunk even with disabled DCE optimization (which is > required for sink optimization). Hence, the register allocated for CONV > IR is the same as for the next IR (ADD, for example). This leads to the > incorrect results when exiting to the interpreter since the register > content is modified by the next instruction. > > This patch fixes this by disabling sinking of the `IR_CONV` with > disabled DCE. > > 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-1537-conv-sink-without-dce > Related issues: > * https://github.com/LuaJIT/LuaJIT/issues/1537 > * https://github.com/tarantool/tarantool/issues/13442 > > Side note: macOS (x86_64) CI is red due to runner problems. > > src/lj_asm.c | 3 +- > .../lj-1537-conv-sink-without-dce.test.lua | 38 +++++++++++++++++++ > 2 files changed, 40 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/lj-1537-conv-sink-without-dce.test.lua > > diff --git a/src/lj_asm.c b/src/lj_asm.c > index f163b2e3..a4d6cf3f 100644 > --- a/src/lj_asm.c > +++ b/src/lj_asm.c > @@ -933,7 +933,8 @@ static void asm_snap_alloc1(ASMState *as, IRRef ref) > } > } else { > RegSet allow; > - if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT) { > + if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && > + (as->flags & JIT_F_OPT_DCE)) { > IRIns *irc; > for (irc = IR(as->curins); irc > ir; irc--) > if ((irc->op1 == ref || irc->op2 == ref) && > diff --git a/test/tarantool-tests/lj-1537-conv-sink-without-dce.test.lua b/test/tarantool-tests/lj-1537-conv-sink-without-dce.test.lua > new file mode 100644 > index 00000000..4b332acb > --- /dev/null > +++ b/test/tarantool-tests/lj-1537-conv-sink-without-dce.test.lua > @@ -0,0 +1,38 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate LuaJIT incorrect sink of the `IR_CONV` > +-- with disabled DCE optimization. > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1537. > +local test = tap.test('lj-1537-conv-sink-without-dce'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(1) > + > +jit.opt.start('hotloop=1', '-dce') > + > +-- Before the patch, the CONV num.int is sunk even with disabled > +-- DCE optimization (which is required for sink optimization). > +-- Hence, the register allocated for CONV IR is the same as for > +-- the next ADD IR, leading to the incorrect results when > +-- exiting to the interpreter. > +-- | 0004 xmm7 num CONV 0003 num.int > +-- | 0005 xmm7 > num SLOAD #4 T > +-- | 0006 xmm7 + num ADD 0005 +1 > +-- | ... > +-- | 0009 ------------ LOOP ------------ > +-- | 0010 xmm7 + num ADD 0006 +1 > +-- | 0011 rbp + int ADD 0007 +1 > +-- | .... SNAP #3 [ ---- ---- ---- 0004 0010 ] > + > +local t = {} > +local conv, n = 0, 0 > +for _ = 1, 4 do > + -- Need preserve the conversion, not int value in a snap. > + conv = #t * 1 > + n = n + 1 -- Occupies the same register. > +end > + > +test:is(conv, 0, 'correct value is restored from snapshot') > + > +test:done(true)