From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit] x86/x64: Use scratch register for IR_TOBIT and IR_CONV u64.num.
Date: Tue, 24 Nov 2026 11:00:38 +0300 [thread overview]
Message-ID: <awVEJsO3r8uvvdP0@root> (raw)
In-Reply-To: <79a76da9-a60f-41f6-b3bc-dcae4faa1ed1@tarantool.org>
Hi, Sergey!
Thanks for the review!
Fixed your comments and force-pushed branch.
On 23.11.26, Sergey Bronnikov wrote:
> Hi, Sergey,
>
> thanks for the patch! Please see my comments below.
>
> Sergey
>
> On 11/18/26 11:48, Sergey Kaplun wrote:
> > From: Mike Pall <mike>
> >
> > Reported by aleksisch. Thanks to Sergey Kaplun.
> >
> > (cherry picked from commit 5585364753b52ac7de4695026fc28be2480c82bd)
> >
> > If `asm_tobit()` allocates a register for the `op1` in the TOBIT IR, its
> > value is modified by adding the TOBIT bias (the second operand). Hence,
> > the restoring value of the source IR is incorrect due to this
> > modification.
> >
> > This patch uses a scratch register instead. The `IR_CONV` case is
> > similar but is unobservable since the adding value `LJ_K64_M2P64`
> > (-2^64) is overlapped in the uint64_t representation.
> >
> > Sergey Kaplun:
> > * added the description for the problem
> and a regression test, right?
Yep, added, thanks!
> >
> > Part of tarantool/tarantool#13442
> > ---
> >
> > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1536-tobit-regalloc
> > Related issues:
> > * https://github.com/LuaJIT/LuaJIT/issues/1536
> > * https://github.com/tarantool/tarantool/issues/13442
> >
> > Side note: macOS (x86_64) CI is red due to runner problems. The metrics
> > CI is red due to problems with configuration.
> >
> > src/lj_asm_x86.h | 7 ++--
> > .../lj-1536-tobit-regalloc.test.lua | 36 +++++++++++++++++++
> > 2 files changed, 38 insertions(+), 5 deletions(-)
> > create mode 100644 test/tarantool-tests/lj-1536-tobit-regalloc.test.lua
> >
> > diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h
> > index 0e3a473c..8e2156eb 100644
> > --- a/src/lj_asm_x86.h
> > +++ b/src/lj_asm_x86.h
<snipped>
> > diff --git a/test/tarantool-tests/lj-1536-tobit-regalloc.test.lua b/test/tarantool-tests/lj-1536-tobit-regalloc.test.lua
> > new file mode 100644
> > index 00000000..120fa1b0
> > --- /dev/null
> > +++ b/test/tarantool-tests/lj-1536-tobit-regalloc.test.lua
> > @@ -0,0 +1,36 @@
> > +local tap = require('tap')
> > +
> > +-- Test file to demonstrate incorrect register allocation for
> > +-- `IR_TOBIT` on x86/x64.
> > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1536.
> > +local test = tap.test('lj-1536-tobit-regalloc'):skipcond({
> > + ['Test requires JIT enabled'] = not jit.status(),
> > +})
> > +
> > +test:plan(1)
> > +
> > +local tobit = bit.tobit
> > +
> > +jit.opt.start('hotloop=1')
> > +
> > +local res
> > +local VALUE = 0x100
> Why exactly this value?
No reason, added the comment:
===================================================================
diff --git a/test/tarantool-tests/lj-1536-tobit-regalloc.test.lua b/test/tarantool-tests/lj-1536-tobit-regalloc.test.lua
index 120fa1b0..8c304ac0 100644
--- a/test/tarantool-tests/lj-1536-tobit-regalloc.test.lua
+++ b/test/tarantool-tests/lj-1536-tobit-regalloc.test.lua
@@ -14,6 +14,7 @@ local tobit = bit.tobit
jit.opt.start('hotloop=1')
local res
+-- Some value to be unchanged.
local VALUE = 0x100
-- Use a table for the `noreg` of the tobit operand.
local t = {k = VALUE}
===================================================================
<snipped>
--
Best regards,
Sergey Kaplun
next prev parent reply other threads:[~2026-11-24 7:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 8:48 Sergey Kaplun via Tarantool-patches
2026-11-23 15:33 ` Sergey Bronnikov via Tarantool-patches
2026-11-24 8:00 ` Sergey Kaplun via Tarantool-patches [this message]
2026-11-24 10:21 ` Sergey Bronnikov via Tarantool-patches
2026-11-24 15:46 ` Evgeniy Temirgaleev via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awVEJsO3r8uvvdP0@root \
--to=tarantool-patches@dev.tarantool.org \
--cc=sergeyb@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit] x86/x64: Use scratch register for IR_TOBIT and IR_CONV u64.num.' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox