Browse Source

Fix check for reuse of SCEV results in FORL.

Mike Pall 11 years ago
parent
commit
095344ce7c
2 changed files with 4 additions and 1 deletions
  1. 1 0
      src/lj_jit.h
  2. 3 1
      src/lj_record.c

+ 1 - 0
src/lj_jit.h

@@ -279,6 +279,7 @@ typedef struct BPropEntry {
 
 
 /* Scalar evolution analysis cache. */
 /* Scalar evolution analysis cache. */
 typedef struct ScEvEntry {
 typedef struct ScEvEntry {
+  MRef pc;		/* Bytecode PC of FORI. */
   IRRef1 idx;		/* Index reference. */
   IRRef1 idx;		/* Index reference. */
   IRRef1 start;		/* Constant start reference. */
   IRRef1 start;		/* Constant start reference. */
   IRRef1 stop;		/* Constant stop reference. */
   IRRef1 stop;		/* Constant stop reference. */

+ 3 - 1
src/lj_record.c

@@ -421,6 +421,7 @@ static void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev,
     J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step);
     J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step);
   J->base[ra+FORL_EXT] = idx;
   J->base[ra+FORL_EXT] = idx;
   scev->idx = tref_ref(idx);
   scev->idx = tref_ref(idx);
+  setmref(scev->pc, fori);
   J->maxslot = ra+FORL_EXT+1;
   J->maxslot = ra+FORL_EXT+1;
 }
 }
 
 
@@ -436,7 +437,7 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)
   IRType t;
   IRType t;
   if (isforl) {  /* Handle FORL/JFORL opcodes. */
   if (isforl) {  /* Handle FORL/JFORL opcodes. */
     TRef idx = tr[FORL_IDX];
     TRef idx = tr[FORL_IDX];
-    if (tref_ref(idx) == J->scev.idx) {
+    if (mref(J->scev.pc, const BCIns) == fori) {
       t = J->scev.t.irt;
       t = J->scev.t.irt;
       stop = J->scev.stop;
       stop = J->scev.stop;
       idx = emitir(IRT(IR_ADD, t), idx, J->scev.step);
       idx = emitir(IRT(IR_ADD, t), idx, J->scev.step);
@@ -2153,6 +2154,7 @@ void lj_record_setup(jit_State *J)
   memset(J->chain, 0, sizeof(J->chain));
   memset(J->chain, 0, sizeof(J->chain));
   memset(J->bpropcache, 0, sizeof(J->bpropcache));
   memset(J->bpropcache, 0, sizeof(J->bpropcache));
   J->scev.idx = REF_NIL;
   J->scev.idx = REF_NIL;
+  setmref(J->scev.pc, NULL);
 
 
   J->baseslot = 1;  /* Invoking function is at base[-1]. */
   J->baseslot = 1;  /* Invoking function is at base[-1]. */
   J->base = J->slot + J->baseslot;
   J->base = J->slot + J->baseslot;