diff options
author | Mike Pall <mike> | 2023-12-10 14:41:56 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2023-12-10 14:41:56 +0100 |
commit | d1236a4caa999b29e774ef5103df3b424d821d9b (patch) | |
tree | a11337cd6c708695028ad7d8362fab67441af8ba | |
parent | 7ad68a1fd34dbd81a62d5fe915ae8b806ea6e213 (diff) | |
download | luajit-d1236a4caa999b29e774ef5103df3b424d821d9b.tar.gz luajit-d1236a4caa999b29e774ef5103df3b424d821d9b.tar.bz2 luajit-d1236a4caa999b29e774ef5103df3b424d821d9b.zip |
Optimize table.new() with constant args to (sinkable) IR_TNEW.
Thanks to Peter Cawley. #1128
-rw-r--r-- | src/lj_ffrecord.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 1233e5f7..151c4c8c 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -1444,6 +1444,15 @@ static void LJ_FASTCALL recff_table_new(jit_State *J, RecordFFData *rd) | |||
1444 | { | 1444 | { |
1445 | TRef tra = lj_opt_narrow_toint(J, J->base[0]); | 1445 | TRef tra = lj_opt_narrow_toint(J, J->base[0]); |
1446 | TRef trh = lj_opt_narrow_toint(J, J->base[1]); | 1446 | TRef trh = lj_opt_narrow_toint(J, J->base[1]); |
1447 | if (tref_isk(tra) && tref_isk(trh)) { | ||
1448 | int32_t a = IR(tref_ref(tra))->i; | ||
1449 | if (a < 0x7fff) { | ||
1450 | uint32_t hbits = hsize2hbits(IR(tref_ref(trh))->i); | ||
1451 | a = a > 0 ? a+1 : 0; | ||
1452 | J->base[0] = emitir(IRTG(IR_TNEW, IRT_TAB), (uint32_t)a, hbits); | ||
1453 | return; | ||
1454 | } | ||
1455 | } | ||
1447 | J->base[0] = lj_ir_call(J, IRCALL_lj_tab_new_ah, tra, trh); | 1456 | J->base[0] = lj_ir_call(J, IRCALL_lj_tab_new_ah, tra, trh); |
1448 | UNUSED(rd); | 1457 | UNUSED(rd); |
1449 | } | 1458 | } |