Skip to content

Commit f1536eb

Browse files
committed
JMP optimization
1 parent 1f12d9d commit f1536eb

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4784,7 +4784,7 @@ static int zend_jit_concat(dasm_State **Dst, const zend_op *opline, const zend_o
47844784
return zend_jit_concat_helper(Dst, opline, op_array, opline->op1_type, opline->op1, op1_addr, op1_info, opline->op2_type, opline->op2, op2_addr, op2_info, res_addr, res_info, may_throw);
47854785
}
47864786

4787-
static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_op *opline, uint32_t type, uint32_t op1_info, uint32_t op2_info, uint32_t found, uint32_t not_found)
4787+
static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_op *opline, uint32_t type, uint32_t op1_info, uint32_t op2_info, uint32_t found, uint32_t not_found, const void *found_exit_addr, const void *not_found_exit_addr)
47884788
/* Labels: 1,2,3,4,5 */
47894789
{
47904790
zend_jit_addr op2_addr = OP2_ADDR();
@@ -4827,7 +4827,11 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
48274827
| cmp dword [FCARG1a + offsetof(zend_array, nNumUsed)], val
48284828
|.endif
48294829
if (type == BP_JIT_IS) {
4830-
| jbe >9 // NOT_FOUND
4830+
if (not_found_exit_addr) {
4831+
| jbe &not_found_exit_addr
4832+
} else {
4833+
| jbe >9 // NOT_FOUND
4834+
}
48314835
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && (type == BP_VAR_R || type == BP_VAR_RW)) {
48324836
| jbe &exit_addr
48334837
} else {
@@ -4860,7 +4864,11 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
48604864
| cmp dword [FCARG1a + offsetof(zend_array, nNumUsed)], FCARG2a
48614865
|.endif
48624866
if (type == BP_JIT_IS) {
4863-
| jbe >9 // NOT_FOUND
4867+
if (not_found_exit_addr) {
4868+
| jbe &not_found_exit_addr
4869+
} else {
4870+
| jbe >9 // NOT_FOUND
4871+
}
48644872
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && (type == BP_VAR_R || type == BP_VAR_RW)) {
48654873
| jbe &exit_addr
48664874
} else {
@@ -4892,7 +4900,11 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
48924900
}
48934901
| EXT_CALL _zend_hash_index_find, r0
48944902
| test r0, r0
4895-
| jz >9 // NOT_FOUND
4903+
if (not_found_exit_addr) {
4904+
| jz &not_found_exit_addr
4905+
} else {
4906+
| jz >9 // NOT_FOUND
4907+
}
48964908
if (op2_info & MAY_BE_STRING) {
48974909
| jmp >5
48984910
}
@@ -5020,7 +5032,11 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
50205032
| EXT_CALL _zend_hash_find_known_hash, r0
50215033
}
50225034
| test r0, r0
5023-
| jz >9 // NOT_FOUND
5035+
if (not_found_exit_addr) {
5036+
| jz &not_found_exit_addr
5037+
} else {
5038+
| jz >9 // NOT_FOUND
5039+
}
50245040
| // if (UNEXPECTED(Z_TYPE_P(retval) == IS_INDIRECT))
50255041
| IF_NOT_Z_TYPE r0, IS_INDIRECT, >1
50265042
| GET_Z_PTR r0, r0
@@ -5101,7 +5117,13 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
51015117
| ZVAL_DEREF r0, MAY_BE_REF
51025118
}
51035119
| cmp byte [r0 + 8], IS_NULL
5104-
| jle >9 // NOT FOUND
5120+
if (not_found_exit_addr) {
5121+
| jle &not_found_exit_addr
5122+
} else if (found_exit_addr) {
5123+
| jg &found_exit_addr
5124+
} else {
5125+
| jle >9 // NOT FOUND
5126+
}
51055127
}
51065128

51075129
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING))) {
@@ -5534,7 +5556,7 @@ static int zend_jit_assign_dim(dasm_State **Dst, const zend_op *opline, const ze
55345556
uint32_t var_info = zend_array_element_type(op1_info, 0, 0);
55355557
zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG1a, 0);
55365558

5537-
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, BP_VAR_W, op1_info, op2_info, 8, 8)) {
5559+
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, BP_VAR_W, op1_info, op2_info, 8, 8, NULL, NULL)) {
55385560
return 0;
55395561
}
55405562

@@ -5755,7 +5777,7 @@ static int zend_jit_assign_dim_op(dasm_State **Dst, const zend_op *opline, const
57555777
var_info |= MAY_BE_REF;
57565778
}
57575779

5758-
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, BP_VAR_RW, op1_info, op2_info, 8, 8)) {
5780+
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, BP_VAR_RW, op1_info, op2_info, 8, 8, NULL, NULL)) {
57595781
return 0;
57605782
}
57615783

@@ -10170,7 +10192,7 @@ static int zend_jit_fetch_dim_read(dasm_State **Dst, const zend_op *opline, cons
1017010192
}
1017110193
}
1017210194
| GET_ZVAL_LVAL ZREG_FCARG1a, op1_addr
10173-
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, (opline->opcode != ZEND_FETCH_DIM_IS) ? BP_VAR_R : BP_VAR_IS, op1_info, op2_info, 8, 9)) {
10195+
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, (opline->opcode != ZEND_FETCH_DIM_IS) ? BP_VAR_R : BP_VAR_IS, op1_info, op2_info, 8, 9, NULL, NULL)) {
1017410196
return 0;
1017510197
}
1017610198
}
@@ -10352,13 +10374,35 @@ static int zend_jit_isset_isempty_dim(dasm_State **Dst, const zend_op *opline, c
1035210374
}
1035310375

1035410376
if (op1_info & MAY_BE_ARRAY) {
10377+
const void *found_exit_addr = NULL;
10378+
const void *not_found_exit_addr = NULL;
10379+
1035510380
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_ARRAY)) {
1035610381
| IF_NOT_ZVAL_TYPE op1_addr, IS_ARRAY, >7
1035710382
}
1035810383
| GET_ZVAL_LVAL ZREG_FCARG1a, op1_addr
10359-
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, BP_JIT_IS, op1_info, op2_info, 8, 9)) {
10384+
if (exit_addr
10385+
&& !(op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_ARRAY))
10386+
&& !may_throw
10387+
&& !(opline->op1_type & (IS_TMP_VAR|IS_VAR))
10388+
&& (!(opline->op2_type & (IS_TMP_VAR|IS_VAR)) || !(op2_info & MAY_BE_LONG))) {
10389+
if (smart_branch_opcode == ZEND_JMPNZ) {
10390+
found_exit_addr = exit_addr;
10391+
} else {
10392+
not_found_exit_addr = exit_addr;
10393+
}
10394+
}
10395+
if (!zend_jit_fetch_dimension_address_inner(Dst, opline, BP_JIT_IS, op1_info, op2_info, 8, 9, found_exit_addr, not_found_exit_addr)) {
1036010396
return 0;
1036110397
}
10398+
10399+
if (found_exit_addr) {
10400+
|9:
10401+
return 1;
10402+
} else if (not_found_exit_addr) {
10403+
|8:
10404+
return 1;
10405+
}
1036210406
}
1036310407

1036410408
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_ARRAY)) {

0 commit comments

Comments
 (0)