]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Fold HREF of TNEW/TDUP to niltv. Fold HLOAD of niltv to nil.
authorMike Pall <mike>
Sun, 28 Mar 2010 04:50:39 +0000 (06:50 +0200)
committerMike Pall <mike>
Sun, 28 Mar 2010 04:53:41 +0000 (06:53 +0200)
src/Makefile.dep
src/lj_iropt.h
src/lj_opt_fold.c
src/lj_opt_mem.c

index 3646349c72ce5467279b5ca1c85233dee3287d95..aeeeeff5437ba01afc81758d591780d8e6864f95 100644 (file)
@@ -87,8 +87,8 @@ lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h
 lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
   lj_ir.h lj_jit.h lj_iropt.h
 lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
-  lj_str.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h \
-  lj_traceerr.h lj_vm.h lj_folddef.h
+  lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
+  lj_bc.h lj_traceerr.h lj_vm.h lj_folddef.h
 lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
   lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \
   lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h lj_vm.h
index 1884892a9936e2492d9deb055bc9e160c82cb5e0..ee593b40294b181ea7a9065de5d3f2c68caf1858 100644 (file)
@@ -110,6 +110,7 @@ LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J);
 LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J);
 LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J);
 LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J);
+LJ_FUNC int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J);
 LJ_FUNC int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref);
 
 /* Dead-store elimination. */
index 5eeffae3fbcf9cb89c381674c68d8e0481dbc461..c91f33820b2758c3234b0d0fb213d4f39bfc2a0f 100644 (file)
@@ -13,6 +13,7 @@
 #if LJ_HASJIT
 
 #include "lj_str.h"
+#include "lj_tab.h"
 #include "lj_ir.h"
 #include "lj_jit.h"
 #include "lj_iropt.h"
@@ -1163,6 +1164,15 @@ LJFOLDF(merge_eqne_snew_kgc)
 LJFOLD(ALOAD any)
 LJFOLDX(lj_opt_fwd_aload)
 
+/* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */
+LJFOLD(HLOAD KPTR)
+LJFOLDF(kfold_hload_kptr)
+{
+  UNUSED(J);
+  lua_assert(ir_kptr(fleft) == niltvg(J2G(J)));
+  return TREF_NIL;
+}
+
 LJFOLD(HLOAD any)
 LJFOLDX(lj_opt_fwd_hload)
 
@@ -1202,6 +1212,27 @@ LJFOLDF(cse_uref)
   return EMITFOLD;
 }
 
+LJFOLD(HREF TNEW any)
+LJFOLDF(fwd_href_tnew)
+{
+  if (lj_opt_fwd_href_nokey(J))
+    return lj_ir_kptr(J, niltvg(J2G(J)));
+  return NEXTFOLD;
+}
+
+LJFOLD(HREF TDUP KPRI)
+LJFOLD(HREF TDUP KGC)
+LJFOLD(HREF TDUP KNUM)
+LJFOLDF(fwd_href_tdup)
+{
+  TValue keyv;
+  lj_ir_kvalue(J->L, &keyv, fright);
+  if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) &&
+      lj_opt_fwd_href_nokey(J))
+    return lj_ir_kptr(J, niltvg(J2G(J)));
+  return NEXTFOLD;
+}
+
 /* We can safely FOLD/CSE array/hash refs and field loads, since there
 ** are no corresponding stores. But NEWREF may invalidate all of them.
 ** Lacking better disambiguation for table references, these optimizations
index 5794831120a85347838c5ab51611cbe5974b2d78..042d60812f25dd1d93d735336032c28041ac103f 100644 (file)
@@ -21,6 +21,7 @@
 /* Some local macros to save typing. Undef'd at the end. */
 #define IR(ref)                (&J->cur.ir[(ref)])
 #define fins           (&J->fold.ins)
+#define fright         (&J->fold.right)
 
 /*
 ** Caveat #1: return value is not always a TRef -- only use with tref_ref().
@@ -220,6 +221,34 @@ TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J)
   return EMITFOLD;
 }
 
+/* Check whether HREF of TNEW/TDUP can be folded to niltv. */
+int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J)
+{
+  IRRef lim = fins->op1;  /* Search limit. */
+  IRRef ref;
+
+  /* The key for an ASTORE may end up in the hash part after a NEWREF. */
+  if (irt_isnum(fright->t) && J->chain[IR_NEWREF] > lim) {
+    ref = J->chain[IR_ASTORE];
+    while (ref > lim) {
+      if (ref < J->chain[IR_NEWREF])
+       return 0;  /* Conflict. */
+      ref = IR(ref)->prev;
+    }
+  }
+
+  /* Search for conflicting stores. */
+  ref = J->chain[IR_HSTORE];
+  while (ref > lim) {
+    IRIns *store = IR(ref);
+    if (aa_ahref(J, fins, IR(store->op1)) != ALIAS_NO)
+      return 0;  /* Conflict. */
+    ref = store->prev;
+  }
+
+  return 1;  /* No conflict. Can fold to niltv. */
+}
+
 /* ASTORE/HSTORE elimination. */
 TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)
 {
@@ -530,5 +559,6 @@ int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref)
 
 #undef IR
 #undef fins
+#undef fright
 
 #endif