Skip to content

Commit f4f6c13

Browse files
authored
Update trace type inference and abstract stack to be consistent with php#16339 (JIT support for ASSIGN_DIM[_OP] with IS_VAR op1) (php#16651)
1 parent 3c3a1df commit f4f6c13

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

ext/opcache/jit/zend_jit_ir.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -12726,7 +12726,7 @@ static int zend_jit_fetch_dim_read(zend_jit_ctx *jit,
1272612726

1272712727
static zend_jit_addr zend_jit_prepare_array_update(zend_jit_ctx *jit,
1272812728
const zend_op *opline,
12729-
uint32_t op1_info,
12729+
uint32_t *op1_info_ptr,
1273012730
zend_jit_addr op1_addr,
1273112731
ir_ref *if_type,
1273212732
ir_ref *ht_ref,
@@ -12735,6 +12735,7 @@ static zend_jit_addr zend_jit_prepare_array_update(zend_jit_ctx *jit,
1273512735
ir_ref ref = IR_UNUSED;
1273612736
ir_ref array_reference_end = IR_UNUSED, array_reference_ref = IR_UNUSED;
1273712737
ir_refs *array_inputs, *array_values;
12738+
uint32_t op1_info = *op1_info_ptr;
1273812739

1273912740
ir_refs_init(array_inputs, 4);
1274012741
ir_refs_init(array_values, 4);
@@ -12826,6 +12827,9 @@ static zend_jit_addr zend_jit_prepare_array_update(zend_jit_ctx *jit,
1282612827
ir_refs_add(array_inputs, ir_END());
1282712828
ir_refs_add(array_values, ref);
1282812829
}
12830+
op1_info &= ~(MAY_BE_UNDEF | MAY_BE_NULL);
12831+
op1_info |= MAY_BE_ARRAY | MAY_BE_RC1;
12832+
*op1_info_ptr = op1_info;
1282912833
}
1283012834

1283112835
if (array_inputs->count) {
@@ -12855,9 +12859,9 @@ static int zend_jit_fetch_dim(zend_jit_ctx *jit,
1285512859
jit_SET_EX_OPLINE(jit, opline);
1285612860
}
1285712861

12858-
op1_addr = zend_jit_prepare_array_update(jit, opline, op1_info, op1_addr, &if_type, &ht_ref, &may_throw);
12862+
op1_addr = zend_jit_prepare_array_update(jit, opline, &op1_info, op1_addr, &if_type, &ht_ref, &may_throw);
1285912863

12860-
if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_ARRAY)) {
12864+
if (op1_info & MAY_BE_ARRAY) {
1286112865
ir_refs *found_inputs, *found_vals;
1286212866

1286312867
ir_refs_init(found_inputs, 8);
@@ -12937,7 +12941,7 @@ static int zend_jit_fetch_dim(zend_jit_ctx *jit,
1293712941
}
1293812942
}
1293912943

12940-
if (op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_ARRAY))) {
12944+
if (op1_info & (MAY_BE_ANY-MAY_BE_ARRAY)) {
1294112945
ir_ref arg2;
1294212946

1294312947
may_throw = 1;
@@ -13247,9 +13251,9 @@ static int zend_jit_assign_dim(zend_jit_ctx *jit,
1324713251
val_info &= ~MAY_BE_UNDEF;
1324813252
}
1324913253

13250-
op1_addr = zend_jit_prepare_array_update(jit, opline, op1_info, op1_addr, &if_type, &ht_ref, &may_throw);
13254+
op1_addr = zend_jit_prepare_array_update(jit, opline, &op1_info, op1_addr, &if_type, &ht_ref, &may_throw);
1325113255

13252-
if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_ARRAY)) {
13256+
if (op1_info & MAY_BE_ARRAY) {
1325313257
if (opline->op2_type == IS_UNUSED) {
1325413258
uint32_t var_info = MAY_BE_NULL;
1325513259
ir_ref if_ok, ref;
@@ -13320,7 +13324,7 @@ static int zend_jit_assign_dim(zend_jit_ctx *jit,
1332013324
ir_END_list(end_inputs);
1332113325
}
1332213326

13323-
if (op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_ARRAY))) {
13327+
if (op1_info & (MAY_BE_ANY-MAY_BE_ARRAY)) {
1332413328
ir_ref arg2, arg4;
1332513329

1332613330
if (if_type) {
@@ -13411,9 +13415,9 @@ static int zend_jit_assign_dim_op(zend_jit_ctx *jit,
1341113415
jit_SET_EX_OPLINE(jit, opline);
1341213416
}
1341313417

13414-
op1_addr = zend_jit_prepare_array_update(jit, opline, op1_info, op1_addr, &if_type, &ht_ref, &may_throw);
13418+
op1_addr = zend_jit_prepare_array_update(jit, opline, &op1_info, op1_addr, &if_type, &ht_ref, &may_throw);
1341513419

13416-
if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_ARRAY)) {
13420+
if (op1_info & MAY_BE_ARRAY) {
1341713421
uint32_t var_def_info = zend_array_element_type(op1_def_info, opline->op1_type, 1, 0);
1341813422

1341913423
if (opline->op2_type == IS_UNUSED) {
@@ -13555,7 +13559,7 @@ static int zend_jit_assign_dim_op(zend_jit_ctx *jit,
1355513559
}
1355613560
}
1355713561

13558-
if (op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_ARRAY))) {
13562+
if (op1_info & (MAY_BE_ANY-MAY_BE_ARRAY)) {
1355913563
binary_op_type binary_op;
1356013564
ir_ref arg2;
1356113565

ext/opcache/jit/zend_jit_trace.c

+16-20
Original file line numberDiff line numberDiff line change
@@ -1860,11 +1860,6 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
18601860
ADD_OP2_TRACE_GUARD();
18611861
break;
18621862
case ZEND_ASSIGN_DIM_OP:
1863-
if (opline->extended_value == ZEND_POW
1864-
|| opline->extended_value == ZEND_DIV) {
1865-
// TODO: check for division by zero ???
1866-
break;
1867-
}
18681863
if (opline->result_type != IS_UNUSED) {
18691864
break;
18701865
}
@@ -1875,23 +1870,18 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
18751870
}
18761871
ZEND_FALLTHROUGH;
18771872
case ZEND_ASSIGN_DIM:
1878-
if (opline->op1_type == IS_CV) {
1879-
if ((opline+1)->op1_type == IS_CV
1880-
&& (opline+1)->op1.var == opline->op1.var) {
1881-
/* skip $a[x] = $a; */
1882-
break;
1883-
}
1873+
if (opline->opcode == ZEND_ASSIGN_DIM
1874+
&& opline->op1_type == IS_CV
1875+
&& (opline+1)->op1_type == IS_CV
1876+
&& (opline+1)->op1.var == opline->op1.var) {
1877+
/* skip $a[x] = $a; */
1878+
break;
1879+
}
1880+
if (opline->op1_type == IS_CV || opline->opcode == ZEND_ASSIGN_DIM_OP) {
18841881
ADD_OP1_DATA_TRACE_GUARD();
1885-
ADD_OP2_TRACE_GUARD();
1886-
ADD_OP1_TRACE_GUARD();
1887-
} else if (orig_op1_type != IS_UNKNOWN
1888-
&& (orig_op1_type & IS_TRACE_INDIRECT)
1889-
&& opline->result_type == IS_UNUSED) {
1890-
if (opline->opcode == ZEND_ASSIGN_DIM_OP) {
1891-
ADD_OP1_DATA_TRACE_GUARD();
1892-
}
1893-
ADD_OP2_TRACE_GUARD();
18941882
}
1883+
ADD_OP2_TRACE_GUARD();
1884+
ADD_OP1_TRACE_GUARD();
18951885
if (op1_type == IS_ARRAY
18961886
&& ((opline->op2_type == IS_CONST
18971887
&& Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) == IS_LONG)
@@ -4773,6 +4763,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
47734763
op1_info, op2_info, op1_data_info, val_type))) {
47744764
goto jit_failure;
47754765
}
4766+
if (opline->op1_type == IS_VAR && !(op1_info & (MAY_BE_ANY-MAY_BE_NULL))) {
4767+
SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var), IS_ARRAY, 1);
4768+
}
47764769
goto done;
47774770
case ZEND_PRE_INC_OBJ:
47784771
case ZEND_PRE_DEC_OBJ:
@@ -5097,6 +5090,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
50975090
&& ssa->vars[(ssa_op+1)->op1_def].alias == NO_ALIAS) {
50985091
ssa->var_info[(ssa_op+1)->op1_def].guarded_reference = ssa->var_info[(ssa_op+1)->op1_use].guarded_reference;
50995092
}
5093+
if (opline->op1_type == IS_VAR && !(op1_info & (MAY_BE_ANY-MAY_BE_NULL))) {
5094+
SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var), IS_ARRAY, 1);
5095+
}
51005096
goto done;
51015097
case ZEND_ASSIGN:
51025098
if (opline->op1_type != IS_CV) {

0 commit comments

Comments
 (0)