@@ -4966,7 +4966,6 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
49664966{
49674967 zend_bool same_ops = zend_jit_same_addr(op1_addr, op2_addr);
49684968 zend_reg result_reg;
4969- zval tmp;
49704969
49714970 if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) {
49724971 | IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >6
@@ -4975,19 +4974,6 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
49754974 | IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >6
49764975 }
49774976
4978- if (opcode == ZEND_MOD && Z_MODE(op2_addr) == IS_CONST_ZVAL &&
4979- op1_range &&
4980- op1_range->min >= 0) {
4981- zend_long l = Z_LVAL_P(Z_ZV(op2_addr));
4982-
4983- if (zend_long_is_power_of_two(l)) {
4984- /* Optimisation for mod of power of 2 */
4985- opcode = ZEND_BW_AND;
4986- ZVAL_LONG(&tmp, l - 1);
4987- op2_addr = ZEND_ADDR_CONST_ZVAL(&tmp);
4988- }
4989- }
4990-
49914977 if (opcode == ZEND_MOD) {
49924978 result_reg = ZREG_RAX;
49934979 if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RAX) {
@@ -5097,6 +5083,15 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
50975083 if (op2_lval == 0) {
50985084 | SET_EX_OPLINE opline, r0
50995085 | jmp ->mod_by_zero
5086+ } else if (zend_long_is_power_of_two(op2_lval) && op1_range && op1_range->min >= 0) {
5087+ zval tmp;
5088+ zend_jit_addr tmp_addr;
5089+
5090+ /* Optimisation for mod of power of 2 */
5091+ ZVAL_LONG(&tmp, op2_lval - 1);
5092+ tmp_addr = ZEND_ADDR_CONST_ZVAL(&tmp);
5093+ | GET_ZVAL_LVAL result_reg, op1_addr
5094+ | LONG_MATH ZEND_BW_AND, result_reg, tmp_addr
51005095 } else {
51015096 result_reg = ZREG_RDX;
51025097 if (op2_lval == -1) {
0 commit comments