mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Add FOLD rules for mixed BAND/BOR with constants.
This commit is contained in:
parent
fbfbd7b9e1
commit
cf8a5bea89
@ -1688,6 +1688,47 @@ LJFOLDF(simplify_andk_shiftk)
|
|||||||
return NEXTFOLD;
|
return NEXTFOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LJFOLD(BAND BOR KINT)
|
||||||
|
LJFOLD(BOR BAND KINT)
|
||||||
|
LJFOLDF(simplify_andor_k)
|
||||||
|
{
|
||||||
|
IRIns *irk = IR(fleft->op2);
|
||||||
|
PHIBARRIER(fleft);
|
||||||
|
if (irk->o == IR_KINT) {
|
||||||
|
int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);
|
||||||
|
/* (i | k1) & k2 ==> i & k2, if (k1 & k2) == 0. */
|
||||||
|
/* (i & k1) | k2 ==> i | k2, if (k1 | k2) == -1. */
|
||||||
|
if (k == (fins->o == IR_BAND ? 0 : -1)) {
|
||||||
|
fins->op1 = fleft->op1;
|
||||||
|
return RETRYFOLD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NEXTFOLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
LJFOLD(BAND BOR KINT64)
|
||||||
|
LJFOLD(BOR BAND KINT64)
|
||||||
|
LJFOLDF(simplify_andor_k64)
|
||||||
|
{
|
||||||
|
#if LJ_HASFFI
|
||||||
|
IRIns *irk = IR(fleft->op2);
|
||||||
|
PHIBARRIER(fleft);
|
||||||
|
if (irk->o == IR_KINT64) {
|
||||||
|
uint64_t k = kfold_int64arith(ir_k64(irk)->u64,
|
||||||
|
ir_k64(fright)->u64, (IROp)fins->o);
|
||||||
|
/* (i | k1) & k2 ==> i & k2, if (k1 & k2) == 0. */
|
||||||
|
/* (i & k1) | k2 ==> i | k2, if (k1 | k2) == -1. */
|
||||||
|
if (k == (fins->o == IR_BAND ? (uint64_t)0 : ~(uint64_t)0)) {
|
||||||
|
fins->op1 = fleft->op1;
|
||||||
|
return RETRYFOLD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NEXTFOLD;
|
||||||
|
#else
|
||||||
|
UNUSED(J); lua_assert(0); return FAILFOLD;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* -- Reassociation ------------------------------------------------------- */
|
/* -- Reassociation ------------------------------------------------------- */
|
||||||
|
|
||||||
LJFOLD(ADD ADD KINT)
|
LJFOLD(ADD ADD KINT)
|
||||||
|
Loading…
Reference in New Issue
Block a user