@@ -4966,7 +4966,6 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
4966
4966
{
4967
4967
zend_bool same_ops = zend_jit_same_addr(op1_addr, op2_addr);
4968
4968
zend_reg result_reg;
4969
- zval tmp;
4970
4969
4971
4970
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) {
4972
4971
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >6
@@ -4975,19 +4974,6 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
4975
4974
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >6
4976
4975
}
4977
4976
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
-
4991
4977
if (opcode == ZEND_MOD) {
4992
4978
result_reg = ZREG_RAX;
4993
4979
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,
5097
5083
if (op2_lval == 0) {
5098
5084
| SET_EX_OPLINE opline, r0
5099
5085
| 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
5100
5095
} else {
5101
5096
result_reg = ZREG_RDX;
5102
5097
if (op2_lval == -1) {
0 commit comments