Skip to content

Commit 29bf790

Browse files
committed
Fixed RC inference for ZEND_ASSIGN_STATIC_PROP and removed useless checks during RC inference
1 parent 4bf2d09 commit 29bf790

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

ext/opcache/Optimizer/zend_dfg.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,9 @@ static zend_always_inline void _zend_dfg_add_use_def_op(const zend_op_array *op_
105105
if (!zend_bitset_in(def, var_num)) {
106106
zend_bitset_incl(use, var_num);
107107
}
108-
#if 0
109108
if ((build_flags & ZEND_SSA_RC_INFERENCE) && next->op1_type == IS_CV) {
110109
zend_bitset_incl(def, var_num);
111110
}
112-
#endif
113111
}
114112
break;
115113
case ZEND_ASSIGN_STATIC_PROP_REF:

ext/opcache/Optimizer/zend_inference.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,12 +2409,10 @@ static zend_always_inline int _zend_update_type_info(
24092409
if (ssa_op->op1_def >= 0) {
24102410
tmp = t1;
24112411
if ((t1 & (MAY_BE_ARRAY|MAY_BE_OBJECT)) &&
2412-
(opline->op1_type == IS_CV) &&
24132412
(opline->extended_value == IS_ARRAY ||
24142413
opline->extended_value == IS_OBJECT)) {
24152414
tmp |= MAY_BE_RCN;
24162415
} else if ((t1 & MAY_BE_STRING) &&
2417-
(opline->op1_type == IS_CV) &&
24182416
opline->extended_value == IS_STRING) {
24192417
tmp |= MAY_BE_RCN;
24202418
}
@@ -2454,7 +2452,7 @@ static zend_always_inline int _zend_update_type_info(
24542452
case ZEND_COPY_TMP:
24552453
if (ssa_op->op1_def >= 0) {
24562454
tmp = t1;
2457-
if ((t1 & (MAY_BE_RC1|MAY_BE_REF)) && (opline->op1_type == IS_CV)) {
2455+
if (t1 & (MAY_BE_RC1|MAY_BE_REF)) {
24582456
tmp |= MAY_BE_RCN;
24592457
}
24602458
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
@@ -2729,7 +2727,7 @@ static zend_always_inline int _zend_update_type_info(
27292727
}
27302728
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
27312729
}
2732-
if ((opline+1)->op1_type == IS_CV && (ssa_op+1)->op1_def >= 0) {
2730+
if ((ssa_op+1)->op1_def >= 0) {
27332731
opline++;
27342732
ssa_op++;
27352733
tmp = OP1_INFO_EX();
@@ -2763,14 +2761,27 @@ static zend_always_inline int _zend_update_type_info(
27632761
UPDATE_SSA_OBJ_TYPE(ce, 1, ssa_op->result_def);
27642762
}
27652763
}
2766-
if ((opline+1)->op1_type == IS_CV) {
2764+
if ((ssa_op+1)->op1_def >= 0) {
27672765
opline++;
27682766
ssa_op++;
27692767
tmp = OP1_INFO_EX();
2770-
if (tmp & (MAY_BE_ANY | MAY_BE_REF)) {
2771-
if (tmp & MAY_BE_RC1) {
2772-
tmp |= MAY_BE_RCN;
2773-
}
2768+
if (tmp & MAY_BE_RC1) {
2769+
tmp |= MAY_BE_RCN;
2770+
}
2771+
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
2772+
}
2773+
break;
2774+
case ZEND_ASSIGN_STATIC_PROP:
2775+
if (ssa_op->result_def >= 0) {
2776+
tmp = MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_RC1 | MAY_BE_RCN;
2777+
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
2778+
}
2779+
if ((ssa_op+1)->op1_def >= 0) {
2780+
opline++;
2781+
ssa_op++;
2782+
tmp = OP1_INFO_EX();
2783+
if (tmp & MAY_BE_RC1) {
2784+
tmp |= MAY_BE_RCN;
27742785
}
27752786
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
27762787
}
@@ -2798,12 +2809,10 @@ static zend_always_inline int _zend_update_type_info(
27982809
}
27992810
break;
28002811
case ZEND_ASSIGN:
2801-
if (opline->op2_type == IS_CV && ssa_op->op2_def >= 0) {
2812+
if (ssa_op->op2_def >= 0) {
28022813
tmp = t2;
2803-
if (tmp & (MAY_BE_ANY | MAY_BE_REF)) {
2804-
if (tmp & MAY_BE_RC1) {
2805-
tmp |= MAY_BE_RCN;
2806-
}
2814+
if (tmp & MAY_BE_RC1) {
2815+
tmp |= MAY_BE_RCN;
28072816
}
28082817
UPDATE_SSA_TYPE(tmp, ssa_op->op2_def);
28092818
}
@@ -2918,7 +2927,7 @@ static zend_always_inline int _zend_update_type_info(
29182927
case ZEND_SEND_VAR:
29192928
if (ssa_op->op1_def >= 0) {
29202929
tmp = t1;
2921-
if ((t1 & (MAY_BE_RC1|MAY_BE_REF)) && (opline->op1_type == IS_CV)) {
2930+
if (t1 & (MAY_BE_RC1|MAY_BE_REF)) {
29222931
tmp |= MAY_BE_RCN;
29232932
}
29242933
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
@@ -3102,7 +3111,7 @@ static zend_always_inline int _zend_update_type_info(
31023111
break;
31033112
case ZEND_INIT_ARRAY:
31043113
case ZEND_ADD_ARRAY_ELEMENT:
3105-
if (opline->op1_type == IS_CV && ssa_op->op1_def >= 0) {
3114+
if (ssa_op->op1_def >= 0) {
31063115
if (opline->extended_value & ZEND_ARRAY_ELEMENT_REF) {
31073116
tmp = (MAY_BE_REF | t1) & ~(MAY_BE_UNDEF|MAY_BE_RC1|MAY_BE_RCN);
31083117
if (t1 & MAY_BE_UNDEF) {
@@ -3190,10 +3199,8 @@ static zend_always_inline int _zend_update_type_info(
31903199
tmp = t1;
31913200
if (opline->opcode == ZEND_FE_RESET_RW) {
31923201
tmp |= MAY_BE_REF;
3193-
} else {
3194-
if ((t1 & MAY_BE_RC1) && opline->op1_type != IS_TMP_VAR) {
3195-
tmp |= MAY_BE_RCN;
3196-
}
3202+
} else if (t1 & MAY_BE_RC1) {
3203+
tmp |= MAY_BE_RCN;
31973204
}
31983205
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
31993206
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);

ext/opcache/Optimizer/zend_ssa.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,12 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
621621
if (next->op1_type & (IS_CV|IS_VAR|IS_TMP_VAR)) {
622622
ssa_ops[k + 1].op1_use = var[EX_VAR_TO_NUM(next->op1.var)];
623623
//USE_SSA_VAR(op_array->last_var + next->op1.var);
624-
#if 0
625624
if ((build_flags & ZEND_SSA_RC_INFERENCE) && next->op1_type == IS_CV) {
626625
ssa_ops[k + 1].op1_def = ssa_vars_count;
627626
var[EX_VAR_TO_NUM(next->op1.var)] = ssa_vars_count;
628627
ssa_vars_count++;
629628
//NEW_SSA_VAR(next->op1.var)
630629
}
631-
#endif
632630
}
633631
break;
634632
case ZEND_ASSIGN_STATIC_PROP_REF:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
JIT ASSIGN_STATIC_PROP: 001
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
class Foo {
13+
public static $prop;
14+
}
15+
16+
function test($x) {
17+
$a = [$x];
18+
Foo::$prop = $a;
19+
$a = 42;
20+
}
21+
test(42);
22+
var_dump(Foo::$prop);
23+
?>
24+
--EXPECT--
25+
array(1) {
26+
[0]=>
27+
int(42)
28+
}

0 commit comments

Comments
 (0)