[Tarantool-patches] [PATCH luajit v2 5/5] Fix IR_RENAME snapshot number. Follow-up fix for a32aeadc.
Maxim Kokryashkin
max.kokryashkin at gmail.com
Tue Mar 14 15:01:47 MSK 2023
From: Mike Pall <mike>
Reported by Victor Bombi, analyzed by XmiliaH. Thanks!
(cherry-picked from commit bf51d3535109c4745bfbbe19a5587a9eac00259a)
If the `snapalloc` flag is set, then the allocation hasn't
occurred yet, meaning that rename is applied to the next
snapshot. Otherwise, refs are already allocated and rename
is applied to the current snapshot.
Maxim Kokryashkin:
* added the description and the test for the problem
Part of tarantool/tarantool#7745
Part of tarantool/tarantool#8069
---
Note: The part with os.exit(test:check() and 0 or 1) replaced by
os.exit(test:check()) is required, since in the first case, when
the trace is recorded, arithmetic register is not allocated yet
by the time th `ra_left` is called. Because of that, the PHI
optimization occurs differently and there is no RENAME.
src/lj_asm.c | 9 ++++++++-
.../gh-7745-ir-rename.test.lua | 20 +++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 test/tarantool-tests/gh-7745-ir-rename.test.lua
diff --git a/src/lj_asm.c b/src/lj_asm.c
index adfaf286..929a6da6 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -682,7 +682,14 @@ static void ra_rename(ASMState *as, Reg down, Reg up)
RA_DBGX((as, "rename $f $r $r", regcost_ref(as->cost[up]), down, up));
emit_movrr(as, ir, down, up); /* Backwards codegen needs inverse move. */
if (!ra_hasspill(IR(ref)->s)) { /* Add the rename to the IR. */
- ra_addrename(as, down, ref, as->snapno);
+ /*
+ ** The rename is effective at the subsequent (already emitted) exit
+ ** branch. This is for the current snapshot (as->snapno). Except if we
+ ** haven't yet allocated any refs for the snapshot (as->snapalloc == 1),
+ ** then it belongs to the next snapshot.
+ ** See also the discussion at asm_snap_checkrename().
+ */
+ ra_addrename(as, down, ref, as->snapno + as->snapalloc);
}
}
diff --git a/test/tarantool-tests/gh-7745-ir-rename.test.lua b/test/tarantool-tests/gh-7745-ir-rename.test.lua
new file mode 100644
index 00000000..d03f6da5
--- /dev/null
+++ b/test/tarantool-tests/gh-7745-ir-rename.test.lua
@@ -0,0 +1,20 @@
+local tap = require('tap')
+local test = tap.test('IR_RENAME on snapshot allocation'):skipcond({
+ ['Test requires JIT enabled'] = not jit.status(),
+})
+test:plan(1)
+
+jit.opt.start('hotloop=1')
+
+local vals = {-0.1, 0.1, -0.1, 0.1}
+local i = 1
+local _
+while i < 5 do
+ assert(i ~= 1.1)
+ local l1 = vals[i]
+ _ = l1 > 0
+ i = i + 1
+end
+
+test:ok(true, 'IR_RENAME is fine')
+os.exit(test:check())
--
2.39.0
More information about the Tarantool-patches
mailing list