Skip to content

Commit 67de359

Browse files
committed
Keep table length forwarding within poll regions
1 parent 7a47081 commit 67de359

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

notes/m6.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ M6 JIT recorder token scaffold:
125125
`IR_XPOLL` or `IR_XBAR`. This deliberately keeps a trace poll as a hard
126126
GC-barrier/handshake boundary for shared cells and field stores, even when a
127127
narrower optimization might be valid in single-threaded stock LuaJIT.
128+
- Table length forwarding now uses the same boundary: `IR_ALEN` CSE and
129+
`t[#t+1]` hint forwarding do not cross `IR_XPOLL` or `IR_XBAR`, so a trace
130+
poll cannot reuse a pre-poll array-length snapshot across a safepoint or
131+
resize window.
128132
- Helper-backed indexed table stores can now trace on Linux/x64 through
129133
release-store helpers. x64 lowers `ASTORE` through
130134
`lj_tab_storetv_forjit_array()`, hash-slot `HSTORE` through

src/lj_opt_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)
425425
TRef LJ_FASTCALL lj_opt_fwd_alen(jit_State *J)
426426
{
427427
IRRef tab = fins->op1; /* Table reference. */
428-
IRRef lim = tab; /* Search limit. */
428+
IRRef lim = poll_alias_limit(J, tab); /* Search limit. */
429429
IRRef ref;
430430

431431
/* Search for conflicting HSTORE with numeric key. */

tests/lib/suite_jit.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function M.trace1_ir_state(t, dump)
1111
array = 0,
1212
hdradd = 0,
1313
xload = 0,
14+
alen = 0,
1415
asize = 0,
1516
eq = 0,
1617
aref = false,
@@ -39,6 +40,7 @@ function M.trace1_ir_state(t, dump)
3940
st.hdradd = st.hdradd + 1
4041
end
4142
if contains(line, " XLOAD ") then st.xload = st.xload + 1 end
43+
if contains(line, " ALEN ") then st.alen = st.alen + 1 end
4244
if line:match("FLOAD .*tab[.]asize") then st.asize = st.asize + 1 end
4345
if contains(line, " p64 EQ ") then st.eq = st.eq + 1 end
4446
if contains(line, " ULE ") then st.ule = true end

tests/suites/m6_jit.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,17 @@ for i = 1, 120 do a[i % 128] = i end
625625
assert(a[119 % 128] == 119)
626626
]=])
627627
assert_loop_after_xpoll(t, store_dump, "FFI XSTORE loop", { "XSTORE" })
628+
629+
local alen_dump = t:tmp("lj-m6-alen-xpoll-ir.dump")
630+
run_ir_dump_probe(t, alen_dump, [=[
631+
jit.flush()
632+
jit.opt.start("hotloop=1", "hotexit=1")
633+
local t = { 1, 2, 3 }
634+
local s = 0
635+
for _ = 1, 80 do s = s + #t end
636+
assert(s == 240)
637+
]=])
638+
assert_loop_after_xpoll(t, alen_dump, "table ALEN loop", { "ALEN" })
628639
run_lua_test_case(t, "m5_jit_hash_store_nyi")
629640
print("M6 JIT XBAR/XPOLL alias guard passed")
630641
end

0 commit comments

Comments
 (0)