Fix narrowing of TOBIT.

This commit is contained in:
Mike Pall 2015-06-10 16:14:41 +02:00
parent 72347895ed
commit 7f454aed82

View File

@ -205,7 +205,6 @@ typedef struct NarrowConv {
jit_State *J; /* JIT compiler state. */
NarrowIns *sp; /* Current stack pointer. */
NarrowIns *maxsp; /* Maximum stack pointer minus redzone. */
int lim; /* Limit on the number of emitted conversions. */
IRRef mode; /* Conversion mode (IRCONV_*). */
IRType t; /* Destination type: IRT_INT or IRT_I64. */
NarrowIns stack[NARROW_MAX_STACK]; /* Stack holding stack-machine code. */
@ -342,7 +341,7 @@ static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth)
NarrowIns *savesp = nc->sp;
int count = narrow_conv_backprop(nc, ir->op1, depth);
count += narrow_conv_backprop(nc, ir->op2, depth);
if (count <= nc->lim) { /* Limit total number of conversions. */
if (count <= 1) { /* Limit total number of conversions. */
*nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref);
return count;
}
@ -414,12 +413,10 @@ TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J)
nc.t = irt_type(fins->t);
if (fins->o == IR_TOBIT) {
nc.mode = IRCONV_TOBIT; /* Used only in the backpropagation cache. */
nc.lim = 2; /* TOBIT can use a more optimistic rule. */
} else {
nc.mode = fins->op2;
nc.lim = 1;
}
if (narrow_conv_backprop(&nc, fins->op1, 0) <= nc.lim)
if (narrow_conv_backprop(&nc, fins->op1, 0) <= 1)
return narrow_conv_emit(J, &nc);
}
return NEXTFOLD;