diff options
Diffstat (limited to 'src/lj_record.c')
-rw-r--r-- | src/lj_record.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/lj_record.c b/src/lj_record.c index 44cb7317..0b0768d6 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -295,9 +295,9 @@ static TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t) | |||
295 | /* Peek before FORI to find a const initializer. Otherwise load from slot. */ | 295 | /* Peek before FORI to find a const initializer. Otherwise load from slot. */ |
296 | static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, IRType t) | 296 | static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, IRType t) |
297 | { | 297 | { |
298 | TRef tr = find_kinit(J, fori, slot, t); | 298 | TRef tr = J->base[slot]; |
299 | if (!tr) { | 299 | if (!tr) { |
300 | tr = J->base[slot]; | 300 | tr = find_kinit(J, fori, slot, t); |
301 | if (!tr) { | 301 | if (!tr) { |
302 | if (t == IRT_INT) | 302 | if (t == IRT_INT) |
303 | t |= IRT_GUARD; | 303 | t |= IRT_GUARD; |
@@ -347,10 +347,16 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl) | |||
347 | if (isforl) { /* Handle FORL/JFORL opcodes. */ | 347 | if (isforl) { /* Handle FORL/JFORL opcodes. */ |
348 | TRef step; | 348 | TRef step; |
349 | idx = tr[FORL_IDX]; | 349 | idx = tr[FORL_IDX]; |
350 | if (!idx) idx = sloadt(J, (int32_t)(ra+FORL_IDX), IRT_NUM, 0); | 350 | if (tref_ref(idx) == J->scev.idx) { |
351 | t = tref_type(idx); | 351 | t = J->scev.t.irt; |
352 | stop = fori_arg(J, fori, ra+FORL_STOP, t); | 352 | stop = J->scev.stop; |
353 | step = fori_arg(J, fori, ra+FORL_STEP, t); | 353 | step = J->scev.step; |
354 | } else { | ||
355 | if (!idx) idx = sloadt(J, (int32_t)(ra+FORL_IDX), IRT_NUM, 0); | ||
356 | t = tref_type(idx); | ||
357 | stop = fori_arg(J, fori, ra+FORL_STOP, t); | ||
358 | step = fori_arg(J, fori, ra+FORL_STEP, t); | ||
359 | } | ||
354 | tr[FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step); | 360 | tr[FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step); |
355 | } else { /* Handle FORI/JFORI opcodes. */ | 361 | } else { /* Handle FORI/JFORI opcodes. */ |
356 | BCReg i; | 362 | BCReg i; |
@@ -2258,6 +2264,10 @@ static void rec_setup_forl(jit_State *J, const BCIns *fori) | |||
2258 | TRef step = fori_arg(J, fori, ra+FORL_STEP, t); | 2264 | TRef step = fori_arg(J, fori, ra+FORL_STEP, t); |
2259 | int dir = (0 <= numV(&forbase[FORL_STEP])); | 2265 | int dir = (0 <= numV(&forbase[FORL_STEP])); |
2260 | lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI); | 2266 | lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI); |
2267 | J->scev.t.irt = t; | ||
2268 | J->scev.dir = dir; | ||
2269 | J->scev.stop = tref_ref(stop); | ||
2270 | J->scev.step = tref_ref(step); | ||
2261 | if (!tref_isk(step)) { | 2271 | if (!tref_isk(step)) { |
2262 | /* Non-constant step: need a guard for the direction. */ | 2272 | /* Non-constant step: need a guard for the direction. */ |
2263 | TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J); | 2273 | TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J); |
@@ -2285,9 +2295,11 @@ static void rec_setup_forl(jit_State *J, const BCIns *fori) | |||
2285 | k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k; | 2295 | k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k; |
2286 | emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k)); | 2296 | emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k)); |
2287 | } | 2297 | } |
2288 | if (t == IRT_INT && !find_kinit(J, fori, ra+FORL_IDX, IRT_INT)) | 2298 | J->scev.start = tref_ref(find_kinit(J, fori, ra+FORL_IDX, IRT_INT)); |
2299 | if (t == IRT_INT && !J->scev.start) | ||
2289 | t |= IRT_GUARD; | 2300 | t |= IRT_GUARD; |
2290 | J->base[ra+FORL_EXT] = sloadt(J, (int32_t)(ra+FORL_IDX), t, IRSLOAD_INHERIT); | 2301 | J->base[ra+FORL_EXT] = sloadt(J, (int32_t)(ra+FORL_IDX), t, IRSLOAD_INHERIT); |
2302 | J->scev.idx = tref_ref(J->base[ra+FORL_EXT]); | ||
2291 | J->maxslot = ra+FORL_EXT+1; | 2303 | J->maxslot = ra+FORL_EXT+1; |
2292 | } | 2304 | } |
2293 | 2305 | ||
@@ -2403,6 +2415,7 @@ void lj_record_setup(jit_State *J) | |||
2403 | memset(J->slot, 0, sizeof(J->slot)); | 2415 | memset(J->slot, 0, sizeof(J->slot)); |
2404 | memset(J->chain, 0, sizeof(J->chain)); | 2416 | memset(J->chain, 0, sizeof(J->chain)); |
2405 | memset(J->bpropcache, 0, sizeof(J->bpropcache)); | 2417 | memset(J->bpropcache, 0, sizeof(J->bpropcache)); |
2418 | J->scev.idx = REF_NIL; | ||
2406 | 2419 | ||
2407 | J->baseslot = 1; /* Invoking function is at base[-1]. */ | 2420 | J->baseslot = 1; /* Invoking function is at base[-1]. */ |
2408 | J->base = J->slot + J->baseslot; | 2421 | J->base = J->slot + J->baseslot; |