Skip to content

Commit a82cfc2

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Tracing JIT: Use packed array guards for ASSIGN_DIM_OP and allow to move them out of loops.
2 parents e04c7eb + e5541c9 commit a82cfc2

File tree

3 files changed

+81
-49
lines changed

3 files changed

+81
-49
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5101,32 +5101,35 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
51015101
|.code
51025102
break;
51035103
case BP_VAR_RW:
5104-
if (packed_loaded) {
5105-
if (not_found_exit_addr) {
5104+
if (packed_loaded && !not_found_exit_addr) {
5105+
| IF_NOT_Z_TYPE REG0, IS_UNDEF, >8, TMP1w
5106+
}
5107+
if (!packed_loaded ||
5108+
!not_found_exit_addr ||
5109+
(op1_info & MAY_BE_ARRAY_NUMERIC_HASH)) {
5110+
if (packed_loaded && not_found_exit_addr) {
51065111
|.cold_code
5107-
} else {
5108-
| IF_NOT_Z_TYPE REG0, IS_UNDEF, >8, TMP1w
51095112
}
5110-
}
5111-
|2:
5112-
|4:
5113-
if (!op2_loaded) {
5114-
| // hval = Z_LVAL_P(dim);
5115-
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr, TMP1
5116-
}
5117-
| SET_EX_OPLINE opline, REG0
5118-
| EXT_CALL zend_jit_hash_index_lookup_rw, REG0
5119-
| mov REG0, RETVALx
5120-
if (not_found_exit_addr) {
5121-
if (packed_loaded) {
5122-
| cbnz REG0, >8
5123-
| b &not_found_exit_addr
5124-
|.code
5113+
|2:
5114+
|4:
5115+
if (!op2_loaded) {
5116+
| // hval = Z_LVAL_P(dim);
5117+
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr, TMP1
5118+
}
5119+
| SET_EX_OPLINE opline, REG0
5120+
| EXT_CALL zend_jit_hash_index_lookup_rw, REG0
5121+
| mov REG0, RETVALx
5122+
if (not_found_exit_addr) {
5123+
if (packed_loaded) {
5124+
| cbnz REG0, >8
5125+
| b &not_found_exit_addr
5126+
|.code
5127+
} else {
5128+
| cbz REG0, &not_found_exit_addr
5129+
}
51255130
} else {
5126-
| cbz REG0, &not_found_exit_addr
5131+
| cbz REG0, >9
51275132
}
5128-
} else {
5129-
| cbz REG0, >9
51305133
}
51315134
break;
51325135
case BP_VAR_W:

ext/opcache/jit/zend_jit_trace.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
15681568
for (;;p++) {
15691569
if (p->op == ZEND_JIT_TRACE_VM) {
15701570
uint8_t orig_op1_type, orig_op2_type, op1_type, op2_type, op3_type;
1571+
uint8_t val_type = IS_UNKNOWN;
15711572
// zend_class_entry *op1_ce = NULL;
15721573
zend_class_entry *op2_ce = NULL;
15731574

@@ -1598,6 +1599,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
15981599
p++;
15991600
}
16001601
if ((p+1)->op == ZEND_JIT_TRACE_VAL_INFO) {
1602+
val_type = (p+1)->op1_type;
16011603
p++;
16021604
}
16031605

@@ -1638,17 +1640,27 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
16381640
ADD_OP2_TRACE_GUARD();
16391641
}
16401642
if (op1_type == IS_ARRAY
1641-
&& !(orig_op1_type & IS_TRACE_PACKED)
16421643
&& ((opline->op2_type == IS_CONST
16431644
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_LONG)
16441645
|| (opline->op2_type != IS_CONST
16451646
&& op2_type == IS_LONG))) {
16461647

1647-
zend_ssa_var_info *info = &tssa->var_info[tssa->ops[idx].op1_use];
1648+
if (!(orig_op1_type & IS_TRACE_PACKED)) {
1649+
zend_ssa_var_info *info = &tssa->var_info[tssa->ops[idx].op1_use];
16481650

1649-
if (MAY_BE_PACKED(info->type) && MAY_BE_HASH(info->type)) {
1650-
info->type |= MAY_BE_PACKED_GUARD;
1651-
info->type &= ~MAY_BE_ARRAY_PACKED;
1651+
if (MAY_BE_PACKED(info->type) && MAY_BE_HASH(info->type)) {
1652+
info->type |= MAY_BE_PACKED_GUARD;
1653+
info->type &= ~MAY_BE_ARRAY_PACKED;
1654+
}
1655+
} else if (opline->opcode == ZEND_ASSIGN_DIM_OP
1656+
&& val_type != IS_UNKNOWN
1657+
&& val_type != IS_UNDEF) {
1658+
zend_ssa_var_info *info = &tssa->var_info[tssa->ops[idx].op1_use];
1659+
1660+
if (MAY_BE_PACKED(info->type) && MAY_BE_HASH(info->type)) {
1661+
info->type |= MAY_BE_PACKED_GUARD;
1662+
info->type &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
1663+
}
16521664
}
16531665
}
16541666
break;
@@ -2072,6 +2084,20 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
20722084
// TODO:
20732085
assert(0);
20742086
}
2087+
if (opline->opcode == ZEND_ASSIGN_DIM_OP
2088+
&& ssa_ops[idx].op1_def > 0
2089+
&& op1_type == IS_ARRAY
2090+
&& (orig_op1_type & IS_TRACE_PACKED)
2091+
&& val_type != IS_UNKNOWN
2092+
&& val_type != IS_UNDEF
2093+
&& ((opline->op2_type == IS_CONST
2094+
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_LONG)
2095+
|| (opline->op2_type != IS_CONST
2096+
&& op2_type == IS_LONG))) {
2097+
zend_ssa_var_info *info = &ssa_var_info[ssa_ops[idx].op1_def];
2098+
2099+
info->type &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
2100+
}
20752101
}
20762102
if (ssa->var_info) {
20772103
/* Add statically inferred restrictions */

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5568,32 +5568,35 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
55685568
|.code
55695569
break;
55705570
case BP_VAR_RW:
5571-
if (packed_loaded) {
5572-
if (not_found_exit_addr) {
5571+
if (packed_loaded && !not_found_exit_addr) {
5572+
| IF_NOT_Z_TYPE r0, IS_UNDEF, >8
5573+
}
5574+
if (!packed_loaded ||
5575+
!not_found_exit_addr ||
5576+
(op1_info & MAY_BE_ARRAY_NUMERIC_HASH)) {
5577+
if (packed_loaded && not_found_exit_addr) {
55735578
|.cold_code
5574-
} else {
5575-
| IF_NOT_Z_TYPE r0, IS_UNDEF, >8
55765579
}
5577-
}
5578-
|2:
5579-
|4:
5580-
if (!op2_loaded) {
5581-
| // hval = Z_LVAL_P(dim);
5582-
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr
5583-
}
5584-
| SET_EX_OPLINE opline, r0
5585-
| EXT_CALL zend_jit_hash_index_lookup_rw, r0
5586-
| test r0, r0
5587-
if (not_found_exit_addr) {
5588-
if (packed_loaded) {
5589-
| jnz >8
5590-
| jmp &not_found_exit_addr
5591-
|.code
5580+
|2:
5581+
|4:
5582+
if (!op2_loaded) {
5583+
| // hval = Z_LVAL_P(dim);
5584+
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr
5585+
}
5586+
| SET_EX_OPLINE opline, r0
5587+
| EXT_CALL zend_jit_hash_index_lookup_rw, r0
5588+
| test r0, r0
5589+
if (not_found_exit_addr) {
5590+
if (packed_loaded) {
5591+
| jnz >8
5592+
| jmp &not_found_exit_addr
5593+
|.code
5594+
} else {
5595+
| jz &not_found_exit_addr
5596+
}
55925597
} else {
5593-
| jz &not_found_exit_addr
5598+
| jz >9
55945599
}
5595-
} else {
5596-
| jz >9
55975600
}
55985601
break;
55995602
case BP_VAR_W:

0 commit comments

Comments
 (0)