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 666E96F3C8; Mon, 26 Sep 2022 00:31:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 666E96F3C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1664141514; bh=9baSz8FwiD2kapJy8c/6BoPjxAJTA2PtwjUKX43Sb+A=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vSJfXzRgIrp47X4etY/OIAmrUdp5shcj40REOYa0EeXKqCVva83dIEtiQFkteutJ3 dRYFwUaehhcOWy5wk+gwCQD7TxT4kJamrqtdp1dnaCf85UIgQTRuz2vuxOpCRPAZCt RMBo37+Izhe9xcdGwU3wVufLQ1WeQn2k3h7ea/Dw= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (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 6E0CD6F3C8 for ; Mon, 26 Sep 2022 00:31:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6E0CD6F3C8 Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1ocZE7-0004kB-Eg; Mon, 26 Sep 2022 00:31:51 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) In-Reply-To: <20220920111649.86190-1-max.kokryashkin@gmail.com> Date: Mon, 26 Sep 2022 00:31:50 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <4DD728DB-B92B-4466-A709-E3FD08576876@tarantool.org> References: <20220920111649.86190-1-max.kokryashkin@gmail.com> To: Maksim Kokryashkin X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD99929F1169E77FC7A3F9488CD0D5932E5BFAB70C53BDD0B78182A05F5380850408B09861143D53E5021FC9390B210083A95B1805AEAF719DD32CC63CACE49EF4C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7495A032B936E882FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EEFC5FE85C3736658638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82CBE73D246EDEDE7702FBBFFD06D32AB117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2F22DFD7D6B35478A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A9935A1E27F592749D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE317119E5299B287EE040F9FF01DFDA4A8C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BB662CFBDBA8F60F475ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B0CBAED148C0C85B123C58F38EC06D5558BAC429CED9F0BC8504940A133A1BEE149C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A9873270276D4334A7FA0F4AD356C0165A47921C57F36141A4ACF3E1D5F92F0F6659E76A11FB1DCC1D7E09C32AA3244C01FBF8E04516419FDE23B525E8912B1F7C0C08F7987826B9927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMoF5vjNyHyIhvZhLLRRixQ== X-Mailru-Sender: 5AA3D5B9D8C486465A7E7C48E78B605DBC90C10A3772261521FC9390B210083A9BBFB9D4C9B7685660D8632BEC246C7D55B4A2144138A8805FC805B5969CB4993EE16157CC7DAB4272D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v2] Fix narrowing of unary minus. 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: sergos via Tarantool-patches Reply-To: sergos Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! I have two questions below. Sergos > On 20 Sep 2022, at 14:16, Maksim Kokryashkin via Tarantool-patches = wrote: >=20 > From: Mike Pall >=20 > (cherry picked from commit 1e6e8aaa20626ac94cf907c69b0452f76e9f5fa5) >=20 > LuaJIT narrowing optimization during BC_UNM recording may ignore > information about sign of zero for integer types of IR. So far the > resulting value on a trace is not the same as for the interpreter. I didn=E2=80=99t get the point - how is it detected, otherwise than = tostring()? If so - should we change the tostring() instead? Otherwise - we need a test that exposes this difference. =20 > However, in DUALNUM mode with using of TValues containing integers the > -0 value is represented in the same way as the 0 value and there is no > difference between them. >=20 > This patch fixes the non-DUALNUM mode behaviour. When the zero value = is > identified during recording it should be cast to number so IR_CONV is > emitted. Also, this patch adds assertion guard checking that value on > which operation of unary minus is performed isn't zero. Does it mean I will exit the trace every time I met a `x =3D 0; x =3D = -x` in it? >=20 > Maxim Kokryashkin: > * added the description and the test for the problem >=20 > Resolves tarantool/tarantool#6976 > Part of tarantool/tarantool#7230 > --- >=20 > Changes in v2: > - Fixed test and commit message as per review by Sergey >=20 > Branch and PR are updated. >=20 > src/lj_opt_narrow.c | 9 +++- > .../gh-6976-narrowing-of-unary-minus.test.lua | 51 +++++++++++++++++++ > 2 files changed, 58 insertions(+), 2 deletions(-) > create mode 100644 = test/tarantool-tests/gh-6976-narrowing-of-unary-minus.test.lua >=20 > diff --git a/src/lj_opt_narrow.c b/src/lj_opt_narrow.c > index cd96ca4b..bb61f97b 100644 > --- a/src/lj_opt_narrow.c > +++ b/src/lj_opt_narrow.c > @@ -551,8 +551,13 @@ TRef lj_opt_narrow_unm(jit_State *J, TRef rc, = TValue *vc) > { > rc =3D conv_str_tonum(J, rc, vc); > if (tref_isinteger(rc)) { > - if ((uint32_t)numberVint(vc) !=3D 0x80000000u) > - return emitir(IRTGI(IR_SUBOV), lj_ir_kint(J, 0), rc); > + uint32_t k =3D (uint32_t)numberVint(vc); > + if ((LJ_DUALNUM || k !=3D 0) && k !=3D 0x80000000u) { > + TRef zero =3D lj_ir_kint(J, 0); > + if (!LJ_DUALNUM) > + emitir(IRTGI(IR_NE), rc, zero); > + return emitir(IRTGI(IR_SUBOV), zero, rc); > + } > rc =3D emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); > } > return emitir(IRTN(IR_NEG), rc, lj_ir_ksimd(J, LJ_KSIMD_NEG)); > diff --git = a/test/tarantool-tests/gh-6976-narrowing-of-unary-minus.test.lua = b/test/tarantool-tests/gh-6976-narrowing-of-unary-minus.test.lua > new file mode 100644 > index 00000000..18778a55 > --- /dev/null > +++ b/test/tarantool-tests/gh-6976-narrowing-of-unary-minus.test.lua > @@ -0,0 +1,51 @@ > +local tap =3D require('tap') > +local test =3D tap.test('gh-6976-narrowing-of-unary-minus') > +test:plan(2) > + > +jit.opt.start('hotloop=3D1', 'hotexit=3D1') > + > +local function check(routine) > + jit.off() > + jit.flush() > + local interp_res =3D routine() > + jit.on() > + local jit_res =3D routine() > + > + for i =3D 1, #interp_res do > + if interp_res[i] ~=3D jit_res[i] then > + return false > + end > + end > + > + return true > +end > + > +test:ok( > + check( > + function() > + local res =3D require('table.new')(3, 0) > + for _ =3D 1, 3 do > + local zero =3D 0 > + zero =3D -zero > + table.insert(res, tostring(zero)) > + end > + return res > + end > + ), > + 'incorrect recording for zero' > +) > + > +test:ok( > + check( > + function() > + local res =3D require('table.new')(3, 0) > + for i =3D 2, 0, -1 do > + table.insert(res, tostring(-i)) > + end > + return res > + end > + ), > + 'assertion guard fail' > +) > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.32.1 (Apple Git-133) >=20