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 E9C155C532D; Wed, 8 Nov 2023 22:36:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E9C155C532D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1699472188; bh=PH/j3EnEDuS5I59ESWEqVGD+dIBz6agVWya/r8UemnE=; 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=ICnneinvNji7GWdX99UR3627X8xaHsZdmelWNBmpM2qDPcJRKy4VhlyXeQRdCZlCd XlexVqEdrae8m43sTi2V7xWYPjlFJlAHsFcMOE/gIZ2iZeSVEWG2YEEeC4YMg4h10/ YQ3AiDJ44lHucIMwIaLYcmlQHcIGRWMgcURda5WY= Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [95.163.41.65]) (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 822E65C532D for ; Wed, 8 Nov 2023 22:36:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 822E65C532D Received: by smtp42.i.mail.ru with esmtpa (envelope-from ) id 1r0oLh-0054in-2a; Wed, 08 Nov 2023 22:36:26 +0300 Message-ID: <1d2e8e64-81cd-402e-8b0b-9f4a83a51d1f@tarantool.org> Date: Wed, 8 Nov 2023 22:36:23 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <20231031124446.17478-1-skaplun@tarantool.org> In-Reply-To: <20231031124446.17478-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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9C2A6B03AB739174C257DF95037FE5E5EC8239E2FC8E2FDC300894C459B0CD1B91BD8DB402269083A76AF54B85244E3385B1CD8F3DB8F46F3862BB7B6EB49490E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74FF5DF51D335CFFFEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637889C00975665ABF68638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89CF87D07A772FE9ACD966DA997C88B38117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD1828451B159A507268D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7AC43C4D2AE8146675D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE32A336C6518635091040F9FF01DFDA4A8C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947C062BEEFFB5F8EA3E2E808ACE2090B5E1725E5C173C3A84C3ED8438A78DFE0A9E089D37D7C0E48F6C8AA50765F79006378534F7D0DA3B5694EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A50F8571CAE5EB1F715533F5B0700D55DDA83E14F4A05CDC4FF87CCE6106E1FC07E67D4AC08A07B9B0E753FA5741D1AD02CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFC813202B12B64971859D08D09A3EAD5F6284D263476064E3FF855DD1CA8A4CADA54F0D539447C58B2B33B16BC67043E00465ECFF98740A708D90DB390509E63EE48CAC7CA610320002C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojGx6zOZpnTNAAQYCydvXBCg== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458FE5F812103C3F6B4409CA635F995CBD5BE72F5411357F79D282EC151BADDC1D3523A6D01B4765B2DFB59E2DDD9FE06B14FA522850F29BC30B0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix FOLD rule for x-0. 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 On 10/31/23 15:44, Sergey Kaplun wrote: > From: Mike Pall > > Reported by XmiliaH. > > (cherry-picked from commit 7b994e0ee0399caf6319865bbac88ddf62129a36) > > Fold optimization x - (-0) ==> x is INVALID for x = -0 in FP arithmetic. > Its result is -0 instead of +0. This patch allows only x - (+0) ==> x > optimization. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9145 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-783-fix-fold-x-0 > Tarantool PR: https://github.com/tarantool/tarantool/pull/9320 > Related Issues: > * https://github.com/tarantool/tarantool/issues/9145 > * https://github.com/LuaJIT/LuaJIT/pull/783 > > src/lj_opt_fold.c | 3 +-- > test/tarantool-tests/lj-783-fold--0.test.lua | 28 ++++++++++++++++++++ > 2 files changed, 29 insertions(+), 2 deletions(-) > create mode 100644 test/tarantool-tests/lj-783-fold--0.test.lua > > diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c > index 09e6c87b..944a9ecc 100644 > --- a/src/lj_opt_fold.c > +++ b/src/lj_opt_fold.c > @@ -1005,8 +1005,7 @@ LJFOLDF(simplify_numadd_xneg) > LJFOLD(SUB any KNUM) > LJFOLDF(simplify_numsub_k) > { > - lua_Number n = knumright; > - if (n == 0.0) /* x - (+-0) ==> x */ > + if (ir_knum(fright)->u64 == 0) /* x - (+0) ==> x */ > return LEFTFOLD; > return NEXTFOLD; > } > diff --git a/test/tarantool-tests/lj-783-fold--0.test.lua b/test/tarantool-tests/lj-783-fold--0.test.lua > new file mode 100644 > index 00000000..d6b4b493 > --- /dev/null > +++ b/test/tarantool-tests/lj-783-fold--0.test.lua > @@ -0,0 +1,28 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate LuaJIT's incorrect fold optimization > +-- x - (-0) ==> x. > +-- See also https://github.com/LuaJIT/LuaJIT/issues/783. > +local test = tap.test('lj-783-fold--0'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(2) > + > +-- XXX: Use the variable to avoid folding during parsing. > +local minus_zero = -0 > +local results = {} > + > +jit.opt.start('hotloop=1') > + > +for i = 1, 4 do > + results[i] = tostring(minus_zero - (-0)) > +end > + > +-- Fold optimization x - (-0) ==> x is INVALID for x = -0 in FP > +-- arithmetic. Its result is -0 instead of +0. > + > +test:is(results[1], '0', 'correct VM value for -0 - (-0)') > +test:samevalues(results, '-0 folding in simplify_numsub_k') > + > +test:done(true)