diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_opt_fold.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index 706fbc90..acbf36a5 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
@@ -1688,6 +1688,47 @@ LJFOLDF(simplify_andk_shiftk) | |||
1688 | return NEXTFOLD; | 1688 | return NEXTFOLD; |
1689 | } | 1689 | } |
1690 | 1690 | ||
1691 | LJFOLD(BAND BOR KINT) | ||
1692 | LJFOLD(BOR BAND KINT) | ||
1693 | LJFOLDF(simplify_andor_k) | ||
1694 | { | ||
1695 | IRIns *irk = IR(fleft->op2); | ||
1696 | PHIBARRIER(fleft); | ||
1697 | if (irk->o == IR_KINT) { | ||
1698 | int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o); | ||
1699 | /* (i | k1) & k2 ==> i & k2, if (k1 & k2) == 0. */ | ||
1700 | /* (i & k1) | k2 ==> i | k2, if (k1 | k2) == -1. */ | ||
1701 | if (k == (fins->o == IR_BAND ? 0 : -1)) { | ||
1702 | fins->op1 = fleft->op1; | ||
1703 | return RETRYFOLD; | ||
1704 | } | ||
1705 | } | ||
1706 | return NEXTFOLD; | ||
1707 | } | ||
1708 | |||
1709 | LJFOLD(BAND BOR KINT64) | ||
1710 | LJFOLD(BOR BAND KINT64) | ||
1711 | LJFOLDF(simplify_andor_k64) | ||
1712 | { | ||
1713 | #if LJ_HASFFI | ||
1714 | IRIns *irk = IR(fleft->op2); | ||
1715 | PHIBARRIER(fleft); | ||
1716 | if (irk->o == IR_KINT64) { | ||
1717 | uint64_t k = kfold_int64arith(ir_k64(irk)->u64, | ||
1718 | ir_k64(fright)->u64, (IROp)fins->o); | ||
1719 | /* (i | k1) & k2 ==> i & k2, if (k1 & k2) == 0. */ | ||
1720 | /* (i & k1) | k2 ==> i | k2, if (k1 | k2) == -1. */ | ||
1721 | if (k == (fins->o == IR_BAND ? (uint64_t)0 : ~(uint64_t)0)) { | ||
1722 | fins->op1 = fleft->op1; | ||
1723 | return RETRYFOLD; | ||
1724 | } | ||
1725 | } | ||
1726 | return NEXTFOLD; | ||
1727 | #else | ||
1728 | UNUSED(J); lua_assert(0); return FAILFOLD; | ||
1729 | #endif | ||
1730 | } | ||
1731 | |||
1691 | /* -- Reassociation ------------------------------------------------------- */ | 1732 | /* -- Reassociation ------------------------------------------------------- */ |
1692 | 1733 | ||
1693 | LJFOLD(ADD ADD KINT) | 1734 | LJFOLD(ADD ADD KINT) |