]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Optimize table.new() with constant args to (sinkable) IR_TNEW.
authorMike Pall <mike>
Sun, 10 Dec 2023 13:41:56 +0000 (14:41 +0100)
committerMike Pall <mike>
Sun, 10 Dec 2023 13:41:56 +0000 (14:41 +0100)
Thanks to Peter Cawley. #1128

src/lj_ffrecord.c

index 1233e5f74e85d1b4f4e7bdde729ecfe92efcad3b..151c4c8cbe50a426a489c80e27f3bcdd45839ee1 100644 (file)
@@ -1444,6 +1444,15 @@ static void LJ_FASTCALL recff_table_new(jit_State *J, RecordFFData *rd)
 {
   TRef tra = lj_opt_narrow_toint(J, J->base[0]);
   TRef trh = lj_opt_narrow_toint(J, J->base[1]);
+  if (tref_isk(tra) && tref_isk(trh)) {
+    int32_t a = IR(tref_ref(tra))->i;
+    if (a < 0x7fff) {
+      uint32_t hbits = hsize2hbits(IR(tref_ref(trh))->i);
+      a = a > 0 ? a+1 : 0;
+      J->base[0] = emitir(IRTG(IR_TNEW, IRT_TAB), (uint32_t)a, hbits);
+      return;
+    }
+  }
   J->base[0] = lj_ir_call(J, IRCALL_lj_tab_new_ah, tra, trh);
   UNUSED(rd);
 }