Closed XmiliaH closed 2 years ago
@XmiliaH Thanks for the report! We'll look into this. It seems like the optimizer needs to be aware of the nkeys IR.
I think the problem is in lj_opt_dse_ahstore
and can be fixed with:
@@ -369,7 +369,9 @@ TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)
** since they are followed by at least one guarded VLOAD.
*/
for (ir = IR(J->cur.nins-1); ir > store; ir--)
- if (irt_isguard(ir->t) || ir->o == IR_ALEN)
+ if (irt_isguard(ir->t) || ir->o == IR_ALEN ||
+ (ir->o == IR_CALLL && ir->op2 == IRCALL_lj_tab_nkeys) ||
+ (ir->o == IR_CALLS && ir->op2 == IRCALL_lj_tab_clone))
goto doemit; /* No elimination possible. */
/* Remove redundant store from chain and replace with NOP. */
*refp = store->prev;
@XmiliaH would you please create a PR for this issue?
It is possible that a
HSTORE
before a call totable.nkeys
ortable.clone
is eliminated by aHSTORE
after said functions resulting in wrong results.This is demonstrated by the following example which should print
0 nil
but the actual output is1 99999
.