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 462E56F861; Tue, 24 Nov 2026 18:00:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 462E56F861 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795532449; bh=f3fIBjuft8KN8HoTB8/n568kFgdNQhtr97DtoJ80FfI=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=nCWXZU5+7kptzfnKgfZRGj2QWxEwz1V3besk5pQv1cVHpMt8BnQEJC3HQ27mKGuOv JRtu5KvVAQ+Ka2GC3uRm2f87XYvCg+kK4kj2xIv7Rulfx+HHVIDmgvUh39p0VOOh+6 G9tcUGLax8jaNtWJWil5vK204RBtSKv2wlV1ZF2w= Received: from send240.i.mail.ru (send240.i.mail.ru [95.163.59.79]) (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 6A5426F861 for ; Tue, 24 Nov 2026 18:00:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6A5426F861 Received: by exim-smtp-56bb8ff957-qhjsv with esmtpa (envelope-from ) id 1xVs0k-00000000JRY-0K6y; Tue, 24 Nov 2026 18:00:46 +0300 Message-ID: <7cf1d71d-1087-4a09-b72e-47a8559636c6@tarantool.org> Date: Tue, 24 Nov 2026 18:00:45 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun 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: 4F1203BC0FB41BD9DFC18640EC9820973AB87E6D124C57EF06B051F3447C6130182A05F538085040004F7234879DE3E13DE06ABAFEAF670547BC645FA8F96C7F57ADDA03A958C024BB0AA60216D37AF7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AD2F2D6F6013FF7FC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6759CC434672EE6371C2A783ECEC0211ADC4224003CC836476D5A39DEEDB180909611E41BBFE2FEB2B7DF571A356C6F0C02CDC444ABA4492B638DDD7C2B01DFC870FCE80028C71274F9FA2833FD35BB23D27C277FBC8AE2E8B3A703B70628EAD7BA471835C12D1D977C4224003CC836476EB9C41850244470149FD398EE364050F9647ADFADE5905B1040F9FF01DFDA4A8C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637343671A7C2EE4F2DEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5589F00B1B72020EA5002B1117B3ED696670EF9C905F22E78715D9AB585B0EB04823CB91A9FED034534781492E4B8EEAD5E90D3DD2A5B7EAFBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F96AB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659535E45CC7FC9DE347263049EBCAB12C1BE9756009F094C78D89F2CBB3169C28E459A5B0D2C1795ADB8341EE9D5BE9A0A8818064440D19A51DB0E560014214D553E3975FFDCF420D2C7CEAA0681F5848F4C41F94D744909CEEF9E35A692215F79327F81E6EEE0AEB67A0F9F91F029B6AF33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWIInXFpZSFeKl/VZul3y37o= X-Mailru-Sender: 015BA6FC0EFA223AFF5DE35D6D355F431962D8F149D492C6CC811723C208B417EEBDCFC40FC9E56CCC5E4764E02DF62A8C34D365DA2E1307B60569B44082A3A3197AF8DA6C69D34BA7BD66BEAC8CCB0C4198E0F3ECE9B5443453F38A29522196 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: Evgeniy Temirgaleev via Tarantool-patches Reply-To: Evgeniy Temirgaleev Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the patch! LGTM On 11/18/26 5:22 PM, 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) -- -- Best regards, Evgeniy Temirgaleev