Skip to content

Commit 5488738

Browse files
committed
Micro optimization for commutative operators
1 parent 4af532a commit 5488738

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ static zend_bool zend_ssa_is_last_use(zend_op_array *op_array, const zend_ssa *s
9898
return use < 0 || zend_ssa_is_no_val_use(op_array->opcodes + use, ssa->ops + use, var);
9999
}
100100

101+
static zend_bool zend_is_commutative(zend_uchar opcode)
102+
{
103+
return
104+
opcode == ZEND_ADD ||
105+
opcode == ZEND_MUL ||
106+
opcode == ZEND_ASSIGN_ADD ||
107+
opcode == ZEND_ASSIGN_MUL;
108+
}
109+
101110
#include "dynasm/dasm_x86.h"
102111
#include "jit/zend_jit_x86.h"
103112
#include "jit/zend_jit_helpers.c"

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ static int zend_jit_math_double_long(dasm_State **Dst,
25252525
|.if SSE
25262526
zend_reg result_reg;
25272527

2528-
if (opline->opcode == ZEND_ADD || opline->opcode == ZEND_MUL || opline->opcode == ZEND_ASSIGN_ADD || opline->opcode == ZEND_ASSIGN_MUL) {
2528+
if (zend_is_commutative(opline->opcode)) {
25292529
if (Z_MODE(res_addr) == IS_REG) {
25302530
result_reg = Z_REG(res_addr);
25312531
} else {
@@ -2611,14 +2611,20 @@ static int zend_jit_math_double_double(dasm_State **Dst,
26112611

26122612
if (zend_jit_x86_flags & ZEND_JIT_CPU_AVX) {
26132613
zend_reg op1_reg;
2614+
zend_jit_addr val_addr;
26142615

26152616
if (Z_MODE(op1_addr) == IS_REG) {
26162617
op1_reg = Z_REG(op1_addr);
2618+
val_addr = op2_addr;
2619+
} else if (Z_MODE(op2_addr) == IS_REG && zend_is_commutative(opline->opcode)) {
2620+
op1_reg = Z_REG(op2_addr);
2621+
val_addr = op1_addr;
26172622
} else {
26182623
| SSE_GET_ZVAL_DVAL result_reg, op1_addr
2619-
op1_reg =result_reg;
2624+
op1_reg = result_reg;
2625+
val_addr = op2_addr;
26202626
}
2621-
| AVX_MATH opline->opcode, result_reg, op1_reg, op2_addr
2627+
| AVX_MATH opline->opcode, result_reg, op1_reg, val_addr
26222628
} else {
26232629
| SSE_GET_ZVAL_DVAL result_reg, op1_addr
26242630
if (same_ops) {

0 commit comments

Comments
 (0)