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 6A81F71224; Wed, 27 Oct 2021 19:08:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6A81F71224 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1635350891; bh=Q3zovXMW9eS5o2b663x2qdv2Kc1bd5HLyzqAcyIXGKk=; 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=A/YypbyFR4ylPdtP/FJCglN0Ujye1A2ELg0q0B+l1vNTlUvhZfDVFBivemHgCn1tv 8J6q5QvJuTuOGPe/gr6dOZ3vyZ6O6anHXWDNAU+3HZlO2EmVsAdEaqUOletwT7ZnXv nY/QDYBti1IELSxwYy9MxieSF4Q0PN/FhWYmTHdo= Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (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 3B8B271223 for ; Wed, 27 Oct 2021 19:08:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3B8B271223 Received: by smtp3.mail.ru with esmtpa (envelope-from ) id 1mflTE-0005SG-9s; Wed, 27 Oct 2021 19:08:09 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) In-Reply-To: <20211018185341.32155-1-skaplun@tarantool.org> Date: Wed, 27 Oct 2021 19:08:06 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20211018185341.32155-1-skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3654.120.0.1.13) X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD942A0FCC6E34F173C5B69D4D573E6E3BA665E25DCA11C3159182A05F5380850404331A9DEB71A422CC05EFA17C7AB78C6A92705D386639DBF5F28CA16C8B9D65A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE746D93DAA4671895CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377E3992E1815AFF058638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8983C72ECCEAB2474EED6679A1F8B6098117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6AC294AFEFA671E80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A50622B241A2929EC224C08A398BE696207EC56D8341C905A8D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7567C209D01CC1E34B410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D6AC337C1E637B8AF2ED9503558103D66D29E12576DB211DA3F9C06CCCB59FC6B8235F4688B68B821D7E09C32AA3244CEBD8033F790B475F93BB089C9229A30AB018FE5BB746DCD1FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojOHwMx23X6B1RDY3pM27tXg== X-Mailru-Sender: 3B9A0136629DC912F4AABCEFC589C81EB573B389874103052E7BA86DD3577730A43B795939E54874AD07DD1419AC565FA614486B47F28B67C5E079CCF3B0523AED31B7EB2E253A9E112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix FOLD rule for strength reduction of widening. 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, see my comments below. Regards, Sergos > On 18 Oct 2021, at 21:53, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > Reported by Matthew Burk. >=20 > (cherry picked from commit 9f0caad0e43f97a4613850b3874b851cb1bc301d) >=20 > The simplify_conv_sext optimization is used for reduction of widening. Whether it is part of narrowing itself?=20 > cdata indexing narrow optimization uses it for narrowing of a C array The sentence is started with lowercase, making one to track back the = start of the sentence. =E2=80=9CA narrow optimization for cdata=E2=80=A6=E2=80=9D= in conjunction of first sentence above should help. > index. The optimization eliminates sign extension for corresponding the > integer value. However, this conversion cannot be omitted for non > constant values (for example loading stack slots) as far as their sign > extension may change. The emitted machine code may be incorrect = without I believe you meant =E2=80=98with=E2=80=99 the conversion.=20 > aforementioned conversion (for example mov instruction instead movsxd = is > used on x86 architecture). As a result the value in a destination The example is too much. Just =E2=80=9Cnegative offset from the stack = pointer may appear positive and result in undefined memory access=E2=80=9D =20 > register during trace execution is invalid. >=20 > This patch allows this optimization only for constant integer values. Should it check if integer - even a constant one - is positive?=20 >=20 > Sergey Kaplun: > * added the description and the test for the problem > --- >=20 > Tarantool branch: = https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-fix-fold-s= implify-conv-sext > Branch: = https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-fix-fold-simp= lify-conv-sext >=20 > src/lj_opt_fold.c | 2 +- > .../lj-fix-fold-simplify-conv-sext.test.lua | 35 +++++++++++++++++++ > 2 files changed, 36 insertions(+), 1 deletion(-) > create mode 100644 = test/tarantool-tests/lj-fix-fold-simplify-conv-sext.test.lua >=20 > diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c > index 3c508062..276dc040 100644 > --- a/src/lj_opt_fold.c > +++ b/src/lj_opt_fold.c > @@ -1227,7 +1227,7 @@ LJFOLDF(simplify_conv_sext) > if (ref =3D=3D J->scev.idx) { > IRRef lo =3D J->scev.dir ? J->scev.start : J->scev.stop; > lua_assert(irt_isint(J->scev.t)); > - if (lo && IR(lo)->i + ofs >=3D 0) { > + if (lo && IR(lo)->o =3D=3D IR_KINT && IR(lo)->i + ofs >=3D 0) { > ok_reduce: > #if LJ_TARGET_X64 > /* Eliminate widening. All 32 bit ops do an implicit = zero-extension. */ > diff --git = a/test/tarantool-tests/lj-fix-fold-simplify-conv-sext.test.lua = b/test/tarantool-tests/lj-fix-fold-simplify-conv-sext.test.lua > new file mode 100644 > index 00000000..bd3738c5 > --- /dev/null > +++ b/test/tarantool-tests/lj-fix-fold-simplify-conv-sext.test.lua > @@ -0,0 +1,35 @@ > +local tap =3D require('tap') > +local ffi =3D require('ffi') > + > +local test =3D tap.test('lj-fix-fold-simplify-conv-sext') > + > +local NSAMPLES =3D 4 > +local NTEST =3D NSAMPLES * 2 + 1 > +test:plan(NTEST) > + > +local samples =3D ffi.new('int [?]', NSAMPLES) > + > +-- Prepare data. > +for i =3D 0, NSAMPLES - 1 do samples[i] =3D i end > + > +local expected =3D {3, 2, 1, 0, 3, 2, 1} > + > +local START =3D 3 > +local STOP =3D -START > + > +local results =3D {} > +jit.opt.start('hotloop=3D1') > +for i =3D START, STOP, -1 do > + -- While recording cdata indexing the fold CONV SEXT > + -- optimization eliminate sign extension for the corresponding > + -- non constant value (i.e. stack slot). As a result the read > + -- out of bounds was occurring. > + results[#results + 1] =3D samples[i % NSAMPLES] > +end > + > +for i =3D 1, NTEST do > + test:ok(results[i] =3D=3D expected[i], 'correct cdata indexing') > +end > + > +os.exit(test:check() and 0 or 1) > + > --=20 > 2.31.0 >=20