Skip to content

Commit

Permalink
Tracing JIT: Use packed array guards for ASSIGN_DIM_OP and allow to m…
Browse files Browse the repository at this point in the history
…ove them out of loops.
  • Loading branch information
dstogov committed Sep 17, 2021
1 parent a30c121 commit e5541c9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 49 deletions.
47 changes: 25 additions & 22 deletions ext/opcache/jit/zend_jit_arm64.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -5101,32 +5101,35 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
|.code
break;
case BP_VAR_RW:
if (packed_loaded) {
if (not_found_exit_addr) {
if (packed_loaded && !not_found_exit_addr) {
| IF_NOT_Z_TYPE REG0, IS_UNDEF, >8, TMP1w
}
if (!packed_loaded ||
!not_found_exit_addr ||
(op1_info & MAY_BE_ARRAY_NUMERIC_HASH)) {
if (packed_loaded && not_found_exit_addr) {
|.cold_code
} else {
| IF_NOT_Z_TYPE REG0, IS_UNDEF, >8, TMP1w
}
}
|2:
|4:
if (!op2_loaded) {
| // hval = Z_LVAL_P(dim);
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr, TMP1
}
| SET_EX_OPLINE opline, REG0
| EXT_CALL zend_jit_hash_index_lookup_rw, REG0
| mov REG0, RETVALx
if (not_found_exit_addr) {
if (packed_loaded) {
| cbnz REG0, >8
| b &not_found_exit_addr
|.code
|2:
|4:
if (!op2_loaded) {
| // hval = Z_LVAL_P(dim);
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr, TMP1
}
| SET_EX_OPLINE opline, REG0
| EXT_CALL zend_jit_hash_index_lookup_rw, REG0
| mov REG0, RETVALx
if (not_found_exit_addr) {
if (packed_loaded) {
| cbnz REG0, >8
| b &not_found_exit_addr
|.code
} else {
| cbz REG0, &not_found_exit_addr
}
} else {
| cbz REG0, &not_found_exit_addr
| cbz REG0, >9
}
} else {
| cbz REG0, >9
}
break;
case BP_VAR_W:
Expand Down
36 changes: 31 additions & 5 deletions ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
for (;;p++) {
if (p->op == ZEND_JIT_TRACE_VM) {
uint8_t orig_op1_type, orig_op2_type, op1_type, op2_type, op3_type;
uint8_t val_type = IS_UNKNOWN;
// zend_class_entry *op1_ce = NULL;
zend_class_entry *op2_ce = NULL;

Expand Down Expand Up @@ -1598,6 +1599,7 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
p++;
}
if ((p+1)->op == ZEND_JIT_TRACE_VAL_INFO) {
val_type = (p+1)->op1_type;
p++;
}

Expand Down Expand Up @@ -1638,17 +1640,27 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
ADD_OP2_TRACE_GUARD();
}
if (op1_type == IS_ARRAY
&& !(orig_op1_type & IS_TRACE_PACKED)
&& ((opline->op2_type == IS_CONST
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_LONG)
|| (opline->op2_type != IS_CONST
&& op2_type == IS_LONG))) {

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

if (MAY_BE_PACKED(info->type) && MAY_BE_HASH(info->type)) {
info->type |= MAY_BE_PACKED_GUARD;
info->type &= ~MAY_BE_ARRAY_PACKED;
if (MAY_BE_PACKED(info->type) && MAY_BE_HASH(info->type)) {
info->type |= MAY_BE_PACKED_GUARD;
info->type &= ~MAY_BE_ARRAY_PACKED;
}
} else if (opline->opcode == ZEND_ASSIGN_DIM_OP
&& val_type != IS_UNKNOWN
&& val_type != IS_UNDEF) {
zend_ssa_var_info *info = &tssa->var_info[tssa->ops[idx].op1_use];

if (MAY_BE_PACKED(info->type) && MAY_BE_HASH(info->type)) {
info->type |= MAY_BE_PACKED_GUARD;
info->type &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
}
}
}
break;
Expand Down Expand Up @@ -2072,6 +2084,20 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
// TODO:
assert(0);
}
if (opline->opcode == ZEND_ASSIGN_DIM_OP
&& ssa_ops[idx].op1_def > 0
&& op1_type == IS_ARRAY
&& (orig_op1_type & IS_TRACE_PACKED)
&& val_type != IS_UNKNOWN
&& val_type != IS_UNDEF
&& ((opline->op2_type == IS_CONST
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_LONG)
|| (opline->op2_type != IS_CONST
&& op2_type == IS_LONG))) {
zend_ssa_var_info *info = &ssa_var_info[ssa_ops[idx].op1_def];

info->type &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH);
}
}
if (ssa->var_info) {
/* Add statically inferred restrictions */
Expand Down
47 changes: 25 additions & 22 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -5568,32 +5568,35 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o
|.code
break;
case BP_VAR_RW:
if (packed_loaded) {
if (not_found_exit_addr) {
if (packed_loaded && !not_found_exit_addr) {
| IF_NOT_Z_TYPE r0, IS_UNDEF, >8
}
if (!packed_loaded ||
!not_found_exit_addr ||
(op1_info & MAY_BE_ARRAY_NUMERIC_HASH)) {
if (packed_loaded && not_found_exit_addr) {
|.cold_code
} else {
| IF_NOT_Z_TYPE r0, IS_UNDEF, >8
}
}
|2:
|4:
if (!op2_loaded) {
| // hval = Z_LVAL_P(dim);
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr
}
| SET_EX_OPLINE opline, r0
| EXT_CALL zend_jit_hash_index_lookup_rw, r0
| test r0, r0
if (not_found_exit_addr) {
if (packed_loaded) {
| jnz >8
| jmp &not_found_exit_addr
|.code
|2:
|4:
if (!op2_loaded) {
| // hval = Z_LVAL_P(dim);
| GET_ZVAL_LVAL ZREG_FCARG2, op2_addr
}
| SET_EX_OPLINE opline, r0
| EXT_CALL zend_jit_hash_index_lookup_rw, r0
| test r0, r0
if (not_found_exit_addr) {
if (packed_loaded) {
| jnz >8
| jmp &not_found_exit_addr
|.code
} else {
| jz &not_found_exit_addr
}
} else {
| jz &not_found_exit_addr
| jz >9
}
} else {
| jz >9
}
break;
case BP_VAR_W:
Expand Down

0 comments on commit e5541c9

Please sign in to comment.