Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
fold: keep type of emitted CONV in sync with its mode
Browse files Browse the repository at this point in the history
Alternative fix for #37

When emitting CONV make sure that its type matches its destination IRType.

This keeps IR fully internally consistent with respect to types - i.e. if
we push narrowing CONV Dt.St upwards through an arithmetic operation of type
St we end up with arithmetic operation of type Dt and two convertions
CONV Dt.St which narrow the operands.

Previous variantion of the fix introduced slight inconsistency with types
(inserted convertions were CONV int.St while arithmetic operation was still of
type Dt).

Signed-off-by: Vyacheslav Egorov <vegorov@google.com>
  • Loading branch information
mraleph committed Nov 25, 2019
1 parent 8a3c054 commit 8a0aaa3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/lj_opt_fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,10 +1260,9 @@ LJFOLDF(simplify_conv_narrow)
IROp op = (IROp)fleft->o;
IRType t = irt_type(fins->t);
IRRef op1 = fleft->op1, op2 = fleft->op2, mode = fins->op2;
mode = (IRT_INT << IRCONV_DSH) | (mode & IRCONV_SRCMASK);
PHIBARRIER(fleft);
op1 = emitir(IRTI(IR_CONV), op1, mode);
op2 = emitir(IRTI(IR_CONV), op2, mode);
op1 = emitir(IRT(IR_CONV, t), op1, mode);
op2 = emitir(IRT(IR_CONV, t), op2, mode);
fins->ot = IRT(op, t);
fins->op1 = op1;
fins->op2 = op2;
Expand Down

0 comments on commit 8a0aaa3

Please sign in to comment.