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 A31B46AFC2F; Tue, 31 Oct 2023 15:49:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A31B46AFC2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1698756563; bh=o1Eyy10oT5gOkHkx0La+7PsLyQPDOfoJsTRekkmiAZM=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nw0V1c0o1qnWPVLKdYC+JwPGQxo63vZuszE7UD1pm9uo3nZpKFkpPLuZOhAyBv2Td sOLrKt6PlRj3X/L6dALmDD+oBy7xoElx0UCUQ8K3OXsnQExxeMUXfiZdRqHvfYZkIj nu4rO00isazdRz9okiA3NAdpPqL2WyrLQVtaYwws= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 D0D826AFC2F for ; Tue, 31 Oct 2023 15:49:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D0D826AFC2F Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1qxoBM-0000YI-S2; Tue, 31 Oct 2023 15:49:21 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Tue, 31 Oct 2023 15:44:46 +0300 Message-ID: <20231031124446.17478-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9C931D0C4A91E7130F333D6F3C33D48C9F7A892AE3F7E098900894C459B0CD1B92EAB92149AF7EE867C57D8922B533D41D4BAEBAE6EB05589E5BD31BE838A11F7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DF2546A43F668C04EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063706922F90966A37BA8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81E79290E97C77F1253D835A05DDA9F5A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269176DF2183F8FC7C0406C186E56A1B26068655334FD4449CB33AC447995A7AD186D8C47C27EEC5E9FD5E8D9A59859A8B67ECBC18655D52CDF089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5CF579CE5A2AEE31673A52CD04C78F113BCD9DD4D1125F5B7F87CCE6106E1FC07E67D4AC08A07B9B064E7220B7C5505929C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF77DD89D51EBB7742D3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFB120BE1A3EDC3B4B15A2B6391A47B7583BBE4659A95DFE8EAA2BA2E407D965FCA54F0D539447C58B516A7BA574885662C74FDD218FCEB99DD39061CE223D230BA74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPJ6ruIekffJXCtlDjSwrvA== X-DA7885C5: C718B9A14C289CB8430B6E76B386E318A7FC2CA811FD63F273F3F5298098092E262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986B47DCADBAD5B14D5651F72F595215BFE70FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [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 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 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) -- 2.42.0