@@ -4162,6 +4162,22 @@ static int zend_jit_inc_dec(dasm_State **Dst, const zend_op *opline, uint32_t op
4162
4162
return 1;
4163
4163
}
4164
4164
4165
+ static int zend_jit_opline_uses_reg(const zend_op *opline, int8_t reg)
4166
+ {
4167
+ if ((opline+1)->opcode == ZEND_OP_DATA
4168
+ && ((opline+1)->op1_type & (IS_VAR|IS_TMP_VAR|IS_CV))
4169
+ && JIT_G(current_frame)->stack[EX_VAR_TO_NUM((opline+1)->op1.var)].reg == reg) {
4170
+ return 1;
4171
+ }
4172
+ return
4173
+ ((opline->result_type & (IS_VAR|IS_TMP_VAR|IS_CV)) &&
4174
+ JIT_G(current_frame)->stack[EX_VAR_TO_NUM(opline->result.var)].reg == reg) ||
4175
+ ((opline->op1_type & (IS_VAR|IS_TMP_VAR|IS_CV)) &&
4176
+ JIT_G(current_frame)->stack[EX_VAR_TO_NUM(opline->op1.var)].reg == reg) ||
4177
+ ((opline->op2_type & (IS_VAR|IS_TMP_VAR|IS_CV)) &&
4178
+ JIT_G(current_frame)->stack[EX_VAR_TO_NUM(opline->op2.var)].reg == reg);
4179
+ }
4180
+
4165
4181
static int zend_jit_math_long_long(dasm_State **Dst,
4166
4182
const zend_op *opline,
4167
4183
zend_uchar opcode,
@@ -4176,7 +4192,14 @@ static int zend_jit_math_long_long(dasm_State **Dst,
4176
4192
zend_reg result_reg;
4177
4193
4178
4194
if (Z_MODE(res_addr) == IS_REG && (res_info & MAY_BE_LONG)) {
4179
- result_reg = Z_REG(res_addr);
4195
+ if (may_overflow && (res_info & MAY_BE_GUARD)
4196
+ && JIT_G(current_frame)
4197
+ && JIT_G(current_frame)->stack
4198
+ && zend_jit_opline_uses_reg(opline, Z_REG(res_addr))) {
4199
+ result_reg = ZREG_R0;
4200
+ } else {
4201
+ result_reg = Z_REG(res_addr);
4202
+ }
4180
4203
} else if (Z_MODE(op1_addr) == IS_REG && Z_LAST_USE(op1_addr)) {
4181
4204
result_reg = Z_REG(op1_addr);
4182
4205
} else if (Z_REG(res_addr) != ZREG_R0) {
@@ -4247,6 +4270,9 @@ static int zend_jit_math_long_long(dasm_State **Dst,
4247
4270
const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point);
4248
4271
if ((res_info & MAY_BE_ANY) == MAY_BE_LONG) {
4249
4272
| jo &exit_addr
4273
+ if (Z_MODE(res_addr) == IS_REG && result_reg != Z_REG(res_addr)) {
4274
+ | mov Ra(Z_REG(res_addr)), Ra(result_reg)
4275
+ }
4250
4276
} else if ((res_info & MAY_BE_ANY) == MAY_BE_DOUBLE) {
4251
4277
| jno &exit_addr
4252
4278
} else {
0 commit comments