Skip to content

Commit 037bfab

Browse files
committed
Optimization for +/- int(0)
1 parent 50af4de commit 037bfab

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,7 +3843,12 @@ static int zend_jit_math_long_long(dasm_State **Dst,
38433843
| lea Ra(result_reg), [Ra(Z_REG(op1_addr))-Z_LVAL_P(Z_ZV(op2_addr))]
38443844
} else {
38453845
| GET_ZVAL_LVAL result_reg, op1_addr
3846-
if (same_ops && opcode != ZEND_DIV) {
3846+
if ((opcode == ZEND_ADD || opcode == ZEND_SUB)
3847+
&& Z_MODE(op2_addr) == IS_CONST_ZVAL
3848+
&& Z_LVAL_P(Z_ZV(op2_addr)) == 0) {
3849+
/* +/- 0 */
3850+
may_overflow = 0;
3851+
} else if (same_ops && opcode != ZEND_DIV) {
38473852
| LONG_MATH_REG opcode, Ra(result_reg), Ra(result_reg)
38483853
} else {
38493854
| LONG_MATH opcode, result_reg, op2_addr
@@ -3990,12 +3995,24 @@ static int zend_jit_math_double_long(dasm_State **Dst,
39903995
| SSE_GET_ZVAL_DVAL result_reg, op1_addr
39913996
op1_reg = result_reg;
39923997
}
3993-
| SSE_GET_ZVAL_LVAL tmp_reg, op2_addr
3994-
| AVX_MATH_REG opcode, result_reg, op1_reg, tmp_reg
3998+
if ((opcode == ZEND_ADD || opcode == ZEND_SUB)
3999+
&& Z_MODE(op2_addr) == IS_CONST_ZVAL
4000+
&& Z_LVAL_P(Z_ZV(op2_addr)) == 0) {
4001+
/* +/- 0 */
4002+
} else {
4003+
| SSE_GET_ZVAL_LVAL tmp_reg, op2_addr
4004+
| AVX_MATH_REG opcode, result_reg, op1_reg, tmp_reg
4005+
}
39954006
} else {
39964007
| SSE_GET_ZVAL_DVAL result_reg, op1_addr
3997-
| SSE_GET_ZVAL_LVAL tmp_reg, op2_addr
3998-
| SSE_MATH_REG opcode, result_reg, tmp_reg
4008+
if ((opcode == ZEND_ADD || opcode == ZEND_SUB)
4009+
&& Z_MODE(op2_addr) == IS_CONST_ZVAL
4010+
&& Z_LVAL_P(Z_ZV(op2_addr)) == 0) {
4011+
/* +/- 0 */
4012+
} else {
4013+
| SSE_GET_ZVAL_LVAL tmp_reg, op2_addr
4014+
| SSE_MATH_REG opcode, result_reg, tmp_reg
4015+
}
39994016
}
40004017
}
40014018
| SSE_SET_ZVAL_DVAL res_addr, result_reg

0 commit comments

Comments
 (0)