[Tarantool-patches] [PATCH luajit] Fix bytecode register allocation for comparisons.
skaplun at tarantool.org
Mon Aug 16 19:44:39 MSK 2021
Thanks for the review!
On 10.08.21, Sergey Ostanevich wrote:
> Thanks for the patch! Just minor grammar, LGTM.
The new commit message is the following:
Fix bytecode register allocation for comparisons.
(cherry picked from commit 2f3f07882fb4ad9c64967d7088461b1ca0a25d3a)
When LuaJIT is built with LJ_FR2 (e.g. with GC64 mode enabled),
information about frame takes two slots -- the first takes the TValue
with the function to be called, the second takes the framelink. The JIT
recording machinery does pretty the same -- the function IR_KGC is
loaded in the first slot, and the second is set to TREF_FRAME value.
This value should be rewritten after return from a callee. This slot is
cleared either by return values or manually (set to zero), when there
are no values to return. The latter case is done by the next bytecode
with RA dst mode. This obliges that the destination of RA takes the next
slot after TREF_FRAME. Hence, this an earlier instruction must use the
smallest possible destination register (see `lj_record_ins()` for the
Bytecode emitter swaps operands for ISGT and ISGE comparisons. As a
result, the aforementioned rule for registers allocations may be
violated. When it happens for a chunk being recorded, the slot with
TREF_FRAME is not rewritten (but the next empty slot after TREF_FRAME
is). This leads to JIT slots inconsistency and assertion failure in
`rec_check_slots()` during recording of the next bytecode instruction.
This patch fixes bytecode register allocation by changing the VM
register allocation order in case of ISGT and ISGE bytecodes.
* added the description and the test for the problem
Part of tarantool/tarantool#5629
More information about the Tarantool-patches